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

Clarify Output of generate_standard_repn(compute_values=False) for Expressions with Mutable Params #3128

Open
shermanjasonaf opened this issue Feb 8, 2024 · 0 comments
Labels

Comments

@shermanjasonaf
Copy link
Contributor

Summary

Consider the following setup:

>>> import pyomo.environ as pyo
>>> from pyomo.repn.standard_repn import generate_standard_repn
>>> m.v = pyo.Var()
>>> m.p = pyo.Param(initialize=1, mutable=True)
>>> m.con = pyo.Constraint(expr=m.v * m.v * m.p == 0)
>>> print(generate_standard_repn(m.con.body, compute_values=False))
constant:       p*0*0
linear vars:    []
linear var ids: []
linear coef:    []
quadratic vars:    [('v', 'v')]
quadratic var ids: [(139757446926000, 139757446926000)]
quadratic coef:    [<pyomo.core.base.param.ScalarParam object at 0x7f1bd157d680>]
nonlinear expr:
p*(p*0)*v + p*(p*0)*v
nonlinear vars: ['v']

As the snippet shows, generate_standard_repn returns a representation with a nonempty list of nonlinear Vars. This may lead one to believe that the nonlinearities of m.con.body are beyond quadratic in nature. The accuracy of contrib.pyros.util.coefficient_matching, which utilizes generate_standard_repn to analyze constraint expressions, may be affected.

I originally expected generate_standard_repn would return

>>> print(generate_standard_repn(m.con.body, compute_values=False))
constant:       0
linear vars:    []
linear var ids: []
linear coef:    []
quadratic vars:    [('v', 'v')]
quadratic var ids: [(139757446926000, 139757446926000)]
quadratic coef:    [<pyomo.core.base.param.ScalarParam object at 0x7f1bd157d680>]
nonlinear expr: None
nonlinear vars: []

At the very least, it would be nice to add a docstring to the function generate_standard_repn() to clarify the meanings of the function's parameters.

Information on your system

Pyomo version: 6.7.1dev0 @ 1e259f6c1
Python version: 3.9.17
Operating system: Ubuntu 20.04
How Pyomo was installed (PyPI, conda, source): source
Solver (if applicable): N/A

@shermanjasonaf shermanjasonaf changed the title Clarify Output of generate_standard_repn(compute_values=False) for Expressions with Mutable Params Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 participant