Summary
I am trying to scale, solve, and unscale a pyomo model. The code itself worked well until I tried to scale but it didn't get a solution probably due to scaling issues. Now, after scaling, the model solves but I get an error when I try to scale it back. Unfortunately, I couldn't find any application in the doc on how to actually use the ```propagate_solution''' method.
I will try to provide a few lines of code to summarize what I'm doing without making it extensively long. The last line is what gives me the error
Steps to reproduce the issue
# example.py
from pyomo.environ import *
from pyomo.dae import *
model = ConcreteModel()
model.t = ContinuousSet(bounds=(0, 5))
model.x = ContinuousSet(bounds=(0, 3))
model.y = Var(model.t, model.x)
model.z = Var(model.t, model.x)
model.dydt = DerivativeVar(model.y, wrt=model.t)
model.dzdt = DerivativeVar(model.z, wrt=model.t)
model.dydx = DerivativeVar(model.y, wrt=model.x)
model.dzdx = DerivativeVar(model.z, wrt=model.x)
2 differential equations here in y and z
2 algebraic equations here in y and z
Discretize both y and z
# create the scaling factors
model.scaling_factor = Suffix(direction=Suffix.EXPORT)
model.scaling_factor[model.diffeq1] = 10 # scale diffeq1
model.scaling_factor[model.z] = 0.1 # scale z
# transform the model
scaled_model = TransformationFactory('core.scale_model').create_using(model)
solver = SolverFactory('ipopt')
results = solver.solve(scaled_model, tee=True)
model = TransformationFactory('core.scale_model').propagate_solution(scaled_model, model)
Error Message
$ # ERROR: evaluating object as numeric value: scaled_dydt[0,0]
(object: <class 'pyomo.core.base.var._GeneralVarData'>)
No value for uninitialized NumericValue object scaled_dydt[0,0]
Traceback (most recent call last):
File "/Users/$USER/filename", line 291, in <module>
model = TransformationFactory('core.scale_model').propagate_solution(scaled_model, model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/$USER/anaconda3/envs/lib/python3.12/site-packages/pyomo/core/plugins/transform/scaling.py", line 326, in propagate_solution
value(scaled_v[k]) / component_scaling_factor_map[scaled_v[k]],
^^^^^^^^^^^^^^^^^^
File "/Users/$USER/anaconda3/envs/watertap-dev/lib/python3.12/site-packages/pyomo/common/numeric_types.py", line 318, in value
raise ValueError(
ValueError: No value for uninitialized NumericValue object scaled_dydt[0,0]
Information on your system
Pyomo version: 6.7.1
Python version: 3.12
Operating system: Mac OS Sonoma
How Pyomo was installed (PyPI, conda, source): conda
Solver (if applicable): ipopt
Summary
I am trying to scale, solve, and unscale a pyomo model. The code itself worked well until I tried to scale but it didn't get a solution probably due to scaling issues. Now, after scaling, the model solves but I get an error when I try to scale it back. Unfortunately, I couldn't find any application in the doc on how to actually use the ```propagate_solution''' method.
I will try to provide a few lines of code to summarize what I'm doing without making it extensively long. The last line is what gives me the error
Steps to reproduce the issue
Error Message
Information on your system
Pyomo version: 6.7.1
Python version: 3.12
Operating system: Mac OS Sonoma
How Pyomo was installed (PyPI, conda, source): conda
Solver (if applicable): ipopt