Open
Description
Summary
The method convert_params_to_vars(model, param_names, fix_vars)
of contrib.parmest.utils
does not seem to properly address cases where a Var
bound is a mutable expression involving one or more of the Param
objects specified through param_names
Steps to reproduce the issue
- Construct a model with at least one
Var
having a bound dependent on at least oneParam
.
>>> import pyomo.environ as pyo
>>> from pyomo.contrib.parmest.utils import convert_params_to_vars
>>> m = pyo.ConcreteModel()
>>> m.q = pyo.Param(initialize=1, mutable=True)
>>> m.v = pyo.Var(bounds=(0, m.q))
>>> m.c = pyo.Constraint(expr=m.v - pyo.log(m.q) ** 2 <= 0)
>>> m.pprint()
1 Param Declarations
q : Size=1, Index=None, Domain=Any, Default=None, Mutable=True
Key : Value
None : 1
1 Var Declarations
v : Size=1, Index=None
Key : Lower : Value : Upper : Fixed : Stale : Domain
None : 0 : None : 1.0 : False : True : Reals
1 Constraint Declarations
c : Size=1, Index=None, Active=True
Key : Lower : Body : Upper : Active
None : -Inf : v - log(q)**2 : 0.0 : True
3 Declarations: q v c
- Invoke
convert_params_to_vars
:
>>> mdl = convert_params_to_vars(m, param_names=["q"])
- Check the updated model:
>>> mdl.pprint()
2 Var Declarations
q : Size=1, Index=None
Key : Lower : Value : Upper : Fixed : Stale : Domain
None : None : 1 : None : False : False : Reals
v : Size=1, Index=None
Key : Lower : Value : Upper : Fixed : Stale : Domain
None : 0 : None : 1.0 : False : True : Reals
2 Constraint Declarations
c : Size=1, Index=None, Active=False
Key : Lower : Body : Upper : Active
None : -Inf : v - log(q)**2 : 0.0 : False
constraints : Size=1, Index={1}, Active=True
Key : Lower : Body : Upper : Active
1 : -Inf : v - log(q)**2 : 0.0 : True
4 Declarations: v c q constraints
- Check the upper bound of
v
further. Notice that the upper bound is aParam
object namedq
that is neitherm.q
normdl.q
and does not live on the modelmdl
returned byconvert_params_to_vars
:
>>> mdl.v.ub
1
>>> mdl.v.upper
q
>>> mdl.v.upper is mdl.q
False
>>> mdl.v.upper is m.q
False
>>> type(mdl.v.upper)
<class 'pyomo.core.base.param.ScalarParam'>
>>> mdl.v.upper.model() is None
True
Information on your system
Pyomo version: 6.8.1dev0 @ df51e99
Python version: 3.12.3
Operating system: Ubuntu 20.04
How Pyomo was installed (PyPI, conda, source): source
Solver (if applicable):