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

Ipopt-v2 #1406

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion watertap/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _handle_requires_idaes_solver(

solver = solver or get_solver()
idaes_bin_dir = Path(bin_directory).resolve()
solver_bin_path = Path(solver.executable()).resolve()
solver_bin_path = Path(solver.config.executable.path()).resolve()

if not idaes_bin_dir in solver_bin_path.parents:
action(f"This test is known to be failing with {solver_bin_path}")
Expand Down
19 changes: 16 additions & 3 deletions watertap/core/plugins/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import pyomo.environ as pyo
from pyomo.common.collections import Bunch
from pyomo.solvers.plugins.solvers.IPOPT import IPOPT
from pyomo.contrib.solver.base import LegacySolverWrapper
from pyomo.contrib.solver.ipopt import Ipopt

import idaes.core.util.scaling as iscale
from idaes.core.util.scaling import (
Expand All @@ -36,14 +37,18 @@ def _pyomo_nl_writer_logger_filter(record):
return True


class LegacyWrapperIpopt(LegacySolverWrapper, Ipopt):
pass


@pyo.SolverFactory.register(
"ipopt-watertap",
doc="The Ipopt NLP solver, with user-based variable and automatic Jacobian constraint scaling",
)
class IpoptWaterTAP:

name = "ipopt-watertap"
_base_solver = IPOPT
_base_solver = LegacyWrapperIpopt

def __init__(self, **kwds):
kwds["name"] = self.name
Expand All @@ -60,7 +65,7 @@ def __getattr__(self, attr):

def solve(self, blk, *args, **kwds):

solver = self._base_solver()
solver = self._base_solver(options={})
self._tee = kwds.get("tee", False)

self._original_options = self.options
Expand All @@ -81,6 +86,14 @@ def solve(self, blk, *args, **kwds):
if "honor_original_bounds" not in self.options:
self.options["honor_original_bounds"] = "no"

# Setup writer_config
if "writer_config" not in kwds:
kwds["writer_config"] = {}
if "linear_presolve" not in kwds["writer_config"]:
kwds["writer_config"]["linear_presolve"] = True
if "scale_model" not in kwds["writer_config"]:
kwds["writer_config"]["scale_model"] = False

if not self._is_user_scaling():
for k, v in self.options.items():
solver.options[k] = v
Expand Down
4 changes: 2 additions & 2 deletions watertap/core/plugins/tests/test_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def test_passthrough_positive(self, m, s):
def test_passthrough_negative(self, m, s):
s.options["nlp_scaling_method"] = "gradient-based"
s.options["ignore_variable_scaling"] = True
with pytest.raises(ApplicationError):
pyo.assert_optimal_termination(s.solve(m, tee=True))
with pytest.raises(RuntimeError):
s.solve(m, tee=True)
del s.options["nlp_scaling_method"]
del s.options["ignore_variable_scaling"]
self._test_bounds(m)
Expand Down
Loading