Callbacks

class ionworkspipeline.callbacks.Callback

Base class for callbacks, for documenting callback methods.

Callbacks are used to perform actions (e.g. logging, saving) at certain points in the simulation. Each callback method is named on_<event>, where <event> describes the point at which the callback is called. For example, the callback on_datafit_finish is called at the end of a data fit. In general, callbacks take a single argument, logs, which is a dictionary of information about the simulation. Each callback method should return None (the output of the method is ignored).

on_datafit_finish(logs)

Called at the end of the DataFit.

Objectives in the ionworkspipeline library will pass logs containing

  • “inputs”: the current values of the parameters (dict)

  • “outputs”: the current values of the variables, including but not limited to

    those used in the objective (dict)

Custom objective may pass different logs.

on_datafit_start(logs)

Called at the start of the DataFit.

Objectives in the ionworkspipeline library will pass logs containing

  • “inputs”: the current values of the parameters (dict)

  • “outputs”: the current values of the variables, including but not limited to

    those used in the objective (dict)

Custom objective may pass different logs.

on_objective_build(logs)

Called after the objective has been set up.

Objectives in the ionworkspipeline library will pass logs containing

  • “options”: the options to be used in the data fit (dict)

  • “data”: the variables in the data, including but not limited to those used in

    the objective (dict)

Custom objective may pass different logs.

on_run_iteration(logs)

Called at each iteration of evaluating the objective.

Objectives in the ionworkspipeline library will pass logs containing

  • “inputs”: the current values of the parameters (dict)

  • “outputs”: the current values of the variables, including but not limited to

    those used in the objective (dict)

Custom objective may pass different logs.

plot_fit_results()

Plot fit results. For internal callbacks, this method is called by DataFit.plot_fit_results(). For external callbacks, the user should implement and call their own plotting method.

class ionworkspipeline.callbacks.SaveResultsCallback(folder=None)

Callback to save the initial and final results of a data fit. Initial results are saved to the initial_results_ attribute when on_datafit_start is called, and final results are saved to the fit_results_ attribute when on_datafit_finish is called.

Most of the inbuilt callbacks in the ionworkspipeline library use this callback as the parent class, then add object-specific functionality (e.g. plotting).

Parameters

folderstr, optional

If provided, results are saved to this folder

Extends: Callback

property all_results

Return all results in a dictionary

model_vs_data_configs(variables, x_key, x_label=None)

Panel configs for this fit: see ionworks.pipeline.plots.fit_panels().

on_datafit_finish(logs)

Called at the end of the DataFit.

Objectives in the ionworkspipeline library will pass logs containing

  • “inputs”: the current values of the parameters (dict)

  • “outputs”: the current values of the variables, including but not limited to

    those used in the objective (dict)

Custom objective may pass different logs.

on_datafit_start(logs)

Called at the start of the DataFit.

Objectives in the ionworkspipeline library will pass logs containing

  • “inputs”: the current values of the parameters (dict)

  • “outputs”: the current values of the variables, including but not limited to

    those used in the objective (dict)

Custom objective may pass different logs.

on_objective_build(logs)

Called after the objective has been set up.

Objectives in the ionworkspipeline library will pass logs containing

  • “options”: the options to be used in the data fit (dict)

  • “data”: the variables in the data, including but not limited to those used in

    the objective (dict)

Custom objective may pass different logs.

plot_model_vs_data(variables, x_key, x_label=None)

Draw those panels, each residual stacked under the curve it came from.

Returns

tuple

(fig, axes).

plotted_outputs(variables)

The model values to plot, one per row of data_ for each variable.

A panel pairs one x with every variable’s y, so an objective scored at only some of the rows it describes overrides this to span them all.

Parameters

variableslist of str

The variables being plotted.

Returns

dict

The fit’s model output, unchanged.