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

Activating IPOPT_V2 with presolver #1436

Merged
merged 24 commits into from
Jun 26, 2024
Merged

Conversation

andrewlee94
Copy link
Member

@andrewlee94 andrewlee94 commented Jun 15, 2024

Replaces #1415

Summary/Motivation:

Second attempt at implementing new solver interface with presolve. Due to the need to maintain backward compatibility, the old model.initialize() methods will continue to use the old ipopt solver interface, whilst the new Initializers and core tests will switch to ipopt_v2. The default solver will remain ipopt for now until all the examples have been switched over (or updated to explicitly use ipopt), at which point we will deprecate the use of ipopt as the default.

Changes proposed in this PR:

  • Basic infrastructure to support new solver interface (mainly the introduction of the new writer_config argument and deprecating options for solver_options).
  • Moving common Initializers to use ipopt_v2.
  • Switch all idaes/core and idaes/models tests to use ipopt_v2.
  • Where possible, switch idaes/apps and idaes/models_extra tests to use ipopt_v2.

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.

@andrewlee94 andrewlee94 self-assigned this Jun 15, 2024
@andrewlee94 andrewlee94 added enhancement New feature or request Priority:High High Priority Issue or PR core Issues dealing with core modeling components backward-compat Affects backward compatibility deprecation Add deprecation to codebase and/or remove deprecated feature scaling_v2 labels Jun 15, 2024
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.

Overall this looks good. Eagerly awaiting the rollout of the new scaling tools, though. Can we manually activate the solve-time scaling by passing a solver writer option?

idaes/config.py Outdated Show resolved Hide resolved
Comment on lines +61 to +68
CONFIG.block_solver_options.declare(
"tol",
ConfigValue(
default=1e-8,
domain=float,
description="Convergence tolerance for block solver",
),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to set constr_viol_tol as well. I'm not sure what tol does in square problems, but in optimization problems constr_viol_tol controls the constraint violation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Whilst most tests appear to pass if we change this to 1e-6, there are a few that start failing so I will leave this out for now. Users can always set this value if they wish.

idaes/core/solvers/get_solver.py Outdated Show resolved Hide resolved
idaes/core/util/phase_equilibria.py Outdated Show resolved Hide resolved
@andrewlee94 andrewlee94 marked this pull request as ready for review June 21, 2024 16:27
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.

Looks good, although it would still be nice to keep around the solve_strongly_connected_components variant of the initializer to use as a debugging tool. Making it a config option instead of a totally different initializer is preferable because we don't want to have to maintain an additional, parallel routine that's 90% the same.

idaes/config.py Outdated
@@ -346,7 +344,6 @@ def _new_idaes_config_block():
domain=str,
default="gradient-based",
description="Ipopt NLP scaling method",
doc="Ipopt NLP scaling method",
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between the doc and description fields, anyway?

Copy link
Member Author

Choose a reason for hiding this comment

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

Long (doc) and short (description) doc strings - which one shows up depends on exactly what you use to display the config block/value.

@codecov-commenter
Copy link

codecov-commenter commented Jun 21, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 12 lines in your changes missing coverage. Please review.

Project coverage is 77.73%. Comparing base (a66d4c4) to head (2df54c5).
Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
...erties/modular_properties/base/generic_property.py 57.89% 4 Missing and 4 partials ⚠️
idaes/core/solvers/config.py 33.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1436      +/-   ##
==========================================
- Coverage   77.83%   77.73%   -0.10%     
==========================================
  Files         394      394              
  Lines       64926    64953      +27     
  Branches    14398    14404       +6     
==========================================
- Hits        50535    50494      -41     
- Misses      11807    11879      +72     
+ Partials     2584     2580       -4     

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

Copy link
Contributor

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

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

Overall, looks good. One question for @andrewlee94...

if solver is None:
solver = "default"
solver_obj = idaes.core.solvers.SolverWrapper(solver, register=False)()

if options is not None:
solver_obj.options.update(options)
if isinstance(solver_obj, LegacySolverWrapper):
Copy link
Contributor

Choose a reason for hiding this comment

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

It is unfortunate that we need to have this test here: the whole point of the Legacy interface is that you shouldn't have to change your code. Is there a reason why you can't just do:

if options is not None:
    for k, v in options.items():
        solver_obj.options[k] = v
if writer_config is not None:
    for k, v in writer_config.items():
        solver_obj.config.writer_config[k] = v

for both new and old solvers? If there writer_config is not None for an old solver, it should just generate an error when you try to set the value on config.writer_config...

Copy link
Member Author

Choose a reason for hiding this comment

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

I can definitely try (and this is why I was waiting for your review).

@andrewlee94 andrewlee94 added the CI:run-integration triggers_workflow: Integration label Jun 26, 2024
@idaes-build idaes-build removed the CI:run-integration triggers_workflow: Integration label Jun 26, 2024
@andrewlee94 andrewlee94 merged commit 2e58de6 into IDAES:main Jun 26, 2024
48 checks passed
@andrewlee94 andrewlee94 deleted the presolve branch June 26, 2024 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backward-compat Affects backward compatibility core Issues dealing with core modeling components deprecation Add deprecation to codebase and/or remove deprecated feature enhancement New feature or request Priority:High High Priority Issue or PR scaling_v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants