1
1
Future Solver Interface Changes
2
2
===============================
3
3
4
- Pyomo offers interfaces into multiple solvers, both commercial and open source.
5
- To support better capabilities for solver interfaces, the Pyomo team is actively
6
- redesigning the existing interfaces to make them more maintainable and intuitive
7
- for use. Redesigned interfaces can be found in ``pyomo.contrib.solver ``.
4
+ .. note ::
5
+
6
+ The new solver interfaces are still under active development. They
7
+ are included in the releases as development previews. Please be
8
+ aware that APIs and functionality may change with no notice.
9
+
10
+ We welcome any feedback and ideas as we develop this capability.
11
+ Please post feedback on
12
+ `Issue 1030 <https://github.com/Pyomo/pyomo/issues/1030 >`_.
13
+
14
+ Pyomo offers interfaces into multiple solvers, both commercial and open
15
+ source. To support better capabilities for solver interfaces, the Pyomo
16
+ team is actively redesigning the existing interfaces to make them more
17
+ maintainable and intuitive for use. A preview of the redesigned
18
+ interfaces can be found in ``pyomo.contrib.solver ``.
8
19
9
20
.. currentmodule :: pyomo.contrib.solver
10
21
11
22
12
23
New Interface Usage
13
24
-------------------
14
25
15
- The new interfaces have two modes: backwards compatible and future capability.
16
- The future capability mode can be accessed directly or by switching the default
17
- ``SolverFactory `` version (see :doc: `future `). Currently, the new versions
18
- available are:
26
+ The new interfaces are not completely backwards compatible with the
27
+ existing Pyomo solver interfaces. However, to aid in testing and
28
+ evaluation, we are distributing versions of the new solver interfaces
29
+ that are compatible with the existing ("legacy") solver interface.
30
+ These "legacy" interfaces are registered with the current
31
+ ``SolverFactory `` using slightly different names (to avoid conflicts
32
+ with existing interfaces).
19
33
20
- .. list-table :: Available Redesigned Solvers
21
- :widths: 25 25 25
34
+ .. |br | raw :: html
35
+
36
+ <br />
37
+
38
+ .. list-table :: Available Redesigned Solvers and Names Registered
39
+ in the SolverFactories
22
40
:header-rows: 1
23
41
24
42
* - Solver
25
- - ``SolverFactory `` (v1) Name
26
- - ``SolverFactory `` (v3) Name
27
- * - ipopt
28
- - ``ipopt_v2 ``
43
+ - Name registered in the |br | ``pyomo.contrib.solver.factory.SolverFactory ``
44
+ - Name registered in the |br | ``pyomo.opt.base.solvers.LegacySolverFactory ``
45
+ * - Ipopt
29
46
- ``ipopt ``
47
+ - ``ipopt_v2 ``
30
48
* - Gurobi
31
- - ``gurobi_v2 ``
32
49
- ``gurobi ``
50
+ - ``gurobi_v2 ``
33
51
34
- Backwards Compatible Mode
35
- ^^^^^^^^^^^^^^^^^^^^^^^^^
52
+ Using the new interfaces through the legacy interface
53
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54
+
55
+ Here we use the new interface as exposed through the existing (legacy)
56
+ solver factory and solver interface wrapper. This provides an API that
57
+ is compatible with the existing (legacy) Pyomo solver interface and can
58
+ be used with other Pyomo tools / capabilities.
36
59
37
60
.. testcode ::
38
61
:skipif: not ipopt_available
@@ -61,16 +84,15 @@ Backwards Compatible Mode
61
84
...
62
85
3 Declarations: x y obj
63
86
64
- Future Capability Mode
65
- ^^^^^^^^^^^^^^^^^^^^^^
87
+ Using the new interfaces directly
88
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
89
67
- There are multiple ways to utilize the future capability mode: direct import
68
- or changed ``SolverFactory `` version.
90
+ Here we use the new interface by importing it directly:
69
91
70
92
.. testcode ::
71
93
:skipif: not ipopt_available
72
94
73
- # Direct import
95
+ # Direct import
74
96
import pyomo.environ as pyo
75
97
from pyomo.contrib.solver.util import assert_optimal_termination
76
98
from pyomo.contrib.solver.ipopt import Ipopt
@@ -87,7 +109,7 @@ or changed ``SolverFactory`` version.
87
109
opt = Ipopt()
88
110
status = opt.solve(model)
89
111
assert_optimal_termination(status)
90
- # Displays important results information; only available in future capability mode
112
+ # Displays important results information; only available through the new interfaces
91
113
status.display()
92
114
model.pprint()
93
115
@@ -99,12 +121,54 @@ or changed ``SolverFactory`` version.
99
121
...
100
122
3 Declarations: x y obj
101
123
102
- Changing the ``SolverFactory `` version:
124
+ Using the new interfaces through the "new" SolverFactory
125
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126
+
127
+ Here we use the new interface by retrieving it from the new ``SolverFactory ``:
103
128
104
129
.. testcode ::
105
130
:skipif: not ipopt_available
106
131
107
- # Change SolverFactory version
132
+ # Import through new SolverFactory
133
+ import pyomo.environ as pyo
134
+ from pyomo.contrib.solver.util import assert_optimal_termination
135
+ from pyomo.contrib.solver.factory import SolverFactory
136
+
137
+ model = pyo.ConcreteModel()
138
+ model.x = pyo.Var(initialize=1.5)
139
+ model.y = pyo.Var(initialize=1.5)
140
+
141
+ def rosenbrock(model):
142
+ return (1.0 - model.x) ** 2 + 100.0 * (model.y - model.x**2) ** 2
143
+
144
+ model.obj = pyo.Objective(rule=rosenbrock, sense=pyo.minimize)
145
+
146
+ opt = SolverFactory('ipopt')
147
+ status = opt.solve(model)
148
+ assert_optimal_termination(status)
149
+ # Displays important results information; only available through the new interfaces
150
+ status.display()
151
+ model.pprint()
152
+
153
+ .. testoutput ::
154
+ :skipif: not ipopt_available
155
+ :hide:
156
+
157
+ solution_loader: ...
158
+ ...
159
+ 3 Declarations: x y obj
160
+
161
+ Switching all of Pyomo to use the new interfaces
162
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163
+
164
+ We also provide a mechanism to get a "preview" of the future where we
165
+ replace the existing (legacy) SolverFactory and utilities with the new
166
+ (development) version (see :doc: `future `):
167
+
168
+ .. testcode ::
169
+ :skipif: not ipopt_available
170
+
171
+ # Change default SolverFactory version
108
172
import pyomo.environ as pyo
109
173
from pyomo.contrib.solver.util import assert_optimal_termination
110
174
from pyomo.__future__ import solver_factory_v3
@@ -120,7 +184,7 @@ Changing the ``SolverFactory`` version:
120
184
121
185
status = pyo.SolverFactory('ipopt').solve(model)
122
186
assert_optimal_termination(status)
123
- # Displays important results information; only available in future capability mode
187
+ # Displays important results information; only available through the new interfaces
124
188
status.display()
125
189
model.pprint()
126
190
@@ -141,16 +205,15 @@ Changing the ``SolverFactory`` version:
141
205
Linear Presolve and Scaling
142
206
^^^^^^^^^^^^^^^^^^^^^^^^^^^
143
207
144
- The new interface will allow for direct manipulation of linear presolve and scaling
145
- options for certain solvers. Currently, these options are only available for
146
- ``ipopt ``.
208
+ The new interface allows access to new capabilities in the various
209
+ problem writers, including the linear presolve and scaling options
210
+ recently incorporated into the redesigned NL writer. For example, you
211
+ can control the NL writer in the new ``ipopt `` interface through the
212
+ solver's ``writer_config `` configuration option:
147
213
148
214
.. autoclass :: pyomo.contrib.solver.ipopt.Ipopt
149
215
:members: solve
150
216
151
- The ``writer_config `` configuration option can be used to manipulate presolve
152
- and scaling options:
153
-
154
217
.. testcode ::
155
218
156
219
from pyomo.contrib.solver.ipopt import Ipopt
0 commit comments