aimclub / GOLEM

Graph Optimiser for Learning and Evolution of Models
https://thegolem.readthedocs.io
BSD 3-Clause "New" or "Revised" License
60 stars 7 forks source link

ParentOperator serialization in case of custom class #215

Closed MangaBoba closed 10 months ago

MangaBoba commented 10 months ago

If as a mutation function provided instance of custom class or partial, GOLEM rises TypeError exception on serialization parent_operator field of individual.

  File "f:\GEFEST\.venv\lib\site-packages\golem\serializers\serializer.py", line 224, in default
    return JSONEncoder.default(self, obj)
  File "C:\Users\user\.pyenv\pyenv-win\versions\3.9.13\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type CustomMutationWrap is not JSON serializable

GOLEM verison: 0.3.3

YamLyubov commented 10 months ago

You can use @register_serializable decorator. To set custom coder and decoder methods just implement to_json and from_json methods for your class or default serialisation will be used.

Example from FEDOT.

maypink commented 10 months ago

@MangaBoba получилось сделать так, как предлложили выше?

MangaBoba commented 10 months ago

https://github.com/aimclub/GOLEM/issues/215#issuecomment-1772644352 solved the problem.