Skip to content

Scaling transformation does not transform named Expressions #3344

Open
@dallan-keylogic

Description

@dallan-keylogic

Summary

When a model is transformed using the model scaling transformation, Expressions are created on the scaled model, but variable scaling factors are not added to them like they are for Constraints, resulting in them returning erroneous values. I've encountered this issue twice now and spent significant amounts of time debugging before I realized the scaling transform was the issue.

Steps to reproduce the issue

# expression_not_transformed.py
import pyomo.environ as pyo

m = pyo.ConcreteModel()

m.x = pyo.Var(initialize=10)
m.y = pyo.Var(initialize=0.1)

m.sum = pyo.Expression(expr=m.x+m.y)

m.scaling_factor = pyo.Suffix(direction=pyo.Suffix.EXPORT)
m.scaling_factor[m.x] = 0.1
m.scaling_factor[m.y] = 10

m_scaled = pyo.TransformationFactory('core.scale_model').create_using(m, rename=False)

print(f"Unscaled value: {pyo.value(m.sum)}")
print(f"Scaled value: {pyo.value(m_scaled.sum)}")

Results:

Unscaled value: 10.1
Scaled value: 2.0

Information on your system

Pyomo version: 6.7.4.dev0
Python version: 3.10.14
Operating system: Windows 10
How Pyomo was installed: Sources
Solver (if applicable): n/a

Additional information

The behavior I would expect would be to transform the Expression like a Constraint, using a scaling suffix if provided and otherwise just using a value of 1. In that case, both values in the example script should return 10.1. If Pyomo does not want to support scaling of Expressions, then it shouldn't even generate them on the scaled model---returning some Exception for pyo.value(m_scaled.sum).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions