CoefficientRegistry¶
- class flexops.core.registration.CoefficientRegistry¶
A dict-like
name -> Varcontainer for a surrogate block’s coefficients.Each registered name is one surrogate parameter, the unit a spec’s
parametersaddresses. A parameter is either a scalar (a scalar Var or one entry of an indexed Var) or an array (a whole indexed Var, one name for many values, e.g. an ML weight matrix). An array’s values map onto the Var’s index set in its iteration order, read row-major for nested lists; onefixedflag covers the whole array.To register every entry of an indexed Var as its own scalar parameter, named by its index, pass it to
register_coefficients().The registry dynamically expands as coefficients are registered. It is attached to every surrogate block as
block.coefficientsbeforebuild()returns, so a developer can callregister_coefficientmultiple times in a singlebuild()method — useful when coefficients come from several independent Var groups (e.g. separate low-flow and high-flow regimes).- is_partially_fixed(name: str) bool¶
Return whether an array parameter has some entries fixed and some free.
- items()¶
Return the registered (name, Var) pairs; an array’s Var is indexed.
- register_coefficient(name: str, var: Any, *, shape: tuple[int, ...] | None = None) None¶
Add one named parameter: a scalar Var entry, or a whole indexed Var.
- Parameters:
name – The parameter name used by specs,
update_parametersandregister_surrogate_coefficients.var – A scalar Pyomo Var or one entry of an indexed Var (a scalar parameter), or a whole indexed Var (an array parameter).
shape – An array parameter’s shape, e.g.
(3, 2). Defaults to(len(var),)for an indexed Var; must be()or omitted for a scalar.
- Raises:
FlexConfigError – If
nameis already registered,varis not a Pyomo Var, orshapedoes not matchvar’s size.
- register_coefficients(mapping) None¶
Bulk-add scalar parameters from a name->Var mapping or an indexed Var.
- Parameters:
mapping – Either a dict of parameter name to Pyomo Var, or a single indexed
pyo.Varwhose entries each become a scalar parameter named by its index.- Raises:
FlexConfigError – If any name is already registered or any value is not a Pyomo Var or Var entry.
- set_value(name: str, value: Any) None¶
Set a parameter’s value without changing whether it is fixed.
- Parameters:
name – A registered parameter.
value – A number for a scalar; for an array, nested lists matching its shape.
- Raises:
FlexConfigError – If
value’s shape does not match the parameter’s.