Currently only model results can be saved/loaded. The consequence of this is that in order to load up a model, a user would have to input the model parameters, then load the data. If the model parameters could also be saved, then the user can save/load the entire state of the model.
I think one way to do this would have a abstract parameter object of:
class Parameter:
def __init__(self, *args, **kwargs):
# store/setup metadata
def to_dict(self):
# create mapping of {'attribute': value}
def from_dict(self, data):
# store/setup metadata from a mapping of {'attribute': value}
In a sense, the thermodynamic objects would also be a parameter, where the metadata includes the database, element and phases
Then when saving, the model will iterate through all the parameters and create a json file that stores all the parameter data. The main barrier right now is that some parameter can take in a lambda function, which would not be json serializable. I suppose a solution would be to replace the lambda function support with a symengine expression. This expression can be saved/loaded as a string, but in the parameter itself, the expression can be built into a callable.
Example for a temperature parameter
from kawin.precipitation import TemperatureParameters
# scalar temperature
temp = TemperatureParameters(1273)
# function input
temp = TemperatureParameters(3*v.time)
temp = TemperatureParameters("3*time")
Another difficulty here would be that we may just want to store the minimal data necessary in the json file to initialize the model rather than all the data. This is for cases where we want to store the thermodynamic information (which includes TDB file) or model results (which includes large numpy arrays), but instead of storing in the json file directly, store a reference to the TDB or npz file. But this would likely have to assume a certain folder structure (maybe tdb, npz and json file needs to be in the same directory?)
On a similar note, it would be nice to abstract out the model data to a single object
class ModelData:
def __init__(self):
# setup arrays
def update_data(self, new_data):
# pad current arrays (if necessary) and add new data
def to_dict(self):
# outputs mapping of {'attribute': np.array}
def from_dict(self, data):
# stores data from mapping of {'attribute': np.array}
Ideally, the model data should be a single object that lives in GenericModel and does not have to be inherited for other models. We could have some functionality to register variables into ModelData to record over time. Then the PrecipitateModel can use the ModelData and register terms such as average radius, precipitate density, etc. while the DiffusionModel can register terms to record the composition profiles.
This will hopefully result in moving the saving/loading and some iteration processing functionality into GenericModel
Currently only model results can be saved/loaded. The consequence of this is that in order to load up a model, a user would have to input the model parameters, then load the data. If the model parameters could also be saved, then the user can save/load the entire state of the model.
I think one way to do this would have a abstract parameter object of:
In a sense, the thermodynamic objects would also be a parameter, where the metadata includes the database, element and phases
Then when saving, the model will iterate through all the parameters and create a json file that stores all the parameter data. The main barrier right now is that some parameter can take in a lambda function, which would not be json serializable. I suppose a solution would be to replace the lambda function support with a symengine expression. This expression can be saved/loaded as a string, but in the parameter itself, the expression can be built into a callable.
Example for a temperature parameter
Another difficulty here would be that we may just want to store the minimal data necessary in the json file to initialize the model rather than all the data. This is for cases where we want to store the thermodynamic information (which includes TDB file) or model results (which includes large numpy arrays), but instead of storing in the json file directly, store a reference to the TDB or npz file. But this would likely have to assume a certain folder structure (maybe tdb, npz and json file needs to be in the same directory?)
On a similar note, it would be nice to abstract out the model data to a single object
Ideally, the model data should be a single object that lives in
GenericModeland does not have to be inherited for other models. We could have some functionality to register variables intoModelDatato record over time. Then thePrecipitateModelcan use theModelDataand register terms such as average radius, precipitate density, etc. while theDiffusionModelcan register terms to record the composition profiles.This will hopefully result in moving the saving/loading and some iteration processing functionality into
GenericModel