Pipeline

class ionworkspipeline.Pipeline(elements, output_file=None, name=None, description=None)

A pipeline is a sequence of pipeline elements, each of which takes a set of parameters as input and returns a set of parameters as output. The output of one element is the input of the next. The pipeline can be run to generate a set of parameters, and a report can be generated to document the pipeline.

Parameters

elementsdict of {str: _PipelineElement}

A dictionary of pipeline elements. The name is used to identify the element in the report.

output_filestr, optional

The file to save the parameters to. If None, the parameters are not saved.

namestr, optional

A name for the pipeline. Useful for identification and reporting.

descriptionstr, optional

A description of what the pipeline does.

Extends: ConfigMixin

See also: Pipeline — field-level documentation.

classmethod from_schema(schema)

Construct a Pipeline from a validated ionworks_schema.Pipeline.

Each entry in schema.elements is dispatched to the matching pipeline element’s from_schema based on the schema class hierarchy: DirectEntry-style schemas, DirectEntryFunctionSchema wrappers, DataFit/ArrayDataFit, Validation, and Calculation are each handled. Pre-built pipeline elements pass through unchanged; raw dicts are forwarded as-is.

Parameters

schemaionworks_schema.Pipeline

Validated schema describing the pipeline elements and metadata.

Returns

Pipeline

Pipeline whose elements are pipeline-side instances ready to run.

run() ParameterValues

Execute all pipeline elements sequentially to generate parameters.

Each element receives the accumulated ParameterValues and returns new parameters to add. Results are combined and optionally saved to a file.

Returns

iwp.ParameterValues

Complete set of parameters generated by the pipeline.

Examples

Build and run a parameter pipeline:

>>> geom_params = iwp.ParameterValues({
...     "Positive electrode capacity [A.h]": 3.0,
...     "Positive electrode active material volume fraction": 0.65,
...     "Positive electrode thickness [m]": 80e-6,
...     "Electrode area [m2]": 0.1,
... })
>>> pipeline = iwp.Pipeline({
...     "geometry": iwp.direct_entries.DirectEntry(geom_params, "Datasheet"),
...     "capacity": iwp.calculations.ElectrodeCapacity(
...         "positive", use_stoich_window=False
...     ),
... })
>>> result = pipeline.run()
>>> float(result["Maximum concentration in positive electrode [mol.m-3]"]) > 0
True
to_config() dict

Convert the Pipeline back to parser configuration format.

Returns

dict

Configuration dictionary that can be passed to parse_pipeline

Every step a pipeline runs is a PipelineElement.

class ionworkspipeline.pipeline.PipelineElement(source: str | None)

Base class for pipeline elements. Provides methods for generating a report and latex source code.

Parameters

sourcestr

The source of the pipeline element, e.g. a reference to a paper or a description of the method used to generate the parameters.

Extends: OptionsController

run(parameter_values: ParameterValues) ParameterValues

Execute the pipeline element.

Parameters

parameter_valuesParameterValues

Input parameters. Must be ParameterValues object.

Returns

ParameterValues

New parameters to add to pipeline.

Elements capture their constructor arguments through ConfigMixin, which is what makes to_config() round-trip.

class ionworkspipeline.controllers.ConfigMixin

Mixin that automatically captures __init__ parameters for subclasses.

When a class inherits from this mixin, any subclass that defines its own __init__ method will have its parameters automatically captured and stored in self._init_params. This is useful for serialization/deserialization (e.g., to_config methods for reverse parsing).

Additionally, if the __init__ has an “options” parameter, it captures which option keys were explicitly passed in self._options_keys_passed before calling the original __init__.

The captured parameters exclude self and filter out None values.

Example

>>> class MyClass(ConfigMixin):
...     def __init__(self, a, b=None, c=10):
...         self.a = a
...         self.c = c
...
>>> obj = MyClass(1, c=20)
>>> obj._init_params
{'a': 1, 'c': 20}

See also: ConfigMixin — field-level documentation.

classmethod from_schema(schema)

Construct from a validated ionworks_schema instance.

Forwards the schema’s fields as kwargs to cls(...), converting any field that holds a nested schema to its runtime counterpart (detected from the values, not declared). Subclasses whose construction needs more (runtime-only fields, alias remapping, deferred parsing) still override.

classmethod get_init_param_names()

Get the list of __init__ parameter names.

Excludes self, *args, and **kwargs.

Returns

list[str]

List of parameter names.

class ionworkspipeline.controllers.OptionsController

Gives a class an options dict validated against its own defaults.

Common pipelines

Collections of pre-defined pipelines for common tasks.