pwrs.power_models.pyomo.context#

Shared state and semantic component registry for Pyomo formulations.

class pwrs.power_models.pyomo.context.PyomoPowerModel(model, network, formulation, result_builder, option_validator, network_build_time=0.0, model_build_time=0.0, variables=<factory>, constraints=<factory>, constraint_senses=<factory>, expressions=<factory>, objective_terms=<factory>, _variable_result_order=(), _constraint_result_order=(), base_variable_groups=(), base_constraint_groups=(), extension_records=(), extensions_applied=False, extension_signature=(), base_problem_class=None)[source]#

Bases: object

A built Pyomo formulation plus the metadata required to solve it.

Parameters:
  • model (Any)

  • network (PowerNetwork)

  • formulation (str)

  • result_builder (ResultBuilder)

  • option_validator (OptionValidator)

  • network_build_time (float)

  • model_build_time (float)

  • variables (dict[str, tuple[Any, ...]])

  • constraints (dict[str, tuple[Any, ...]])

  • constraint_senses (dict[str, tuple[str, ...]])

  • expressions (dict[str, Any])

  • objective_terms (dict[str, Any])

  • _variable_result_order (tuple[str, ...])

  • _constraint_result_order (tuple[str, ...])

  • base_variable_groups (tuple[str, ...])

  • base_constraint_groups (tuple[str, ...])

  • extension_records (tuple[Any, ...])

  • extensions_applied (bool)

  • extension_signature (tuple[tuple[str, int], ...])

  • base_problem_class (str | None)

add_constraint(name, constraint, *, senses=None)[source]#

Attach and register a named custom Pyomo constraint component.

Parameters:
  • name (str)

  • constraint (Any)

  • senses (str | tuple[str, ...] | None)

Return type:

Any

add_variable(name, variable)[source]#

Attach and register an auxiliary Pyomo variable component.

Parameters:
  • name (str)

  • variable (Any)

Return type:

Any

add_objective_term(name, expression)[source]#

Attach a named expression and add it to the minimization objective.

Parameters:
  • name (str)

  • expression (Any)

Return type:

Any

add_bounded_constraint(name, expression, *, lower=None, upper=None)[source]#

Create and register one semantic group of scalar bounds.

Parameters:
  • name (str)

  • expression (Any)

  • lower (float | None)

  • upper (float | None)

Return type:

Any

add_bounded_constraints(name, bounds)[source]#

Create and register a group of scalar lower/upper bounds.

Parameters:
  • name (str)

  • bounds (tuple[tuple[Any, float | None, float | None], ...])

Return type:

Any

add_equality_constraints(name, equalities)[source]#

Create and register a group of scalar equalities.

Parameters:
  • name (str)

  • equalities (tuple[tuple[Any, float], ...])

Return type:

Any

quantity(name, index=None)[source]#

Return a semantic variable/expression group or one indexed value.

Parameters:
  • name (str)

  • index (int | None)

Return type:

Any

variable(name, index=None)[source]#

Compatibility alias for quantity().

Parameters:
  • name (str)

  • index (int | None)

Return type:

Any

unregistered_active_constraints()[source]#

Return native active constraint names missing from the registry.

Return type:

tuple[str, …]