mirror of
https://github.com/clearml/clearml
synced 2025-05-07 06:14:31 +00:00
Automation Parameter serialization type name
This commit is contained in:
parent
0626d807a7
commit
9f9452ecf4
@ -37,6 +37,7 @@ class Parameter(RandomSeed):
|
||||
"""
|
||||
The base hyper-parameter optimization object.
|
||||
"""
|
||||
_class_type_serialize_name = 'type'
|
||||
|
||||
def __init__(self, name):
|
||||
# type: (Optional[str]) -> ()
|
||||
@ -79,7 +80,7 @@ class Parameter(RandomSeed):
|
||||
|
||||
:return: dict representation of the object (serialization).
|
||||
"""
|
||||
serialize = {'type.': str(self.__class__).split('.')[-1][:-2]}
|
||||
serialize = {self._class_type_serialize_name: str(self.__class__).split('.')[-1][:-2]}
|
||||
# noinspection PyCallingNonCallable
|
||||
serialize.update(dict(((k, v.to_dict() if hasattr(v, 'to_dict') else v) for k, v in self.__dict__.items())))
|
||||
return serialize
|
||||
@ -93,7 +94,7 @@ class Parameter(RandomSeed):
|
||||
:return: The Parameter object.
|
||||
"""
|
||||
a_dict = a_dict.copy()
|
||||
a_cls = a_dict.pop('type.', None)
|
||||
a_cls = a_dict.pop(cls._class_type_serialize_name, None)
|
||||
if not a_cls:
|
||||
return None
|
||||
try:
|
||||
@ -101,8 +102,9 @@ class Parameter(RandomSeed):
|
||||
except AttributeError:
|
||||
return None
|
||||
instance = a_cls.__new__(a_cls)
|
||||
instance.__dict__ = dict((k, cls.from_dict(v) if isinstance(v, dict) and 'type.' in v else v)
|
||||
for k, v in a_dict.items())
|
||||
instance.__dict__ = dict(
|
||||
(k, cls.from_dict(v) if isinstance(v, dict) and cls._class_type_serialize_name in v else v)
|
||||
for k, v in a_dict.items())
|
||||
return instance
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user