Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing scaling bug related to external functions with string arguments #1487

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions idaes/core/util/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,10 +1472,14 @@ def _get_nominal_value_expr_if(self, node, child_nominal_values):

def _get_nominal_value_external_function(self, node, child_nominal_values):
# First, need to get expected magnitudes of input terms, which may be sub-expressions
input_mag = [
self._get_nominal_value_for_sum_subexpression(i)
for i in child_nominal_values
]
input_mag = []
for i in child_nominal_values:
if isinstance(i[0], str):
# Sometimes external functions might have string arguments
# Check here, and return the string if true
input_mag.append(i[0])
else:
input_mag.append(self._get_nominal_value_for_sum_subexpression(i))

# Next, create a copy of the external function with expected magnitudes as inputs
newfunc = node.create_node_with_local_data(input_mag)
Expand Down
11 changes: 11 additions & 0 deletions idaes/core/util/tests/test_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
CubicThermoExpressions,
CubicType as CubicEoS,
)
from idaes.models.properties import iapws95

__author__ = "John Eslick, Tim Bartholomew"

Expand Down Expand Up @@ -2230,6 +2231,16 @@ def test_constraint(self, m):
expr=m.constraint.expr
) == [21, 0.5 ** (22 + 23 + 24)]

@pytest.mark.component
def test_external_function_w_string_argument(self):
m = pyo.ConcreteModel()
m.properties = iapws95.Iapws95ParameterBlock()
m.state = m.properties.build_state_block([0])

assert sc.NominalValueExtractionVisitor().walk_expression(
expr=m.state[0].temperature
) == [pytest.approx(235.0, rel=1e-8)]


@pytest.fixture(scope="function")
def m():
Expand Down
Loading