Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserving of optimisation results implemented #37

Merged
merged 5 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code review fixes
  • Loading branch information
nicl-nno committed Aug 6, 2022
commit f9d97ee741343124856ee5421232717ecb5c061a
39 changes: 23 additions & 16 deletions gefest/core/serialization/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ def _get_coder_by_type(coder_type: Type, coder_aim: str):

@staticmethod
def dump_path_to_obj(obj: INSTANCE_OR_CALLABLE) -> Dict[str, str]:
"""
Dumps the full path (module + name) to the input object into the dict
"""Dumps the full path (module + name) to the input object into the dict

:param obj: object which path should be resolved (class, function or method)
Args:
obj: object which path should be resolved (class, function or method)

:return: dict[str, str] with path to the object
Returns:
dictionary with path to the object
"""

if isclass(obj) or isfunction(obj) or ismethod(obj):
obj_name = obj.__qualname__
else:
Expand All @@ -83,12 +85,13 @@ def dump_path_to_obj(obj: INSTANCE_OR_CALLABLE) -> Dict[str, str]:
}

def default(self, obj: INSTANCE_OR_CALLABLE) -> Dict[str, Any]:
"""
Tries to encode objects that are not simply json-encodable to JSON-object
"""Tries to encode objects that are not simply json-encodable to JSON-object

:param obj: object to be encoded (class, function or method)
Args:
obj: object to be encoded (class, function or method)

:return: dict[str, Any] which is in fact json object
Returns:
json object
"""
if isfunction(obj) or ismethod(obj):
return Serializer.dump_path_to_obj(obj)
Expand All @@ -100,28 +103,32 @@ def default(self, obj: INSTANCE_OR_CALLABLE) -> Dict[str, Any]:

@staticmethod
def _get_class(class_path: str) -> Type[INSTANCE_OR_CALLABLE]:
"""
Gets the object type from the class_path
"""Gets the object type from the class_path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

этот метод скрытый, зачем его документировать докстрингами?

если им можно пользоваться, то почему он не может быть обычным?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Документировать не обязательно, но лишним не будет. В таком виде взял из FEDOT-а.


:param class_path: full path (module + name) of the class
Args:
class_path: full path (module + name) of the class

:return: class, function or method type
Returns:
class, function or method type
"""

module_name, class_name = class_path.split(MODULE_X_NAME_DELIMITER)
obj_cls = import_module(module_name)
for sub in class_name.split('.'):
obj_cls = getattr(obj_cls, sub)
return obj_cls

def object_hook(self, json_obj: Dict[str, Any]) -> Union[INSTANCE_OR_CALLABLE, dict]:
"""
Decodes every JSON-object to python class/func object or just returns dict
"""Decodes every JSON-object to python class/func object or just returns dict

:param json_obj: dict[str, Any] to be decoded into Python class, function or
Args:
json_obj: dict[str, Any] to be decoded into Python class, function or
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

типы объектов принималось обозначать через type, то есть dict[str, Any]
в таком случае этот объект будет в симпатишном квадратике

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

при этом сами объекты, например Point, Domain и прочее, вот так -> :obj:Domain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пока просто убрал дублирующую type hint-ы типизацию.

method object only if it has some special fields

:return: Python class, function or method object OR input if it's just a regular dict
Returns:
Python class, function or method object OR input if it's just a regular dict
"""

if CLASS_PATH_KEY in json_obj:
obj_cls = Serializer._get_class(json_obj[CLASS_PATH_KEY])
del json_obj[CLASS_PATH_KEY]
Expand Down
2 changes: 1 addition & 1 deletion gefest/core/viz/struct_vizualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ def plot_poly(self, poly: Polygon, info: str) -> plt.plot:
y = [pt.y for pt in poly.points]

plt.plot(x, y, label=info)
plt.legend()
plt.legend()