Result

class ionworkspipeline.Result(parameter_values: dict, optimizer_result: OptimizerResult | SamplerResult, samples: ndarray | None = None, costs: ndarray | None = None, callbacks: dict | None = None, callback_results: dict | None = None, children: list[Result] | None = None, initial_guess: dict | None = None, job_id: int | None = None)

Optimization results combining fitted parameters with metadata.

Inherits from ParameterValues to integrate seamlessly with the pipeline while providing rich optimization metadata as attributes. Supports dict-like access to parameters and attribute access to optimization details.

Parameters

parameter_valuesdict

Final optimized parameter values.

optimizer_resultiwp.OptimizerResult | iwp.SamplerResult

Result object from the optimizer/sampler.

samplesnp.ndarray | None, default=None

Parameter samples (for samplers) or single parameter vector (for optimizers).

costsnp.ndarray | None, default=None

Cost function values corresponding to samples.

callbacksdict | None, default=None

Callbacks used during optimization.

callback_resultsdict | None, default=None

Results collected by callbacks.

childrenlist[Result] | None, default=None

Results from individual multistart jobs.

initial_guessdict | None, default=None

Initial parameter values used for optimization.

job_idint | None, default=None

Identifier for this optimization job.

Examples

Result is returned by DataFit.run() and provides dict-like parameter access:

>>> result = sample_datafit.run(sample_setup_params)
>>> isinstance(result["a"], float)
True

Access optimization metadata to check convergence:

>>> result.optimizer_result.success
True
>>> result.costs < 1
True

Use in a pipeline where Result flows from fit to validate:

>>> pipeline = iwp.Pipeline({
...     "setup": iwp.direct_entries.DirectEntry(
...         sample_parameter_values, "Chen2020"
...     ),
...     "validate": sample_validation,
... })
>>> params = pipeline.run()
>>> sample_validation.summary_stats is not None
True

Notes

This class inherits from ParameterValues, enabling:
  • Dict-like access: result[“Diffusivity [m2.s-1]”]

  • PyBaMM methods: .process_symbol(), .evaluate(), etc.

  • Pipeline integration: automatically works as input to next element

  • Metadata access: result.cost, result.optimizer_result

The specific attributes available in optimizer_result may vary depending on the optimization method used. Refer to SciPy’s documentation for a complete list of possible attributes.

Attributes

parameter_valuesdict

The final values of the optimized parameters.

optimizer_resultiwp.OptimizerResult | iwp.SamplerResult

The result object in the format returned by the optimizer.

callbacksdict

The callbacks used during optimization.

callback_resultsdict

Results collected by callbacks, formatted as:

{
    "callback_name": {
        "data": ...,
        "options": ...,
        "initial_results": {"inputs": ..., "outputs": ...},
        "fit_results": {"inputs": ..., "outputs": ...},
    },
    ...
}
childrenlist[Result]

Results from sub-fits if this was part of a composite fit.

initial_guessdict

The initial guess for the parameters.

samplesnp.ndarray

Parameter samples (for probabilistic methods) or final parameters (for deterministic).

costsnp.ndarray

Cost function values.

Extends: ionworkspipeline.parameter_values.ParameterValues

best_results(num_results: int | integer | None = None) list[Result]

Returns the best results from the children in ascending order of cost.

Parameters

num_resultsint or np.integer, optional

The number of best results to return. If None, all children are returned.

Returns

list[Result]

The best results from the children in ascending order of cost.

get_fit_results()

Get the results of the fit.

Returns

dict

Dictionary containing fit results for each objective.

plot_fit_results()

Plot the results of the fit by calling the plot_fit_results method of each internal callback in each objective. Any user-defined callbacks should be called manually instead of using this method.

Returns

dict

Dictionary containing figure and axes objects for each objective.

class ionworkspipeline.OptimizerResult(x=None)

Result of an optimization. Inherits from scipy.optimize.OptimizeResult.

This class represents the result of running an optimizer. It contains the optimal parameter values found and other optimization-related information like function evaluations, success status etc.

Parameters

xarray_like, optional

The solution of the optimization. Default is None.

Extends: scipy.optimize._optimize.OptimizeResult

class ionworkspipeline.SamplerResult(samples=None, costs=None)

Result of a sampling procedure. Inherits from scipy.optimize.OptimizeResult.

This class represents the result of running a sampler. It contains the samples drawn from the parameter space and their associated costs/objective function values.

Parameters

samplesarray_like, optional

The samples drawn from the parameter space. Default is None.

costsarray_like, optional

The cost/objective function values for each sample. Default is None.

Extends: scipy.optimize._optimize.OptimizeResult

property log_pdfs

Converts costs to log probability density values.

Returns

array_like

The negative log of the costs, representing log probability densities.

property x

Returns the sample with the lowest cost.

Since we are minimizing the cost function, this represents the best parameter values found during sampling.

Returns

array_like

The sample with the minimum cost value.

ionworkspipeline.result.combine(children: list[Result]) Result

Combine a list of results into a single result.

Parameters

childrenlist[Result]

The list of results to combine.

Returns

Result

A new Result object containing the combined children of both results, sorted by their minimum costs. The properties of the returned Result are taken from the child with the smallest cost.