Skip to content

PEP: Standardize Example Imports #3543

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

Merged
merged 27 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b1c4c5e
Convert gdp examples
mrmundt Mar 26, 2025
ca65913
Fix imports in pyomo directory
mrmundt Mar 26, 2025
3295f58
One more - pe instead of pyo
mrmundt Mar 26, 2025
c65c7a6
Apply black
mrmundt Mar 26, 2025
fc0239b
Change imports in dae examples
mrmundt Mar 26, 2025
5ef520b
Apply black
mrmundt Mar 26, 2025
6cef24b
Update imports in doc
mrmundt Mar 26, 2025
e4bb16e
Path didn't exist
mrmundt Mar 26, 2025
8b3867d
Missed an import
mrmundt Mar 26, 2025
f796741
Update performance imports
mrmundt Mar 26, 2025
023eb96
Remove final three star imports
mrmundt Mar 26, 2025
62a5c5c
SAVE POINT: explanation
mrmundt Mar 27, 2025
6ca4b45
Update src file imports
mrmundt Mar 27, 2025
9fbc7be
Residual imports
mrmundt Mar 27, 2025
bfb75e1
Merge branch 'main' into example-imports
mrmundt Mar 27, 2025
2e125ac
One missed black file
mrmundt Mar 27, 2025
a2fb58f
Merge branch 'example-imports' of github.com:mrmundt/pyomo into examp…
mrmundt Mar 27, 2025
b3e5b62
A few missed imports and a typo
mrmundt Mar 31, 2025
b2c2a1f
Update typo
mrmundt Mar 31, 2025
e97567e
Merge branch 'main' into example-imports
mrmundt Mar 31, 2025
b49900b
Merge remote-tracking branch 'origin' into example-imports
mrmundt Apr 1, 2025
620b9af
Apply some requested changes; another round incoming
mrmundt Apr 1, 2025
9e4ab49
Decorator syntax whoops
mrmundt Apr 1, 2025
3d32f10
All the comment corrections
mrmundt Apr 1, 2025
92ca179
Fix doc links; also a weird usage of pyomo.environ in kernel
mrmundt Apr 3, 2025
9ee797e
Remove redundancy
mrmundt Apr 3, 2025
50129d0
Revert changes for plurality
mrmundt Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/OnlineDocs/contribution_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ provides an example of how this can be done, including a directory
for plugins and package tests. For example, this package can be
imported as a subpackage of ``pyomo.contrib``::

from pyomo.environ import *
import pyomo.environ as pyo
from pyomo.contrib.example import a

# Print the value of 'a' defined by this package
Expand Down
24 changes: 12 additions & 12 deletions doc/OnlineDocs/explanation/analysis/sensitivity_toolbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ Here :math:`x_1`, :math:`x_2`, and :math:`x_3` are the decision variables while
.. doctest:: python

# Import Pyomo and the sensitivity toolbox
>>> from pyomo.environ import *
>>> import pyomo.environ as pyo
>>> from pyomo.contrib.sensitivity_toolbox.sens import sensitivity_calculation

# Create a concrete model
>>> m = ConcreteModel()
>>> m = pyo.ConcreteModel()

# Define the variables with bounds and initial values
>>> m.x1 = Var(initialize = 0.15, within=NonNegativeReals)
>>> m.x2 = Var(initialize = 0.15, within=NonNegativeReals)
>>> m.x3 = Var(initialize = 0.0, within=NonNegativeReals)
>>> m.x1 = pyo.Var(initialize = 0.15, within=pyo.NonNegativeReals)
>>> m.x2 = pyo.Var(initialize = 0.15, within=pyo.NonNegativeReals)
>>> m.x3 = pyo.Var(initialize = 0.0, within=pyo.NonNegativeReals)

# Define the parameters
>>> m.eta1 = Param(initialize=4.5,mutable=True)
>>> m.eta2 = Param(initialize=1.0,mutable=True)
>>> m.eta1 = pyo.Param(initialize=4.5,mutable=True)
>>> m.eta2 = pyo.Param(initialize=1.0,mutable=True)

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


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.
Expand All @@ -58,8 +58,8 @@ Next we define the perturbed parameter values :math:`\hat{p}_1` and :math:`\hat{

.. doctest:: python

>>> m.perturbed_eta1 = Param(initialize = 4.0)
>>> m.perturbed_eta2 = Param(initialize = 1.0)
>>> m.perturbed_eta1 = pyo.Param(initialize = 4.0)
>>> m.perturbed_eta2 = pyo.Param(initialize = 1.0)

And finally we call sIPOPT or k_aug:

Expand Down
Loading
Loading