xarray-simlab
xarray-simlab copied to clipboard
Model optimization: allow easy integration with scipy.optimize API
A preliminary idea would be to provide a helper function that returns a callable that can be easily used with scipy.optimize functions or with scikit-optimize.
The returned callable would basically do three things:
- setup a new simulation (i.e., update from an existing setup with a new set of free parameters)
- run the simulation
- compute and return the result of either an external function that takes simulation output as input or a function attached to the model as a process.
The signature of the helper function might look like (naming could be better):
xsimlab.create_minimize_func(model, in_dataset, params, fvalue)
where:
-
modelis an instance ofxsimlab.Model -
in_datasetis an inputxarray.Dataset, which has for example been created usingxsimlab.create_setup(model=model, ...) -
paramsis a list with the names of the model inputs that are free parameters. This will correspond to the input arguments of the returned function to minimize. -
fvalueis either the name of the variable inModelthat correspond to the value of the function to minimize or a callable that take an outputxarray.Dataset(as returned byDataset.xsimlab.run(model=model)) and that returns the value of the function to minimize.
Optionally, the helper function might also return initial guesses for each free parameter (i.e., x0), taken directly from in_dataset.