Coverage for backend/ahuora-builder/src/ahuora_builder/methods/property_map_manipulation.py: 0%
19 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-06-23 21:51 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-06-23 21:51 +0000
1from __future__ import annotations
2from pyomo.core.base.var import ScalarVar
3from pyomo.environ import units as pyunits
4from ahuora_builder.methods.adapter import fix_slice, fix_var
5from ahuora_builder.properties_manager import PropertyComponent
7from pyomo.core.base.expression import ScalarExpression, Expression
8from pyomo.core.base.var import ScalarVar, VarData, _GeneralVarData
9from pyomo.core.base.constraint import ScalarConstraint, ConstraintData, _GeneralConstraintData
10from pyomo.core.base.indexed_component import IndexedComponent
11from pyomo.environ import value
12from sympy import var
13from ahuora_builder.methods.adapter import fix_slice
14from .units_handler import ValueWithUnits
16def update_property(property_component: PropertyComponent, values: list[ValueWithUnits]):
17 """
18 This function is used to update what a property component is fixed to.
19 For example, in the online solving, we want to update properties to their new values from the OPC UA server, and then re-solve the model.
20 This saves us from having to re-create the model and re-fix all the properties every time.
21 Args:
22 - property_component (PropertyComponent): The property component to update. This can be retrieved from the PropertiesManager.
23 - values (list[ValueWithUnits]): The new values to set the property component to. These could be a list of values with the IDAES unit attached too.
25 """
26 constraints: list[ScalarVar] = list(property_component.corresponding_constraint)
27 if len(values) != len(constraints):
28 raise ValueError(f"Number of values provided ({len(values)}) does not match the number of constraints ({len(constraints)}) for property {property_component.name} (id {property_component}). Please provide the correct number of values.")
30 for var, value in zip(constraints, values):
31 var.set_value(value)