Skip to content

Commit 166119a

Browse files
authored
Merge pull request #3543 from mrmundt/example-imports
PEP: Standardize Example Imports
2 parents cfc0850 + 50129d0 commit 166119a

File tree

242 files changed

+3678
-3491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+3678
-3491
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

+12-12
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ 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
38-
>>> m = ConcreteModel()
38+
>>> m = pyo.ConcreteModel()
3939

4040
# Define the variables with bounds and initial values
41-
>>> m.x1 = Var(initialize = 0.15, within=NonNegativeReals)
42-
>>> m.x2 = Var(initialize = 0.15, within=NonNegativeReals)
43-
>>> m.x3 = Var(initialize = 0.0, within=NonNegativeReals)
41+
>>> m.x1 = pyo.Var(initialize = 0.15, within=pyo.NonNegativeReals)
42+
>>> m.x2 = pyo.Var(initialize = 0.15, within=pyo.NonNegativeReals)
43+
>>> m.x3 = pyo.Var(initialize = 0.0, within=pyo.NonNegativeReals)
4444

4545
# Define the parameters
46-
>>> m.eta1 = Param(initialize=4.5,mutable=True)
47-
>>> m.eta2 = Param(initialize=1.0,mutable=True)
46+
>>> m.eta1 = pyo.Param(initialize=4.5,mutable=True)
47+
>>> m.eta2 = pyo.Param(initialize=1.0,mutable=True)
4848

4949
# Define the constraints and objective
50-
>>> m.const1 = Constraint(expr=6*m.x1+3*m.x2+2*m.x3-m.eta1 ==0)
51-
>>> m.const2 = Constraint(expr=m.eta2*m.x1+m.x2-m.x3-1 ==0)
52-
>>> m.cost = Objective(expr=m.x1**2+m.x2**2+m.x3**2)
50+
>>> m.const1 = pyo.Constraint(expr=6*m.x1+3*m.x2+2*m.x3-m.eta1 ==0)
51+
>>> m.const2 = pyo.Constraint(expr=m.eta2*m.x1+m.x2-m.x3-1 ==0)
52+
>>> m.cost = pyo.Objective(expr=m.x1**2+m.x2**2+m.x3**2)
5353

5454

5555
The solution of this optimization problem is :math:`x_1^* = 0.5`, :math:`x_2^* = 0.5`, and :math:`x_3^* = 0.0`. But what if we change the parameter values to :math:`\hat{p}_1 = 4.0` and :math:`\hat{p}_2 = 1.0`? Is there a quick way to approximate the new solution :math:`\hat{x}_1^*`, :math:`\hat{x}_2^*`, and :math:`\hat{x}_3^*`? Yes! This is the main functionality of sIPOPT and k_aug.
@@ -58,8 +58,8 @@ Next we define the perturbed parameter values :math:`\hat{p}_1` and :math:`\hat{
5858

5959
.. doctest:: python
6060

61-
>>> m.perturbed_eta1 = Param(initialize = 4.0)
62-
>>> m.perturbed_eta2 = Param(initialize = 1.0)
61+
>>> m.perturbed_eta1 = pyo.Param(initialize = 4.0)
62+
>>> m.perturbed_eta2 = pyo.Param(initialize = 1.0)
6363

6464
And finally we call sIPOPT or k_aug:
6565

0 commit comments

Comments
 (0)