-
Notifications
You must be signed in to change notification settings - Fork 579
Initialization Module #3912
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
base: main
Are you sure you want to change the base?
Initialization Module #3912
Changes from 83 commits
00b3c27
d2aae9f
b2fa0a5
fd06964
d29a2cf
8914a63
5ebfdd4
488a539
e993623
aa450e1
4945388
ab9a46c
6f30fac
043f8c8
83c5e72
8bf25d1
4e3d913
c8a0730
e019bff
9568bb0
387a646
24dbd64
2616502
54d354e
056cc99
d70e677
823641d
6a29fba
5eb638f
3ddc25d
0b02132
f96a421
b185c8b
25d50e6
2355870
e40f487
42d7fff
fe98b7c
5d9660b
c08a92c
ec9f9b9
e52e123
5b4fe02
135b152
fc60afe
48bae52
eb0e0ea
d0dab9a
89ccca8
4c32139
0d1175f
2030f4e
5d81def
8f2a0da
0534849
f5fe237
061e46f
cba1223
c85a864
a33c665
a800114
2d4594a
784804d
cc6b78f
9aaa84c
f56e4b6
d3e79ac
021f968
f4f71aa
f1e6467
bd4f5ae
fa557b3
75436ea
e80b737
9ba42c6
c7cb2f9
ba1a999
6d8d072
4a895b2
d90d2be
4cc1659
ac60807
8668d8e
7a182bf
53c0073
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 |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| .. _analysis_nlp_initialization: | ||
|
|
||
| NLP Initialization | ||
| ****************** | ||
|
|
||
| .. warning:: | ||
|
|
||
| This package lives in :mod:`pyomo.devel`. APIs, options, and behavior may | ||
| change without notice. | ||
|
|
||
| The initialization module within ``pyomo.devel.initialization`` is intended to | ||
| provide methods to help initialize nonconvex nonlinear programs (NLPs). The | ||
| goal is to increase the chance of finding a local minimizer (i.e., decrease the | ||
| chance of getting stuck a point that locally minimizes infeasibility). If | ||
| you are already able to solve your problem with a local NLP solver, these | ||
| tools will not help you. Example usage is shown below. | ||
|
|
||
| .. literalinclude:: /../../pyomo/devel/initialization/examples/init_polynomial_ex.py | ||
| :start-after: # === Required imports === | ||
|
|
||
| The :func:`initialize_nlp <pyomo.devel.initialization.initialize.initialize_nlp>` | ||
| function uses the specified method to try to find a good starting point for the | ||
| NLP solver and then attempts to solve the problem with the given NLP solver. | ||
|
|
||
| .. note:: | ||
|
|
||
| Currently, this module only works with solvers from :mod:`pyomo.contrib.solver`. | ||
|
|
||
|
|
||
| Initialization Methods | ||
| ====================== | ||
|
|
||
| The initialization method is selected using the | ||
| :class:`InitializationMethod <pyomo.devel.initialization.initialize.InitializationMethod>` enum. | ||
|
|
||
| .. note:: | ||
|
|
||
| Not all of the methods described below require all nonlinear variables to be | ||
| bounded. However, all of the methods will perform better if all nonlinear | ||
| variables are bounded (the tighter the bounds, the better). | ||
|
|
||
|
|
||
| Method ``global_opt`` | ||
| --------------------- | ||
|
|
||
| This method uses an MINLP solver to try to find a feasible solution. We | ||
| adjust the solver parameters so that the solver will stop as soon as any | ||
| feasible solution is found. We then initialize the NLP solver at that | ||
| feasible solution. Many MINLP solvers will default to a very large | ||
| time limit, so it can be useful to specify a time limit before | ||
| calling :func:`initialize_nlp <pyomo.devel.initialization.initialize.initialize_nlp>`: | ||
|
|
||
| .. testcode:: | ||
| :skipif: not pyscipopt_available | ||
|
|
||
| import pyomo.environ as pyo | ||
| from pyomo.contrib.solver.common.factory import SolverFactory | ||
|
|
||
| global_solver = SolverFactory('scip_direct') | ||
| global_solver.config.time_limit = 600 # 10 minutes | ||
| # now call initialize_nlp | ||
|
|
||
| This method currently works with the following solver interfaces for MINLP solvers: | ||
|
|
||
| * SCIP (:class:`direct <pyomo.contrib.solver.solvers.scip.scip_direct.ScipDirect>` and | ||
| :class:`persistent <pyomo.contrib.solver.solvers.scip.scip_direct.ScipPersistent>`) | ||
| * :class:`Gurobi MINLP <pyomo.contrib.solver.solvers.gurobi.gurobi_direct_minlp.GurobiDirectMINLP>` | ||
|
|
||
| Advantages | ||
| ^^^^^^^^^^ | ||
|
|
||
| * Currently, this is the method that is most likely to succeed in finding a | ||
| feasible solution. | ||
| * Does not strictly require variable bounds | ||
|
|
||
| Disadvantages | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| * This method will only work if the model is completely algebraic. It will not | ||
| work with external functions. | ||
|
|
||
|
|
||
| Method ``pwl_approximation`` | ||
| ---------------------------- | ||
|
|
||
| This method builds a piecewise linear (PWL) approximation of the model, solves | ||
| it, and initializes the NLP solver at the solution. If the NLP solver does not | ||
| converge, then the PWL approximation will be refined by adding additional | ||
| "segments". This is repeated until either a feasible solution is found or | ||
| the iteration limit is reached. | ||
|
|
||
| This method does not currently work as well as ``global_opt``, but it does | ||
| have a great deal of potential. We expect future versions of this method | ||
| to perform significantly better. | ||
|
|
||
| Advantages | ||
| ^^^^^^^^^^ | ||
|
|
||
| * Does not require an MINLP solver | ||
| * Future versions will work with external functions | ||
|
|
||
| Disadvantages | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| * Current implementation can be slow | ||
| * Requires all nonlinear variables to be bounded | ||
|
|
||
|
|
||
| Method ``lp_approximation`` | ||
| --------------------------- | ||
|
|
||
| This method is similar to the PWL approximation method, but it builds | ||
| an LP approximation instead and does not do any refinement. Another | ||
| distinction is that the LP approximation uses a linear least-squares | ||
| fit, so the approximation may not equal the original function at the | ||
| variable bounds. This also means that variable bounds are not strictly | ||
| necessary, though they do help improve the approximation. | ||
|
|
||
| Advantages | ||
| ^^^^^^^^^^ | ||
|
|
||
| * Fast | ||
| * Future versions will work with external functions | ||
| * Does not strictly require variable bounds | ||
| * Does not require an MINLP or even an MILP solver | ||
|
|
||
| Disadvantages | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| * This method only attempts to initialize the problem once. If it does | ||
| not succeed, it is done. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ Explanations | |
| `Design of Experiments` | ||
| `MPC` | ||
| `AOS` | ||
| `NLP Initialization` | ||
|
Member
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 don't think this change was necessary. I'm pretty sure this is just an old comment block we were using to track the documentation reorganization effort. |
||
| `Modeling Utilities` | ||
| `Latex Printer` | ||
| `FME` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The purpose of this module is to provide methods for initializing nonlinear programming models. | ||
|
Member
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. Is this readme necessary? Should it just have a pointer to the documentation? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # ____________________________________________________________________________________ | ||
| # | ||
| # Pyomo: Python Optimization Modeling Objects | ||
| # Copyright (c) 2008-2026 National Technology and Engineering Solutions of Sandia, LLC | ||
| # Under the terms of Contract DE-NA0003525 with National Technology and Engineering | ||
| # Solutions of Sandia, LLC, the U.S. Government retains certain rights in this | ||
| # software. This software is distributed under the 3-clause BSD License. | ||
| # ____________________________________________________________________________________ | ||
|
|
||
| from pyomo.devel.initialization.initialize import initialize_nlp, InitializationMethod |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # ____________________________________________________________________________________ | ||
| # | ||
| # Pyomo: Python Optimization Modeling Objects | ||
| # Copyright (c) 2008-2026 National Technology and Engineering Solutions of Sandia, LLC | ||
| # Under the terms of Contract DE-NA0003525 with National Technology and Engineering | ||
| # Solutions of Sandia, LLC, the U.S. Government retains certain rights in this | ||
| # software. This software is distributed under the 3-clause BSD License. | ||
| # ____________________________________________________________________________________ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # ____________________________________________________________________________________ | ||
| # | ||
| # Pyomo: Python Optimization Modeling Objects | ||
| # Copyright (c) 2008-2026 National Technology and Engineering Solutions of Sandia, LLC | ||
| # Under the terms of Contract DE-NA0003525 with National Technology and Engineering | ||
| # Solutions of Sandia, LLC, the U.S. Government retains certain rights in this | ||
| # software. This software is distributed under the 3-clause BSD License. | ||
| # ____________________________________________________________________________________ | ||
|
|
||
| from pyomo.core.base.block import BlockData | ||
| from pyomo.contrib.fbbt.fbbt import fbbt | ||
| from pyomo.devel.initialization.utils import get_vars | ||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def bound_all_nonlinear_variables(m: BlockData, default_bound: float = 1.0e8): | ||
| """ | ||
| Attempt to obtain valid bounds on all nonlinear variables based on the | ||
| constraints in the model, m. If variable bounds cannot be obtained, | ||
| we use default_bound. | ||
| """ | ||
| fbbt(m) | ||
|
Member
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. Is it worth only running FBBT on constraints that actually involve unbounded variables (instead of attempting to tighten all variables in the model)? |
||
| for v in get_vars(m): | ||
| if v.lb is None or v.lb < -default_bound: | ||
| logger.debug( | ||
| f'Could not obtain a lower bound for {str(v)} better than {-default_bound}; setting the lower bound to {-default_bound}' | ||
| ) | ||
| v.setlb(-default_bound) | ||
| if v.ub is None or v.ub > default_bound: | ||
| logger.debug( | ||
| f'Could not obtain an upper bound for {str(v)} better than {default_bound}; setting the upper bound to {default_bound}' | ||
| ) | ||
| v.setub(default_bound) | ||
| fbbt(m) | ||
|
michaelbynum marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # ____________________________________________________________________________________ | ||
| # | ||
| # Pyomo: Python Optimization Modeling Objects | ||
| # Copyright (c) 2008-2026 National Technology and Engineering Solutions of Sandia, LLC | ||
| # Under the terms of Contract DE-NA0003525 with National Technology and Engineering | ||
| # Solutions of Sandia, LLC, the U.S. Government retains certain rights in this | ||
| # software. This software is distributed under the 3-clause BSD License. | ||
| # ____________________________________________________________________________________ |
Uh oh!
There was an error while loading. Please reload this page.