Constraints

Constraint classes for enforcing constraints in optimization problems.

class ionworkspipeline.data_fits.objective_functions.regularizers.Constraint(fun: Symbol | Number, regularizer_weight: float | None = None)

An equality or inequality constraint on the fit inputs.

An equality is a pybamm.Symbol f(x) that evaluates to 0 when satisfied; an inequality is a Heaviside g(x) <= h(x). Either is a soft penalty on the cost, w * f(x)**2 or w * max(0, g(x) - h(x))**2, applied the same way by every scipy optimizer and method. A fit can sit slightly past the boundary; raise regularizer_weight to tighten it.

Parameters

funpybamm.Symbol or Number

The constraint expression as a pybamm symbol or a constant number.

regularizer_weightfloat, optional

Weight applied to the constraint term. Default is 1.0.

Extends: Regularizer

See also: Constraint — field-level documentation.

property is_inequality: bool

bool: Whether this constraint is an inequality constraint.

process_symbol(parameter_values: ParameterValues)

Process the stored symbolic expression into an evaluable function. For inequality constraints (heavisides), unwraps into max(0, lhs - rhs).

Parameters

parameter_valuespybamm.ParameterValues

The parameter values used to resolve parameters in the expression.

class ionworkspipeline.data_fits.objective_functions.regularizers.ConstraintSet(regularizers: list | tuple | ndarray, x_to_inputs, regularizer_set_weight: float | None = None)

A set of constraints.

Parameters

regularizerslist, tuple or ndarray

Collection of constraint terms.

x_to_inputscallable

Function converting parameter vectors to input dictionaries.

regularizer_set_weightfloat, optional

Weight applied to the entire constraint set. Default is 1.0.

Extends: RegularizerSet

property base_regularizer_type

type: The base type for regularizers in this set.

Utility Functions

ionworkspipeline.data_fits.objective_functions.regularizers.constraints.DEFAULT_CONSTRAINT_SET_WEIGHT()