Parameterized Models¶
Manage parameterized models in Ionworks Studio.
For usage examples and guides, see Managing parameterized models on docs.ionworks.com.
Parameterized model client for managing parameterized battery models.
This module provides the ParameterizedModelClient for creating,
reading, and updating parameterized models, which combine a base model with
specific parameter values for a given cell specification.
- class ionworks.api.parameterized_model.ParameterizedModelClient(client: Any)[source]¶
Bases:
objectClient for managing parameterized models.
Parameterized models combine a base model (e.g. SPM, DFN) with specific parameter values for a given cell specification.
- __init__(client: Any) None[source]¶
Initialize the ParameterizedModelClient.
- Parameters:
client (Any) – The HTTP client instance for making API requests.
- get(parameterized_model_id: str, summary: bool = False) ParameterizedModel[source]¶
Get a specific parameterized model by ID.
Uses the non-cell-scoped endpoint so callers don’t need the cell spec ID just to fetch an existing model.
- Parameters:
parameterized_model_id (str) – The ID of the parameterized model to retrieve.
summary (bool, optional) – If True, return id, name, cell specification, base model and timestamps only, without the parameter values (see
get_parameter_values()). Defaults to False.
- Returns:
The requested parameterized model object.
- Return type:
- list_by_cell_specification(cell_spec_id: str, limit: int | None = None, offset: int | None = None) PaginatedList[ParameterizedModel][source]¶
List parameterized models for a cell specification.
- Parameters:
- Returns:
A paginated list of parameterized model objects.
- Return type:
- list_by_project(project_id: str | None = None, limit: int | None = None, offset: int | None = None, *, cell_spec_id: str | None = None, summary: bool = False) PaginatedList[ParameterizedModel][source]¶
List parameterized models across all cell specs in a project.
Unlike
list(), which scopes to a single cell specification, this returns every parameterized model linked to any cell specification in the project.- Parameters:
project_id (str | None, optional) – The ID of the project to list models for. Defaults to the project_id set on the Ionworks client.
limit (int | None, optional) – Maximum number of models to return per page.
offset (int | None, optional) – Number of models to skip for pagination.
cell_spec_id (str | None, optional) – If provided, restrict results to a single cell specification within the project. Defaults to None (all cell specs in the project).
summary (bool, optional) – Return each model’s id, name, description,
cell_spec_id,model_id,model_nameand timestamps only, without its parameter values, which can be very large. Read one model’s values withget_parameter_values(). Defaults to False.
- Returns:
A paginated list of parameterized model objects.
- Return type:
- create(cell_spec_id: str | None, data: dict[str, Any], *, summary: bool = False) ParameterizedModel[source]¶
Create a new parameterized model for a cell specification or a project.
Pass
summary=Trueto return metadata without parameter values or model config.- Parameters:
cell_spec_id (str | None) – The ID of the cell specification to create the parameterized model for, whose capacity and voltage cut-offs override the parameter set’s.
Nonecreates a model with no cell specification in the projectdata["project_id"](defaulting to the client’s project), which keeps the parameter set’s own values.Dictionary containing the parameterized model data. Required fields:
name,model_id. Optional fields:description,parameters,simulation_settings,project_id.parametersmay be a parameters dict, apybamm.ParameterValues, or the name of a pybamm parameter set (e.g."Chen2020"); the latter two are serialized for you.simulation_settingsis a persistent bag of pybamm simulation kwargs (var_pts/submesh_types/spatial_methods/solver) that takes precedence over the base model’s settings when this parameterized model is simulated. Pass aniw.pipeline.models.SimulationSettings(...)object (serialized for you) or its config dict (seeModelClient.create()).
- Returns:
The newly created parameterized model object.
- Return type:
- Raises:
ValueError – If
cell_spec_idisNoneand noproject_idis given or set on the client.
- create_or_get(cell_spec_id: str, data: dict[str, Any]) ParameterizedModel[source]¶
Create a new parameterized model or get an existing one.
Creates a new parameterized model if one with the same name does not already exist for the cell specification, otherwise returns the existing one. This makes setup scripts safely re-runnable, matching the
create_or_getbehaviour of the cell spec, instance, and measurement clients.- Parameters:
- Returns:
The parameterized model object (newly created or existing).
- Return type:
- update(cell_spec_id: str | None, parameterized_model_id: str, data: dict[str, Any], *, summary: bool = False) ParameterizedModel[source]¶
Update a parameterized model’s name, description, or simulation settings.
Pass
summary=Trueto return metadata without parameter values or model config.- Parameters:
cell_spec_id (str | None) – The ID of the cell specification the model belongs to, or
Nonefor a model with no cell specification.parameterized_model_id (str) – The ID of the parameterized model to update.
data (dict[str, Any]) – Dictionary containing the fields to update. Supports
name,description, andsimulation_settings(aSimulationSettingsobject or its config dict; sendnullto clear the persisted settings and fall back to the base model / defaults).
- Returns:
The updated parameterized model object.
- Return type:
- create_version(cell_spec_id: str | None, parameterized_model_id: str, parameters: dict[str, Any] | None = None, description: str | None = None, simulation_settings: Any = None, *, summary: bool = False) ParameterizedModel[source]¶
Save a new version of a parameterized model with some parameters changed.
Pass
summary=Trueto return metadata without parameter values or model config.Parameter values cannot be edited in place, so this is how a model is revised. The version keeps the parent’s base model, cell specification and name, starts from the parent’s parameters (calculations kept, so changing an input recomputes them) and applies
parameterson top. The parent is left unchanged, so runs made with it keep the values they used.- Parameters:
cell_spec_id (str | None) – The cell specification the model belongs to, or
Nonefor a model with no cell specification. A mismatch 404s.parameterized_model_id (str) – The version to start from.
parameters (dict[str, Any] | None, optional) – Values that differ from the parent’s, by parameter name.
description (str | None, optional) – The new version’s description. Defaults to the parent’s.
simulation_settings (SimulationSettings | dict | None, optional) – The new version’s simulation settings. Defaults to the parent’s.
- Returns:
The new version, with its
version_numberandfamily_id.- Return type:
- list_versions(parameterized_model_id: str, limit: int = 100, offset: int = 0) PaginatedList[ParameterizedModel][source]¶
List every version in a parameterized model’s family, oldest first.
- Parameters:
- Returns:
Summaries without parameter values, each with
version_number,parent_parameterized_model_idandis_current_version.- Return type:
- delete(cell_spec_id: str | None, parameterized_model_id: str) None[source]¶
Delete a parameterized model, addressed under its cell spec if it has one.
- Parameters:
- Raises:
IonworksError – 403 if the caller’s project role may not delete parameterized models.
- get_parameter_values(parameterized_model_id: str, resolve: bool = True, names: list[str] | None = None, match: str | None = None) dict[str, Any][source]¶
Get a parameterized model’s parameter values as JSON.
Returns the complete parameter set by default, suitable for use as baseline parameters in DataFit, parameterization, or optimization workflows. Version and citation metadata are excluded.
- Parameters:
parameterized_model_id (str) – The ID of the parameterized model to fetch parameters from.
resolve (bool, optional) – True (the default) returns calculated parameters as numbers. False keeps them as calculations: use it to copy values into a new model, so that changing an input there recomputes what depends on it.
names (list[str] | None, optional) – Only these parameters, by exact name. Names the model does not have are left out.
match (str | None, optional) – Only parameters whose name contains this text, case-insensitively (e.g.
"electrolyte"). Withnames, a parameter must satisfy both.
- Returns:
The parameter values as JSON, narrowed by
namesandmatch.- Return type: