Skip to content

Commit

Permalink
Removing unnecessary test for legacy solver wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Lee committed Jun 26, 2024
1 parent 6a66e13 commit 2df54c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
25 changes: 6 additions & 19 deletions idaes/core/solvers/get_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""
This module contains the IDAES get_solver method.
"""
from pyomo.contrib.solver.base import LegacySolverWrapper

import idaes.logger as idaeslog
import idaes.core.solvers
Expand Down Expand Up @@ -58,23 +57,11 @@ def get_solver(
solver = "default"
solver_obj = idaes.core.solvers.SolverWrapper(solver, register=False)()

if isinstance(solver_obj, LegacySolverWrapper):
# 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."
)
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

return solver_obj
24 changes: 6 additions & 18 deletions idaes/core/solvers/tests/test_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,12 @@ def test_get_solver_default():

@pytest.mark.skipif(not pyo.SolverFactory("ipopt").available(False), reason="no Ipopt")
@pytest.mark.unit
def test_get_solver_default_solver_w_options(caplog):
solver = get_solver(
options={"foo": "bar", "tol": 1e-5}, writer_config={"foo": "bar"}
)

assert not isinstance(solver, LegacySolverWrapper)

assert solver.options == {
"nlp_scaling_method": "gradient-based",
"tol": 1e-5,
"max_iter": 200,
"foo": "bar",
}

assert (
"Older Pyomo solver interface does not support writer_config argument: ignoring."
in caplog.text
)
def test_get_solver_default_solver_w_options():
with pytest.raises(
AttributeError,
match="'IPOPT' object has no attribute 'config'",
):
get_solver(options={"foo": "bar", "tol": 1e-5}, writer_config={"foo": "bar"})


@pytest.mark.skipif(not pyo.SolverFactory("ipopt").available(False), reason="no Ipopt")
Expand Down

0 comments on commit 2df54c5

Please sign in to comment.