Skip to content

Commit 9fbc7be

Browse files
committed
Residual imports
1 parent 6ca4b45 commit 9fbc7be

File tree

11 files changed

+50
-50
lines changed

11 files changed

+50
-50
lines changed

doc/OnlineDocs/contribution_guide.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ provides an example of how this can be done, including a directory
413413
for plugins and package tests. For example, this package can be
414414
imported as a subpackage of ``pyomo.contrib``::
415415

416-
from pyomo.environ import *
416+
import pyomo.environ as pyo
417417
from pyomo.contrib.example import a
418418

419419
# Print the value of 'a' defined by this package

doc/OnlineDocs/explanation/analysis/sensitivity_toolbox.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Here :math:`x_1`, :math:`x_2`, and :math:`x_3` are the decision variables while
3131
.. doctest:: python
3232

3333
# Import Pyomo and the sensitivity toolbox
34-
>>> from pyomo.environ import *
34+
>>> import pyomo.environ as pyo
3535
>>> from pyomo.contrib.sensitivity_toolbox.sens import sensitivity_calculation
3636

3737
# Create a concrete model

doc/OnlineDocs/explanation/modeling/dae.rst

+9-9
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ concrete Pyomo model:
6969
.. doctest::
7070

7171
Required imports
72-
>>> from pyomo.environ import *
73-
>>> from pyomo.dae import *
72+
>>> import pyomo.environ as pyo
73+
>>> from pyomo.dae import ContinuousSet
7474

7575
>>> model = pyo.ConcreteModel()
7676

@@ -96,10 +96,10 @@ abstract Pyomo model using the example data file.
9696
.. doctest::
9797

9898
Required imports
99-
>>> from pyomo.environ import *
100-
>>> from pyomo.dae import *
99+
>>> import pyomo.environ as pyo
100+
>>> from pyomo.dae import ContinuousSet
101101

102-
>>> model = AbstractModel()
102+
>>> model = pyo.AbstractModel()
103103

104104
The ContinuousSet below will be initialized using the points
105105
in the data file when a model instance is created.
@@ -151,7 +151,7 @@ argument. Any keyword argument that is valid for a Pyomo
151151
.. doctest::
152152

153153
Required imports
154-
>>> from pyomo.environ import *
154+
>>> import pyomo.environ as pyo
155155
>>> from pyomo.dae import ContinuousSet, DerivativeVar
156156

157157
>>> model = pyo.ConcreteModel()
@@ -198,7 +198,7 @@ an ordinary or partial differential equation.
198198
.. doctest::
199199

200200
Required imports
201-
>>> from pyomo.environ import *
201+
>>> fimport pyomo.environ as pyo
202202
>>> from pyomo.dae import ContinuousSet, DerivativeVar, Integral
203203

204204
>>> model = pyo.ConcreteModel()
@@ -803,7 +803,7 @@ We begin by formulating the model using pyomo.DAE
803803
>>> m.theta[0].fix(3.14 - 0.1)
804804

805805
>>> def _diffeq1(m, t):
806-
... return m.domegadt[t] == -m.b * m.omega[t] - m.c * sin(m.theta[t])
806+
... return m.domegadt[t] == -m.b * m.omega[t] - m.c * pyo.sin(m.theta[t])
807807
>>> m.diffeq1 = pyo.Constraint(m.t, rule=_diffeq1)
808808

809809
>>> def _diffeq2(m, t):
@@ -886,7 +886,7 @@ example.
886886

887887
>>> def _diffeq1(m, t):
888888
... return m.domegadt[t] == -m.b[t] * m.omega[t] - \
889-
... m.c[t] * sin(m.theta[t])
889+
... m.c[t] * pyo.sin(m.theta[t])
890890
>>> m.diffeq1 = pyo.Constraint(m.t, rule=_diffeq1)
891891

892892
>>> def _diffeq2(m, t):

doc/OnlineDocs/explanation/modeling/network.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ concrete Pyomo model:
4545

4646
.. doctest::
4747

48-
>>> from pyomo.environ import *
49-
>>> from pyomo.network import *
48+
>>> import pyomo.environ as pyo
49+
>>> from pyomo.network import Port
5050
>>> m = pyo.ConcreteModel()
5151
>>> m.x = pyo.Var()
5252
>>> m.y = pyo.Var(['a', 'b']) # can be indexed
@@ -79,8 +79,8 @@ concrete Pyomo model:
7979

8080
.. doctest::
8181

82-
>>> from pyomo.environ import *
83-
>>> from pyomo.network import *
82+
>>> import pyomo.environ as pyo
83+
>>> from pyomo.network import Port, Arc
8484
>>> m = pyo.ConcreteModel()
8585
>>> m.x = pyo.Var()
8686
>>> m.y = pyo.Var(['a', 'b'])
@@ -139,8 +139,8 @@ the arcs on a model:
139139

140140
.. doctest::
141141

142-
>>> from pyomo.environ import *
143-
>>> from pyomo.network import *
142+
>>> import pyomo.environ as pyo
143+
>>> from pyomo.network import Port, Arc
144144
>>> m = pyo.ConcreteModel()
145145
>>> m.x = pyo.Var()
146146
>>> m.y = pyo.Var(['a', 'b'])
@@ -301,8 +301,8 @@ class:
301301
.. doctest::
302302
:skipif: not __import__("pyomo.network").network.decomposition.imports_available
303303

304-
>>> from pyomo.environ import *
305-
>>> from pyomo.network import *
304+
>>> import pyomo.environ as pyo
305+
>>> from pyomo.network import Port, Arc, SequentialDecomposition
306306
>>> m = pyo.ConcreteModel()
307307
>>> m.unit1 = pyo.Block()
308308
>>> m.unit1.x = pyo.Var()

doc/OnlineDocs/explanation/modeling_utils/preprocessing.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ transformation on a concrete Pyomo model:
4040

4141
.. doctest::
4242

43-
>>> from pyomo.environ import *
43+
>>> import pyomo.environ as pyo
4444
>>> m = pyo.ConcreteModel()
4545
>>> m.v1 = pyo.Var(initialize=1, bounds=(1, 8))
4646
>>> m.v2 = pyo.Var(initialize=2, bounds=(0, 3))
@@ -67,7 +67,7 @@ Explicit pyo.Constraints to Variable Bounds
6767

6868
.. doctest::
6969

70-
>>> from pyomo.environ import *
70+
>>> import pyomo.environ as pyo
7171
>>> m = pyo.ConcreteModel()
7272
>>> m.v1 = pyo.Var(initialize=1)
7373
>>> m.v2 = pyo.Var(initialize=2)

doc/OnlineDocs/explanation/solvers/gdpopt.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ An example that includes the modeling approach may be found below.
6363
:skipif: not glpk_available
6464

6565
Required imports
66-
>>> from pyomo.environ import *
67-
>>> from pyomo.gdp import *
66+
>>> import pyomo.environ as pyo
67+
>>> from pyomo.gdp import Disjunct, Disjunction
6868

6969
Create a simple model
7070
>>> model = pyo.ConcreteModel(name='LOA example')
@@ -80,7 +80,7 @@ An example that includes the modeling approach may be found below.
8080
>>> model.fix_y.c = pyo.Constraint(expr=model.y == 0)
8181

8282
>>> model.d = Disjunction(expr=[model.fix_x, model.fix_y])
83-
>>> model.objective = pyo.Objective(expr=model.x + 0.1*model.y, sense=minimize)
83+
>>> model.objective = pyo.Objective(expr=model.x + 0.1*model.y, sense=pyo.minimize)
8484

8585
Solve the model using GDPopt
8686
>>> results = pyo.SolverFactory('gdpopt.loa').solve(
@@ -158,14 +158,14 @@ To use the GDPopt-LBB solver, define your Pyomo GDP model as usual:
158158
:skipif: not baron_available
159159

160160
Required imports
161-
>>> from pyomo.environ import *
161+
>>> import pyomo.environ as pyo
162162
>>> from pyomo.gdp import Disjunct, Disjunction
163163

164164
Create a simple model
165165
>>> m = pyo.ConcreteModel()
166166
>>> m.x1 = pyo.Var(bounds = (0,8))
167167
>>> m.x2 = pyo.Var(bounds = (0,8))
168-
>>> m.obj = pyo.Objective(expr=m.x1 + m.x2, sense=minimize)
168+
>>> m.obj = pyo.Objective(expr=m.x1 + m.x2, sense=pyo.minimize)
169169
>>> m.y1 = Disjunct()
170170
>>> m.y2 = Disjunct()
171171
>>> m.y1.c1 = pyo.Constraint(expr=m.x1 >= 2)

doc/OnlineDocs/explanation/solvers/mindtpy.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ An example which includes the modeling approach may be found below.
7272
.. doctest::
7373

7474
Required imports
75-
>>> from pyomo.environ import *
75+
>>> import pyomo.environ as pyo
7676

7777
Create a simple model
7878
>>> model = pyo.ConcreteModel()
7979

8080
>>> model.x = pyo.Var(bounds=(1.0,10.0),initialize=5.0)
81-
>>> model.y = pyo.Var(within=Binary)
81+
>>> model.y = pyo.Var(within=pyo.Binary)
8282

8383
>>> model.c1 = pyo.Constraint(expr=(model.x-4.0)**2 - model.x <= 50.0*(1-model.y))
84-
>>> model.c2 = pyo.Constraint(expr=model.x*log(model.x)+5.0 <= 50.0*(model.y))
84+
>>> model.c2 = pyo.Constraint(expr=model.x*pyo.log(model.x)+5.0 <= 50.0*(model.y))
8585

86-
>>> model.objective = pyo.Objective(expr=model.x, sense=minimize)
86+
>>> model.objective = pyo.Objective(expr=model.x, sense=pyo.minimize)
8787

8888
Solve the model using MindtPy
8989
>>> pyo.SolverFactory('mindtpy').solve(model, mip_solver='glpk', nlp_solver='ipopt') # doctest: +SKIP
@@ -140,7 +140,7 @@ A usage example for LP/NLP based branch-and-bound algorithm is as follows:
140140

141141
.. code::
142142
143-
>>> pyo.pyo.SolverFactory('mindtpy').solve(model,
143+
>>> pyo.SolverFactory('mindtpy').solve(model,
144144
... strategy='OA',
145145
... mip_solver='cplex_persistent', # or 'gurobi_persistent'
146146
... nlp_solver='ipopt',
@@ -160,7 +160,7 @@ A usage example for regularized OA is as follows:
160160

161161
.. code::
162162
163-
>>> pyo.pyo.SolverFactory('mindtpy').solve(model,
163+
>>> pyo.SolverFactory('mindtpy').solve(model,
164164
... strategy='OA',
165165
... mip_solver='cplex',
166166
... nlp_solver='ipopt',
@@ -181,7 +181,7 @@ A usage example for OA with solution pool is as follows:
181181

182182
.. code::
183183
184-
>>> pyo.pyo.SolverFactory('mindtpy').solve(model,
184+
>>> pyo.SolverFactory('mindtpy').solve(model,
185185
... strategy='OA',
186186
... mip_solver='cplex_persistent',
187187
... nlp_solver='ipopt',
@@ -202,7 +202,7 @@ A usage example for Feasibility Pump as the initialization strategy is as follow
202202

203203
.. code::
204204
205-
>>> pyo.pyo.SolverFactory('mindtpy').solve(model,
205+
>>> pyo.SolverFactory('mindtpy').solve(model,
206206
... strategy='OA',
207207
... init_strategy='FP',
208208
... mip_solver='cplex',
@@ -215,7 +215,7 @@ A usage example for Feasibility Pump as the decomposition strategy is as follows
215215

216216
.. code::
217217
218-
>>> pyo.pyo.SolverFactory('mindtpy').solve(model,
218+
>>> pyo.SolverFactory('mindtpy').solve(model,
219219
... strategy='FP',
220220
... mip_solver='cplex',
221221
... nlp_solver='ipopt',
@@ -282,7 +282,7 @@ A usage example for GOA is as follows:
282282

283283
.. code::
284284
285-
>>> pyo.pyo.SolverFactory('mindtpy').solve(model,
285+
>>> pyo.SolverFactory('mindtpy').solve(model,
286286
... strategy='GOA',
287287
... mip_solver='cplex',
288288
... nlp_solver='baron')

doc/OnlineDocs/explanation/solvers/multistart.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To use the multistart solver, define your Pyomo model as usual:
1414
.. doctest::
1515

1616
Required import
17-
>>> from pyomo.environ import *
17+
>>> import pyomo.environ as pyo
1818

1919
Create a simple model
2020
>>> m = pyo.ConcreteModel()

doc/OnlineDocs/explanation/solvers/z3_interface.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To use the sat solver define your pyomo model as usual:
1919
.. doctest::
2020

2121
Required import
22-
>>> from pyomo.environ import *
22+
>>> import pyomo.environ as pyo
2323
>>> from pyomo.contrib.satsolver.satsolver import SMTSatSolver
2424

2525
Create a simple model

doc/OnlineDocs/howto/abstract_models/data/raw_dicts.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ components, the required data dictionary maps the implicit index
1414

1515
.. doctest::
1616

17-
>>> from pyomo.environ import *
18-
>>> m = AbstractModel()
19-
>>> m.I = Set()
20-
>>> m.p = Param()
21-
>>> m.q = Param(m.I)
22-
>>> m.r = Param(m.I, m.I, default=0)
17+
>>> import pyomo.environ as pyo
18+
>>> m = pyo.AbstractModel()
19+
>>> m.I = pyo.Set()
20+
>>> m.p = pyo.Param()
21+
>>> m.q = pyo.Param(m.I)
22+
>>> m.r = pyo.Param(m.I, m.I, default=0)
2323
>>> data = {None: {
2424
... 'I': {None: [1,2,3]},
2525
... 'p': {None: 100},

doc/OnlineDocs/howto/interrogating.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ can be accessed using its ``value`` member. For example, suppose the
2727
model contains a variable named ``quant`` that is a singleton (has no
2828
indexes) and suppose further that the name of the instance object is
2929
``instance``. Then the value of this variable can be accessed using
30-
``pyo.value(instance.quant)``. Variables with indexes can be referenced
30+
``pyo.pyo.value(instance.quant)``. Variables with indexes can be referenced
3131
by supplying the index.
3232

3333
Consider the following very simple example, which is similar to the
@@ -54,13 +54,13 @@ the following code snippet displays all variables and their values:
5454
>>> for v in instance.component_objects(pyo.Var, active=True):
5555
... print("Variable",v) # doctest: +SKIP
5656
... for index in v:
57-
... print (" ",index, pyo.value(v[index])) # doctest: +SKIP
57+
... print (" ",index, pyo.pyo.value(v[index])) # doctest: +SKIP
5858

5959

6060
Alternatively,
6161

6262
>>> for v in instance.component_data_objects(pyo.Var, active=True):
63-
... print(v, pyo.value(v)) # doctest: +SKIP
63+
... print(v, pyo.pyo.value(v)) # doctest: +SKIP
6464

6565
This code could be improved by checking to see if the variable is not
6666
indexed (i.e., the only index value is ``None``), then the code could
@@ -96,7 +96,7 @@ of every Parameter in a model:
9696
... nametoprint = str(str(parmobject.name))
9797
... print ("Parameter ", nametoprint) # doctest: +SKIP
9898
... for index in parmobject:
99-
... vtoprint = pyo.value(parmobject[index])
99+
... vtoprint = pyo.pyo.value(parmobject[index])
100100
... print (" ",index, vtoprint) # doctest: +SKIP
101101

102102

@@ -136,7 +136,7 @@ an instance, duals can be accessed in the following fashion.
136136
:language: python
137137

138138
The following snippet will only work, of course, if there is a
139-
constraint with the name ``AxbConstraint`` that has and index, which is
139+
constraint with the name ``Axbpyo.Constraint`` that has and index, which is
140140
the string ``Film``.
141141

142142
.. literalinclude:: /src/scripting/driveabs2_Access_one_dual.spy
@@ -145,7 +145,7 @@ the string ``Film``.
145145
Here is a complete example that relies on the file ``abstract2.py`` to
146146
provide the model and the file ``abstract2.dat`` to provide the
147147
data. Note that the model in ``abstract2.py`` does contain a constraint
148-
named ``AxbConstraint`` and ``abstract2.dat`` does specify an index for
148+
named ``Axbpyo.Constraint`` and ``abstract2.dat`` does specify an index for
149149
it named ``Film``.
150150

151151
.. literalinclude:: /src/scripting/driveabs2.spy

0 commit comments

Comments
 (0)