Skip to content

Comments

Add Solver Config Option to IPOPT Convergence Analysis#1606

Merged
dallan-keylogic merged 5 commits intoIDAES:mainfrom
MarcusHolly:convergence_analysis_solver
Apr 10, 2025
Merged

Add Solver Config Option to IPOPT Convergence Analysis#1606
dallan-keylogic merged 5 commits intoIDAES:mainfrom
MarcusHolly:convergence_analysis_solver

Conversation

@MarcusHolly
Copy link
Contributor

@MarcusHolly MarcusHolly commented Apr 10, 2025

Summary/Motivation:

Addresses an issue in watertap-org/watertap#1563 where tests are passing locally but failing on GitHub. This is believed to be a result of this tool defaulting the solver to ipopt, whereas WaterTAP requires ipopt-watertap.

Changes proposed in this PR:

  • Adds a config option to IPOPTConvergenceAnalysis

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the license terms described in the LICENSE.txt file at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@MarcusHolly MarcusHolly added the Priority:Normal Normal Priority Issue or PR label Apr 10, 2025
@MarcusHolly MarcusHolly self-assigned this Apr 10, 2025
@codecov
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.85%. Comparing base (6e72af3) to head (1e154d7).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1606   +/-   ##
=======================================
  Coverage   76.85%   76.85%           
=======================================
  Files         394      394           
  Lines       63241    63246    +5     
  Branches    10359    10360    +1     
=======================================
+ Hits        48604    48608    +4     
- Misses      12188    12191    +3     
+ Partials     2449     2447    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MarcusHolly MarcusHolly marked this pull request as ready for review April 10, 2025 13:02
Copy link
Contributor

@dallan-keylogic dallan-keylogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid mutable objects as default arguments.

CONFIG = CACONFIG()

def __init__(self, model, **kwargs):
def __init__(self, model, solver=SolverFactory("ipopt"), **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having mutable Python objects as default arguments causes trouble, because it uses the same object each time the function is called.

In [1]: def append_a(lst=[]):
   ...:     lst.append("a")
   ...:     return lst
   ...:

In [2]: lst = append_a()

In [3]: lst = append_a()

In [4]: lst
Out[4]: ['a', 'a']

We might expect the second instance of lst to contain a single element because it's using the default argument of [], but because it uses the same instance of the list object each time the function is called, it contains two elements.

The way we work around this is by using None as the default argument, then creating an object if the argument is None:

def __init__(self, model, solver=None, **kwargs):
    if solver is None:
        solver = SolverFactory("ipopt")

Also, if you expect a solver object to be passed, you should make solver_obj the name of the function argument. It would be even better to add it as a config argument instead of an argument to __init__.

I assume that ipopt_watertap has some set of default options different than those in IDAES.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Doug! I didn't realize default arguments for each instance builds on top of the previous ones. I've set the default solver argument to None.

I'm not too familiar with the differences between ipopt and ipopt-watertap other than the fact that using ipopt has caused issues in the past.

Copy link
Contributor

@agarciadiego agarciadiego Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcusHolly It's a tricky issue, and it would have caused major headaches for me if I hadn't been alerted to it by senior team members.

CONFIG = CACONFIG()

def __init__(self, model, **kwargs):
def __init__(self, model, solver=None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also change the name from solver to solver_obj? Typically if we had solver as the default argument, we'd pass the string "ipopt" instead of an IPOPT solver object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Contributor

@dallan-keylogic dallan-keylogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dallan-keylogic dallan-keylogic requested a review from bpaul4 April 10, 2025 18:04
@dallan-keylogic dallan-keylogic enabled auto-merge (squash) April 10, 2025 18:15
@dallan-keylogic dallan-keylogic merged commit 6291747 into IDAES:main Apr 10, 2025
57 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority:Normal Normal Priority Issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants