Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
1.95k stars 504 forks source link

k_aug interface in Pyomo sensitivity toolbox reports wrong answer #2123

Open adowling2 opened 2 years ago

adowling2 commented 2 years ago

Summary

For the following simple example:

'''
Consider the following optimization problem.
min f:  p1*x1+ p2*(x2^2) + p1*p2
         s.t  c1: x1 + x2 = p1
              c2: x2 + x3 = p2
              0 <= x1, x2, x3 <= 10
              p1 = 10
              p2 = 5
Variables = (x1, x2, x3)
Parameters (fixed variables) = (p1, p2)
'''

The k_aug interface in pyomo/contrib/sensitivity_toolbox/sens.py does not give the correct sensitivity values (which can be calculated analytically).

The k_aug interface in /idaes/apps/uncertainty_propagation/sens.py does give the correct answer.

Moreover, sens.py in Pyomo has been updated in the past few months including improved comments and some code refactorization. There is a larger need to merge these two versions of sens.py (and the IDAES toolbox should use the version in Pyomo).

Steps to reproduce the issue

The code for the example is here: https://github.com/IDAES/idaes-pse/blob/main/idaes/apps/uncertainty_propagation/examples/simple_opt_problem.py

A new .py file to show the inconsistency will be added to the corresponding PR for this issue.

Error Message

No error message, but calculated values do not match the analytic solution.

Information on your system

Pyomo version: Python version: Operating system: How Pyomo was installed (PyPI, conda, source): Solver (if applicable):

Additional information

jialuw96 commented 2 years ago

Two separate issues for minimal working examples in PR #2124 :

(1) get_dfds_dcds() has the same (wrong) behavior for sens.py in IDAES and Pyomo. It is missing a non-zero entry.

(2) get_dsdp() gives different results for sens.py in IDAES and Pyomo. The IDAES version is correct, but the Pyomo version has the code clarity enhancement you have made in the past few months.

Robbybp commented 2 years ago

@adowling2 @jialuw96 I looked at this last year and was unable to reproduce the issue. Is this still a problem? The code I ran is attached.

sens_example.zip

adowling2 commented 2 years ago

@jialuw96 Can you provide an update on this here?