ergoExo
- class adept.ergoExo(mlflow_run_id: str | None = None, mlflow_nested: bool = False, parent_run_id: str | None = None)Source
Bases:
objectThis class is the main interface for running a simulation. It is responsible for calling all the ADEPT modules in the right order and logging parameters and results to mlflow.
This approach helps decouple the numerical solvers from the experiment management and facilitates the addition of new solvers
Typical usage is as follows
exoskeleton = ergoExo() modules = exoskeleton.setup(cfg) run_output, post_processing_output, mlflow_run_id = exoskeleton(modules, args=None)
If you are resuming an existing mlflow run, you can do the following
exoskeleton = ergoExo(mlflow_run_id=mlflow_run_id) modules = exoskeleton.setup(cfg) run_output, post_processing_output, mlflow_run_id = exoskeleton(modules, args=None)
If you are introducing a custom ADEPTModule, you can do the following
exoskeleton = ergoExo() modules = exoskeleton.setup(cfg, exoskeleton_module=custom_module) run_output, post_processing_output, mlflow_run_id = adept(modules, args=None)
- setup(cfg: dict, adept_module: ADEPTModule | None = None) dict[str, Module]Source
This function sets up the differentiable simulation by getting the chosen solver and setting it up At this point in time, the setup includes
initializing the mlflow run and setting the runid or resuming an existing run
getting the right
ADEPTModuleor using the one passed in. This gets assigned toself.adept_module.updating the config, units, derived quantities, and array config as defined by the
ADEPTModule. It also dumps this information to the temporary directory, which will be logged later, and logging the parameters to mlflowinitializing the state and args as defined by the
ADEPTModuleinitializing the diffeqsolve as defined by the
ADEPTModuleinitializing the necessary (trainable) physics modules as defined by the
ADEPTModule
- Parameters:
cfg – The configuration dictionary
- Returns:
A dictionary of trainable modules (
Dict[str, eqx.Module])This is a dictionary of the (trainable) modules that are required to run the simulation. These can be modules that change the initial conditions, or the driver (boundary conditions), or the metric calculation. These modules are
equinoxmodules in order to play nice withdiffrax
- __call__(modules: dict | None = None, args: dict | None = None, export=True) tuple[Solution, dict, str]Source
This function is the main entry point for running a simulation. It takes a configuration dictionary and returns a
diffrax.Solutionobject and a dictionary of datasets. It calls theself.adept_module’s__call__function.It is also responsible for logging the artifacts and metrics to mlflow.
- Parameters:
modules (Dict(str, eqx.Module)) – The trainable modules that are required to run the simulation.
call (All the other parameters are static and initialized during the setup)
- Returns:
a tuple of the run_output (
diffrax.Solution), post_processing_output (Dict[str, xarray.dataset]), and the mlflow_run_id (str).The run_output comes from the
__call__function of theself.adept_module. The post_processing_output comes from thepost_processmethod of theself.adept_module. The mlflow_run_id is the id of the mlflow run that was created during the setup call or passed in during the initialization of the class
- val_and_grad(modules: dict | None = None, args: dict | None = None, export=True) tuple[float, dict, tuple[Solution, dict, str]]Source
This function is the value and gradient of the simulation. This is a very similar looking function to the
__call__function but calls theself.adept_module.vgrather than theself.adept_module.__call__.It is also responsible for logging the artifacts and metrics to mlflow.
- Parameters:
modules – The (trainable) modules that are required to run the simulation and take the gradient against.
call (All the other parameters are static and initialized during the setup)
- Returns:
a tuple of the value (
float), gradient (Dict), and a tuple of the run_output (diffrax.Solution), post_processing_output (Dict[str, xarray.dataset]), and the mlflow_run_id (str).The value and gradient, and run_output come from the
adept_module.vgfunction. The run_output is the same as that from__call__function of theself.adept_module. The post_processing_output comes from thepost_processmethod of theself.adept_module. The mlflow_run_id is the id of the mlflow run that was created during the setup call or passed in during the initialization