forked from VSharp-team/VSharp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mlSearcher' of https://github.com/gsvgit/VSharp into ml…
…Searcher
- Loading branch information
Showing
20 changed files
with
333 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# python cache and venv | ||
.env | ||
__pycache__/ | ||
epochs_best/ | ||
report/ | ||
*.pkl | ||
*.onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from dataclasses import asdict as dataclasses_asdict, is_dataclass | ||
from typing import ClassVar, Protocol | ||
|
||
|
||
class Dataclass(Protocol): | ||
__dataclass_fields__: ClassVar[dict] | ||
|
||
|
||
BareObject = type("BareObject", (), {}) | ||
|
||
|
||
def obj_from_dict(data: dict | list | str | float) -> BareObject: | ||
if isinstance(data, list): | ||
return [obj_from_dict(item) for item in data] | ||
if isinstance(data, dict): | ||
inner_dict = { | ||
field_name: obj_from_dict(field_raw) | ||
for field_name, field_raw in data.items() | ||
} | ||
bare_obj = BareObject() | ||
bare_obj.__dict__ = inner_dict | ||
return bare_obj | ||
return data | ||
|
||
|
||
def asdict( | ||
data: BareObject | Dataclass | list | dict | str | float, | ||
) -> dict | list | str | float: | ||
if isinstance(data, BareObject): | ||
return {asdict(k): asdict(v) for k, v in data.__dict__.items()} | ||
elif is_dataclass(data): | ||
try: | ||
return data.to_json() | ||
except TypeError: | ||
return asdict(dataclasses_asdict(data)) | ||
elif isinstance(data, list): | ||
return [asdict(item) for item in data] | ||
elif isinstance(data, dict): | ||
return {asdict(k): asdict(v) for k, v in data.items()} | ||
else: | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
from dataclasses import dataclass, field | ||
from typing import Callable | ||
|
||
from dataclasses_json import config, dataclass_json | ||
|
||
from ml.model_wrappers.nnwrapper import NNWrapper, encode, decode | ||
from agent.unsafe_json import asdict | ||
from config import FeatureConfig | ||
from ml.model_wrappers.nnwrapper import NNWrapper, decode, encode | ||
from selection.classes import Map2Result | ||
|
||
|
||
def custom_encoder_if_disable_message_checks() -> Callable | None: | ||
return asdict if FeatureConfig.DISABLE_MESSAGE_CHECKS else None | ||
|
||
|
||
@dataclass_json | ||
@dataclass | ||
class Agent2ResultsOnMaps: | ||
agent: NNWrapper = field(metadata=config(encoder=encode, decoder=decode)) | ||
results: list[Map2Result] | ||
results: list[Map2Result] = field( | ||
metadata=config(encoder=custom_encoder_if_disable_message_checks()) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.