-
Notifications
You must be signed in to change notification settings - Fork 238
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
Changes from 22 commits
528a4f7
0faabba
47d9d73
47beac6
c39f256
04f1463
3ce08dd
4aa1405
7353472
e88bd83
d5135f4
9ccc8b4
9423501
6754964
f6079ca
ad475fd
dda16b3
bc8e411
4273e24
542914a
6578d01
84e9d69
6a66e13
2df54c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
""" | ||
This module contains the IDAES get_solver method. | ||
""" | ||
from pyomo.contrib.solver.base import LegacySolverWrapper | ||
|
||
import idaes.logger as idaeslog | ||
import idaes.core.solvers | ||
|
@@ -22,25 +23,58 @@ | |
|
||
|
||
# Author: Andrew Lee | ||
def get_solver(solver=None, options=None): | ||
def get_solver( | ||
solver=None, | ||
solver_options: dict = None, | ||
writer_config: dict = None, | ||
options: dict = None, | ||
): | ||
""" | ||
General method for getting a solver object which defaults to the standard | ||
IDAES solver (defined in the IDAES configuration). | ||
|
||
Args: | ||
solver: string name for desired solver. Default=None, use default solver | ||
options: dict of solver options to use, overwrites any settings | ||
solver_options: dict of solver options to use, overwrites any settings | ||
provided by IDAES configuration. Default = None, use default | ||
solver options. | ||
writer_config: dict of configuration options for solver writer, overwrites | ||
ny settings provided by IDAES configuration. Default = None, use | ||
default solver options. | ||
options: DEPRECATED. Alias of solver_options. | ||
|
||
Returns: | ||
A Pyomo solver object | ||
""" | ||
if solver_options is not None: | ||
if options is not None: | ||
raise ValueError( | ||
"Cannot provide both the 'options' and 'solver_options' argument. " | ||
"'options' has been deprecated in favor of 'solver_options'." | ||
) | ||
options = solver_options | ||
|
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
# New solver interface. | ||
# LegacySolverWrapper is a wrapper for the new solver interface that makes it | ||
# backward compatible. | ||
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 | ||
else: | ||
# Old solver interface | ||
if options is not None: | ||
solver_obj.options.update(options) | ||
if writer_config is not None: | ||
_log.info( | ||
"Older Pyomo solver interface does not support writer_config argument: ignoring." | ||
) | ||
andrewlee94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return solver_obj |
There was a problem hiding this comment.
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 whattol
does in square problems, but in optimization problemsconstr_viol_tol
controls the constraint violation.There was a problem hiding this comment.
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.