IDAES / idaes-pse

The IDAES Process Systems Engineering Framework
https://idaes-pse.readthedocs.io/
Other
218 stars 235 forks source link

Solver issue with compute_infeasibility_explanation() in Diagnostic Toolbox #1520

Closed luohezhiming closed 2 weeks ago

luohezhiming commented 2 weeks ago

The compute_infeasibility_explanation() fails to solve after the numerical issues are reported. The errors are:

ERROR: Unable to clone Pyomo component attribute. Component 'FiniteSetOf'
contains an uncopyable field '_ref' (<class 'dict_keys'>).  Setting field to
`None` on new object
ERROR: Unable to clone Pyomo component attribute. Component 'FiniteSetOf'
contains an uncopyable field '_ref' (<class 'dict_keys'>).  Setting field to
`None` on new object
ERROR: Unable to clone Pyomo component attribute. Component 'FiniteSetOf'
contains an uncopyable field '_ref' (<class 'dict_keys'>).  Setting field to
`None` on new object
WARNING: model contains export suffix 'scaling_factor' that contains 1134
component keys that are not exported as part of the NL file.  Skipping.
WARNING: model contains export suffix 'scaling_factor' that contains 274 keys
that are not Var, Constraint, Objective, or the model.  Skipping.
WARNING: model contains export suffix 'scaling_factor' that contains 1134
component keys that are not exported as part of the NL file.  Skipping.
WARNING: model contains export suffix 'scaling_factor' that contains 274 keys
that are not Var, Constraint, Objective, or the model.  Skipping.
WARNING: model contains export suffix 'scaling_factor' that contains 92
component keys that are not exported as part of the NL file.  Skipping.
WARNING: model contains export suffix 'scaling_factor' that contains 274 keys
that are not Var, Constraint, Objective, or the model.  Skipping.
WARNING: model contains export suffix 'scaling_factor' that contains 1135
component keys that are not exported as part of the NL file.  Skipping.
WARNING: model contains export suffix 'scaling_factor' that contains 274 keys
that are not Var, Constraint, Objective, or the model.  Skipping.
Could not find a feasible solution with violated constraints or bounds. This model is likely unstable
WARNING: model contains export suffix 'scaling_factor' that contains 2263
component keys that are not exported as part of the NL file.  Skipping.
WARNING: model contains export suffix 'scaling_factor' that contains 274 keys
that are not Var, Constraint, Objective, or the model.  Skipping.
Traceback (most recent call last):
  File "C:\Users\wcy78\anaconda3\envs\watertap-dev\Lib\site-packages\IPython\core\interactiveshell.py", line 3577, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-4381b6494d21>", line 1, in <module>
    runfile('D:/Keylogic/WaterTap_Chenyu/watertap/watertap/flowsheets/electroNP/BSM2_electroNP_surrogate_bioP_initialization_refined.py', wdir='D:/Keylogic/WaterTap_Chenyu/watertap/watertap/flowsheets/electroNP')
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.2\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/Keylogic/WaterTap_Chenyu/watertap/watertap/flowsheets/electroNP/BSM2_electroNP_surrogate_bioP_initialization_refined.py", line 1438, in <module>
    m, results = main(has_electroNP=True)
                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:/Keylogic/WaterTap_Chenyu/watertap/watertap/flowsheets/electroNP/BSM2_electroNP_surrogate_bioP_initialization_refined.py", line 165, in main
    dt.compute_infeasibility_explanation()
  File "C:\Users\wcy78\anaconda3\envs\watertap-dev\Lib\site-packages\idaes\core\util\model_diagnostics.py", line 775, in compute_infeasibility_explanation
    mis.compute_infeasibility_explanation(
  File "C:\Users\wcy78\anaconda3\envs\watertap-dev\Lib\site-packages\pyomo\contrib\iis\mis.py", line 290, in compute_infeasibility_explanation
    if pyo.check_optimal_termination(results):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\wcy78\anaconda3\envs\watertap-dev\Lib\site-packages\pyomo\opt\results\solver.py", line 152, in check_optimal_termination
    if results.solver.status == SolverStatus.ok and (
       ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'solver'
adam-a-a commented 2 weeks ago

I was just about to report the same issue that I had put off posting. The problem is here https://github.com/Pyomo/pyomo/blob/main/pyomo/contrib/iis/mis.py#L285-L290:

    try:
        results = solver.solve(modified_model, tee=tee)
    except:
        results = None

When the solve fails and check_optimal_termination is called on results which is None, we get back this unhelpful error.

I guess the question is--assuming that being able to solve the problem at hand would not be trivial or possible---can we return a better exception? And I suppose that this issue might technically belong on Pyomo.

andrewlee94 commented 2 weeks ago

I am fairly certain this is a Pyomo issue - @jsiirola @blnicho @bknueven any ideas on the best course of action?

bknueven commented 2 weeks ago

https://github.com/Pyomo/pyomo/blob/ad90ee2b050f58a85cc27aa733499851e5f44557/pyomo/contrib/iis/mis.py#L290

This conditional should first check that results is not None before pyo.check_optimal_termination(results).

luohezhiming commented 2 weeks ago

I was just about to report the same issue that I had put off posting. The problem is here https://github.com/Pyomo/pyomo/blob/main/pyomo/contrib/iis/mis.py#L285-L290:

    try:
        results = solver.solve(modified_model, tee=tee)
    except:
        results = None

When the solve fails and check_optimal_termination is called on results which is None, we get back this unhelpful error.

I guess the question is--assuming that being able to solve the problem at hand would not be trivial or possible---can we return a better exception? And I suppose that this issue might technically belong on Pyomo.

My case is kind of similar to you, I use Degeneracy Hunter to run this problem and it diverge to a infeasible point

lbianchi-lbl commented 2 weeks ago

Since this was fixed upstream in Pyomo, this requires IDAES and/or its clients to update to a recent enough version of Pyomo that includes Pyomo/pyomo#3403.

@blnicho can you confirm whether this is in the tag that's being tested in #1523?

blnicho commented 2 weeks ago

Yes, the fix for this issue is in the tag being tested in #1523