11Future Solver Interface Changes
22===============================
33
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 ``.
819
920.. currentmodule :: pyomo.contrib.solver
1021
1122
1223New Interface Usage
1324-------------------
1425
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).
1933
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
2240 :header-rows: 1
2341
2442 * - 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
2946 - ``ipopt ``
47+ - ``ipopt_v2 ``
3048 * - Gurobi
31- - ``gurobi_v2 ``
3249 - ``gurobi ``
50+ - ``gurobi_v2 ``
3351
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.
3659
3760.. testcode ::
3861 :skipif: not ipopt_available
@@ -61,16 +84,15 @@ Backwards Compatible Mode
6184 ...
6285 3 Declarations: x y obj
6386
64- Future Capability Mode
65- ^^^^^^^^^^^^^^^^^^^^^^
87+ Using the new interfaces directly
88+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6689
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:
6991
7092.. testcode ::
7193 :skipif: not ipopt_available
7294
73- # Direct import
95+ # Direct import
7496 import pyomo.environ as pyo
7597 from pyomo.contrib.solver.util import assert_optimal_termination
7698 from pyomo.contrib.solver.ipopt import Ipopt
@@ -87,7 +109,7 @@ or changed ``SolverFactory`` version.
87109 opt = Ipopt()
88110 status = opt.solve(model)
89111 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
91113 status.display()
92114 model.pprint()
93115
@@ -99,12 +121,54 @@ or changed ``SolverFactory`` version.
99121 ...
100122 3 Declarations: x y obj
101123
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 ``:
103128
104129.. testcode ::
105130 :skipif: not ipopt_available
106131
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
108172 import pyomo.environ as pyo
109173 from pyomo.contrib.solver.util import assert_optimal_termination
110174 from pyomo.__future__ import solver_factory_v3
@@ -120,7 +184,7 @@ Changing the ``SolverFactory`` version:
120184
121185 status = pyo.SolverFactory('ipopt').solve(model)
122186 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
124188 status.display()
125189 model.pprint()
126190
@@ -141,16 +205,15 @@ Changing the ``SolverFactory`` version:
141205Linear Presolve and Scaling
142206^^^^^^^^^^^^^^^^^^^^^^^^^^^
143207
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:
147213
148214.. autoclass :: pyomo.contrib.solver.ipopt.Ipopt
149215 :members: solve
150216
151- The ``writer_config `` configuration option can be used to manipulate presolve
152- and scaling options:
153-
154217.. testcode ::
155218
156219 from pyomo.contrib.solver.ipopt import Ipopt
0 commit comments