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

Model attributes need to be JSON serializable #1408

Open
PeterLombaers opened this issue Apr 17, 2023 · 2 comments
Open

Model attributes need to be JSON serializable #1408

PeterLombaers opened this issue Apr 17, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@PeterLombaers
Copy link
Member

Describe the bug
When you create a model extension class an attribute which is an argument to class.__init__ and which is not json serializable, the state class will complain when saving the settings.

To Reproduce
Create a model extension with an attribute that is not json serializable and run a simulation.

Additional context
The state class stores the settings and metadata as a json (see here). Part of the settings object is the parameters of the different model parts. These parameters are set here. This param property of BaseModel is constructed by looping over parameters in the signature of class.__init__ and getting the current values of these parametes as a class attribute. If the current value is not json serializable, this will give a problem when the state class tries to store the settings.

Another problem is that this method of storing the model parameters only works if the arguments to __init__ are actually used as class attributes, which need not be the case.

@PeterLombaers PeterLombaers added the bug Something isn't working label Apr 17, 2023
@PeterLombaers
Copy link
Member Author

One quick fix on the side of the model extension is to override the param property to return something that is json serializable.

@J535D165
Copy link
Member

Good catch.

One quick fix on the side of the model extension is to override the param property to return something that is json serializable.

Alternative quick fix: What about providing the class json serializable arguments? Convert them to the desired structure internally (e.g fit method).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants