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

add support for cyipopt #2830

Merged
merged 11 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
6 changes: 5 additions & 1 deletion doc/OnlineDocs/contributed_packages/mindtpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ The following algorithms are currently available in MindtPy:
Usage and early implementation details for MindtPy can be found in the PSE 2018 paper Bernal et al.,
(`ref <https://doi.org/10.1016/B978-0-444-64241-7.50144-0>`_,
`preprint <http://egon.cheme.cmu.edu/Papers/Bernal_Chen_MindtPy_PSE2018Paper.pdf>`_).
This solver implementation has been developed by `David Bernal <https://github.com/bernalde>`_
and `Zedong Peng <https://github.com/ZedongPeng>`_ as part of research efforts at the `Bernal Research Group
<https://bernalde.github.io/>`_ and the `Grossmann Research Group <http://egon.cheme.cmu.edu/>`_
at Purdue University and Carnegie Mellon University.

.. _Duran & Grossmann, 1986: https://dx.doi.org/10.1007/BF02592064
.. _Westerlund & Petterson, 1995: http://dx.doi.org/10.1016/0098-1354(95)87027-X
Expand Down Expand Up @@ -310,6 +314,6 @@ Report a Bug
If you find a bug in MindtPy, we will be grateful if you could

- submit an `issue`_ in Pyomo repository
- directly contact David Bernal <bernalde@cmu.edu> and Zedong Peng <peng_zedong@126.com>.
- directly contact David Bernal <dbernaln@purdue.edu> and Zedong Peng <zdpeng95@gmail.com>.

.. _issue: https://github.com/Pyomo/pyomo/issues
5 changes: 0 additions & 5 deletions pyomo/contrib/mindtpy/MindtPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ class MindtPySolver(object):
- Global LP/NLP based branch-and-bound (GLP/NLP)
- Regularized LP/NLP based branch-and-bound (RLP/NLP)
- Feasibility pump (FP)

This solver implementation has been developed by David Bernal <https://github.com/bernalde>
and Zedong Peng <https://github.com/ZedongPeng> as part of research efforts at the Grossmann
Research Group (http://egon.cheme.cmu.edu/) at the Department of Chemical Engineering at
Carnegie Mellon University.
"""

CONFIG = _get_MindtPy_config()
Expand Down
31 changes: 24 additions & 7 deletions pyomo/contrib/mindtpy/algorithm_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def set_up_solve_data(self, model, config):
self.primal_bound_progress = [self.primal_bound]
self.dual_bound_progress = [self.dual_bound]

if config.nlp_solver == 'ipopt':
if config.nlp_solver in {'ipopt', 'cyipopt'}:
if not hasattr(self.working_model, 'ipopt_zL_out'):
self.working_model.ipopt_zL_out = Suffix(direction=Suffix.IMPORT)
if not hasattr(self.working_model, 'ipopt_zU_out'):
Expand Down Expand Up @@ -900,11 +900,22 @@ def init_rNLP(self, config, add_oa_cuts=True):
)
# Add OA cut
if add_oa_cuts:
dual_values = (
list(m.dual[c] for c in MindtPy.constraint_list)
if config.calculate_dual_at_solution
else None
)
if (
self.config.nlp_solver == 'cyipopt'
and self.objective_sense == minimize
):
# TODO: recover the opposite dual when cyipopt issue #2831 is solved.
dual_values = (
list(-1 * m.dual[c] for c in MindtPy.constraint_list)
if config.calculate_dual_at_solution
else None
)
else:
dual_values = (
list(m.dual[c] for c in MindtPy.constraint_list)
if config.calculate_dual_at_solution
else None
)
ZedongPeng marked this conversation as resolved.
Show resolved Hide resolved
copy_var_list_values(
m.MindtPy_utils.variable_list,
self.mip.MindtPy_utils.variable_list,
Expand Down Expand Up @@ -1194,6 +1205,12 @@ def handle_subproblem_optimal(self, fixed_nlp, config, cb_opt=None, fp=False):
for c in fixed_nlp.tmp_duals:
if fixed_nlp.dual.get(c, None) is None:
fixed_nlp.dual[c] = fixed_nlp.tmp_duals[c]
elif (
self.config.nlp_solver == 'cyipopt'
and self.objective_sense == minimize
):
# TODO: recover the opposite dual when cyipopt issue #2831 is solved.
fixed_nlp.dual[c] = -fixed_nlp.dual[c]
ZedongPeng marked this conversation as resolved.
Show resolved Hide resolved
dual_values = list(
fixed_nlp.dual[c] for c in fixed_nlp.MindtPy_utils.constraint_list
)
Expand Down Expand Up @@ -1798,7 +1815,7 @@ def set_up_mip_solver(self, config, regularization_problem=False):
The customized MIP solver.
"""
# Deactivate extraneous IMPORT/EXPORT suffixes
if config.nlp_solver == 'ipopt':
if config.nlp_solver in {'ipopt', 'cyipopt'}:
getattr(self.mip, 'ipopt_zL_out', _DoNothing()).deactivate()
getattr(self.mip, 'ipopt_zU_out', _DoNothing()).deactivate()
if regularization_problem:
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/mindtpy/config_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def _add_subsolver_configs(CONFIG):
'nlp_solver',
ConfigValue(
default='ipopt',
domain=In(['ipopt', 'appsi_ipopt', 'gams', 'baron']),
domain=In(['ipopt', 'appsi_ipopt', 'gams', 'baron', 'cyipopt']),
description='NLP subsolver name',
doc='Which NLP subsolver is going to be used for solving the nonlinear'
'subproblems.',
Expand Down
19 changes: 4 additions & 15 deletions pyomo/contrib/mindtpy/extended_cutting_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,16 @@
@SolverFactory.register(
'mindtpy.ecp', doc='MindtPy: Mixed-Integer Nonlinear Decomposition Toolbox in Pyomo'
)
class MindtPy_OA_Solver(_MindtPyAlgorithm):
class MindtPy_ECP_Solver(_MindtPyAlgorithm):
"""
Decomposition solver for Mixed-Integer Nonlinear Programming (MINLP) problems.

The MindtPy (Mixed-Integer Nonlinear Decomposition Toolbox in Pyomo) solver
applies a variety of decomposition-based approaches to solve Mixed-Integer
Nonlinear Programming (MINLP) problems.
These approaches include:

- Outer approximation (OA)
- Global outer approximation (GOA)
- Regularized outer approximation (ROA)
- LP/NLP based branch-and-bound (LP/NLP)
- Global LP/NLP based branch-and-bound (GLP/NLP)
- Regularized LP/NLP based branch-and-bound (RLP/NLP)
- Feasibility pump (FP)

This solver implementation has been developed by David Bernal <https://github.com/bernalde>
and Zedong Peng <https://github.com/ZedongPeng> as part of research efforts at the Grossmann
Research Group (http://egon.cheme.cmu.edu/) at the Department of Chemical Engineering at
Carnegie Mellon University.
This class includes:

- Extended Cutting Plane (ECP)
"""

CONFIG = _get_MindtPy_ECP_config()
Expand Down
13 changes: 1 addition & 12 deletions pyomo/contrib/mindtpy/feasibility_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,9 @@ class MindtPy_FP_Solver(_MindtPyAlgorithm):
The MindtPy (Mixed-Integer Nonlinear Decomposition Toolbox in Pyomo) solver
applies a variety of decomposition-based approaches to solve Mixed-Integer
Nonlinear Programming (MINLP) problems.
These approaches include:
This class includes:

- Outer approximation (OA)
- Global outer approximation (GOA)
- Regularized outer approximation (ROA)
- LP/NLP based branch-and-bound (LP/NLP)
- Global LP/NLP based branch-and-bound (GLP/NLP)
- Regularized LP/NLP based branch-and-bound (RLP/NLP)
- Feasibility pump (FP)

ZedongPeng marked this conversation as resolved.
Show resolved Hide resolved
This solver implementation has been developed by David Bernal <https://github.com/bernalde>
and Zedong Peng <https://github.com/ZedongPeng> as part of research efforts at the Grossmann
Research Group (http://egon.cheme.cmu.edu/) at the Department of Chemical Engineering at
Carnegie Mellon University.
"""

CONFIG = _get_MindtPy_FP_config()
Expand Down
14 changes: 2 additions & 12 deletions pyomo/contrib/mindtpy/global_outer_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,17 @@
@SolverFactory.register(
'mindtpy.goa', doc='MindtPy: Mixed-Integer Nonlinear Decomposition Toolbox in Pyomo'
)
class MindtPy_OA_Solver(_MindtPyAlgorithm):
class MindtPy_GOA_Solver(_MindtPyAlgorithm):
"""
Decomposition solver for Mixed-Integer Nonlinear Programming (MINLP) problems.

The MindtPy (Mixed-Integer Nonlinear Decomposition Toolbox in Pyomo) solver
applies a variety of decomposition-based approaches to solve Mixed-Integer
Nonlinear Programming (MINLP) problems.
These approaches include:
This class includes:

- Outer approximation (OA)
- Global outer approximation (GOA)
- Regularized outer approximation (ROA)
- LP/NLP based branch-and-bound (LP/NLP)
- Global LP/NLP based branch-and-bound (GLP/NLP)
- Regularized LP/NLP based branch-and-bound (RLP/NLP)
- Feasibility pump (FP)

ZedongPeng marked this conversation as resolved.
Show resolved Hide resolved
This solver implementation has been developed by David Bernal <https://github.com/bernalde>
and Zedong Peng <https://github.com/ZedongPeng> as part of research efforts at the Grossmann
Research Group (http://egon.cheme.cmu.edu/) at the Department of Chemical Engineering at
Carnegie Mellon University.
"""

CONFIG = _get_MindtPy_GOA_config()
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/mindtpy/mip_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def set_up_mip_solver(solve_data, config, regularization_problem):
The customized MIP solver.
"""
# Deactivate extraneous IMPORT/EXPORT suffixes
if config.nlp_solver == 'ipopt':
if config.nlp_solver in {'ipopt', 'cyipopt'}:
getattr(solve_data.mip, 'ipopt_zL_out', _DoNothing()).deactivate()
getattr(solve_data.mip, 'ipopt_zU_out', _DoNothing()).deactivate()
if regularization_problem:
Expand Down
6 changes: 6 additions & 0 deletions pyomo/contrib/mindtpy/nlp_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ def handle_subproblem_optimal(fixed_nlp, solve_data, config, cb_opt=None):
for c in fixed_nlp.tmp_duals:
if fixed_nlp.dual.get(c, None) is None:
fixed_nlp.dual[c] = fixed_nlp.tmp_duals[c]
elif (
config.nlp_solver == 'cyipopt'
and solve_data.objective_sense == minimize
):
# TODO: recover the opposite dual when cyipopt issue #2831 is solved.
fixed_nlp.dual[c] = -fixed_nlp.dual[c]
ZedongPeng marked this conversation as resolved.
Show resolved Hide resolved
dual_values = list(
fixed_nlp.dual[c] for c in fixed_nlp.MindtPy_utils.constraint_list
)
Expand Down
10 changes: 1 addition & 9 deletions pyomo/contrib/mindtpy/outer_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,12 @@ class MindtPy_OA_Solver(_MindtPyAlgorithm):
The MindtPy (Mixed-Integer Nonlinear Decomposition Toolbox in Pyomo) solver
applies a variety of decomposition-based approaches to solve Mixed-Integer
Nonlinear Programming (MINLP) problems.
These approaches include:
This class includes:

- Outer approximation (OA)
- Global outer approximation (GOA)
- Regularized outer approximation (ROA)
- LP/NLP based branch-and-bound (LP/NLP)
- Global LP/NLP based branch-and-bound (GLP/NLP)
- Regularized LP/NLP based branch-and-bound (RLP/NLP)
- Feasibility pump (FP)

ZedongPeng marked this conversation as resolved.
Show resolved Hide resolved
This solver implementation has been developed by David Bernal <https://github.com/bernalde>
and Zedong Peng <https://github.com/ZedongPeng> as part of research efforts at the Grossmann
Research Group (http://egon.cheme.cmu.edu/) at the Department of Chemical Engineering at
Carnegie Mellon University.
"""

CONFIG = _get_MindtPy_OA_config()
Expand Down
6 changes: 6 additions & 0 deletions pyomo/contrib/mindtpy/single_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ def handle_lazy_subproblem_optimal(self, fixed_nlp, solve_data, config, opt):
for c in fixed_nlp.tmp_duals:
if fixed_nlp.dual.get(c, None) is None:
fixed_nlp.dual[c] = fixed_nlp.tmp_duals[c]
elif (
config.nlp_solver == 'cyipopt'
and solve_data.objective_sense == minimize
):
# TODO: recover the opposite dual when cyipopt issue #2831 is solved.
fixed_nlp.dual[c] = -fixed_nlp.dual[c]
ZedongPeng marked this conversation as resolved.
Show resolved Hide resolved
dual_values = list(
fixed_nlp.dual[c] for c in fixed_nlp.MindtPy_utils.constraint_list
)
Expand Down
3 changes: 3 additions & 0 deletions pyomo/contrib/mindtpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ def set_solver_options(opt, timing, config, solver_type, regularization=False):
elif solver_name in {'ipopt', 'appsi_ipopt'}:
opt.options['max_cpu_time'] = remaining
ZedongPeng marked this conversation as resolved.
Show resolved Hide resolved
opt.options['constr_viol_tol'] = config.zero_tolerance
elif solver_name == 'cyipopt':
opt.config.options['max_cpu_time'] = float(remaining)
opt.config.options['constr_viol_tol'] = config.zero_tolerance
elif solver_name == 'gams':
if solver_type == 'mip':
opt.options['add_options'] = [
Expand Down