flexops.surrogates¶
Predefined classes for surrogate structures. A
SurrogateSpec names one by
SurrogateType and carries its config and
parameters. Each class owns its contract: it defines what config holds,
which parameters (names and shapes) that config implies, and how to build the
Pyomo relationship. It validates a spec in __init__ without building any
Pyomo objects, builds in build(), and
reads its live spec back with read_spec().
swap_relation() is the only caller
of build, whether the surrogate came from a spec at build time or was
supplied at runtime through apply_to_model().
This is a leaf subpackage of flexops (it imports only flexcore,
pydantic and Pyomo), which is what lets flexops.core.ops_block realize a
config’s surrogate at construction time with no flexparameterize import
anywhere in flexops. flexparameterize builds specs only through each
class’s make_spec.
SurrogateType -> the class that implements it. |
- flexops.surrogates.surrogates.surrogate_from_spec(spec: SurrogateSpec) Surrogate¶
Construct and validate the surrogate
specnames.The surrogate migrates an older
config_versionof its own config.- Parameters:
spec – The
SurrogateSpecto realize.- Returns:
The constructed, validated
Surrogate.- Raises:
FlexConfigError – If no class is registered for
spec.surrogate_typeorspecdoes not match its contract.NotImplementedError – If the named class is not yet implemented.
- flexops.surrogates.surrogates.surrogate_class(surrogate_type: SurrogateType | str) type[Surrogate]¶
Return the class registered for
surrogate_type.- Parameters:
surrogate_type – A
SurrogateTypeor its value.- Returns:
The registered class.
- Raises:
FlexConfigError – If no class is registered for it.
- flexops.surrogates.surrogates.is_registered(surrogate: Surrogate) bool¶
Return whether
surrogate’s class is the one registered for its type.Only a registered class can be rebuilt from a spec, so only such a surrogate is written out by
emit_model; a custom subclass is not.- Parameters:
surrogate – A surrogate instance.
- Returns:
Truewhentype(surrogate)isSURROGATES[surrogate_type].
Base class¶
Base class of every predefined surrogate-structure class. |
Every subclass declares input_variables/output_variables as
{name: units} mappings in its config. These are the units the relationship
was fitted or declared in, not necessarily the model’s own. build converts
each factor from the unit’s actual variable into the surrogate’s declared
units before using it, and swap_relation()
converts the whole body from the surrogate’s declared output units into the
registered target’s own units. Both conversions double as validation. A
declared unit dimensionally incompatible with the model’s variable raises a
FlexConfigError rather than silently rescaling.
Developing a surrogate starts with its contract: subclass
Surrogate, define config_model,
parameter_shapes and a typed make_spec, implement _build
registering every parameter, and add the class to
SURROGATES. The shared contract tests
then cover it. Regression tooling comes after, producing specs only through
make_spec. A change to a type’s config format bumps its config_version
and adds a migrate_config step.
Multilinear¶
A constant plus a sum of coefficient * (product of distinct declared
inputs). This is the expanded form that covers what a previous milestone
called linear (no cross terms) and bilinear (one cross term).
config.terms lists the products, each a product of names from
input_variables, separated by *, each appearing at most once (no ^
exponent, no repeated factor). The parameters are intercept, the constant
term read in the declared output units, plus one per term.
A constant plus a sum of coefficient * (product of distinct inputs). |
|
A multilinear surrogate's config: its variables and its product terms. |
ARIMA¶
A non-seasonal ARIMA(p, d, q) with exogenous inputs. config holds the
order, the deterministic term (intercept for d=0, drift for
d=1, or none), an optional max_ar_coeff and the pre-horizon
history. The parameters are the deterministic term, ar.L1 to ar.Lp,
ma.L1 to ma.Lq and exog.<input> per input.
unit.update_surrogate_state() rewrites history from a solved horizon.
Non-seasonal ARIMA/ARIMAX relationship with explicit innovations. |
|
An ARIMA surrogate's config: order, variables, options and history. |
|
Pre-horizon ARIMA state: disturbances and innovations on a dated grid. |
|
Return an ARIMA surrogate's parameter names, in registration order. |
Constant intensity¶
Sets a unit’s energy_intensity (its one parameter) rather than swapping a
relation; the unit already has the relationship
power_electrical == energy_intensity * flow.
Sets a unit's |
|
A constant-intensity surrogate's config: the variables, for reference. |
Not yet implemented¶
A quadratic (up to degree-2, including squared terms) relationship. |
|
An exponential relationship in its inputs. |
|
A neural-network (e.g. ReLU big-M or ICNN) forward-pass relationship. |