Skip to content

Commit

Permalink
Merge branch 'main' into mis
Browse files Browse the repository at this point in the history
  • Loading branch information
DLWoodruff authored Apr 3, 2024
2 parents fe6cc1d + f15a1da commit d3d9d6f
Show file tree
Hide file tree
Showing 36 changed files with 800 additions and 357 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,28 @@ Sur = "Sur"
# contrib package named mis and the acronym whence the name comes
mis = "mis"
MIS = "MIS"
# Ignore the shorthand ans for answer
ans = "ans"
# Ignore the keyword arange
arange = "arange"
# Ignore IIS
IIS = "IIS"
iis = "iis"
# Ignore PN
PN = "PN"
# Ignore hd
hd = "hd"
# Ignore opf
opf = "opf"
# Ignore FRE
FRE = "FRE"
# Ignore MCH
MCH = "MCH"
# Ignore RO
ro = "ro"
RO = "RO"
# Ignore EOF - end of file
EOF = "EOF"
# Ignore lst as shorthand for list
lst = "lst"
# AS NEEDED: Add More Words Below
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ version, we will remove testing for that Python version.

### Tutorials and Examples

* [Pyomo — Optimization Modeling in Python](https://link.springer.com/book/10.1007/978-3-030-68928-5)
* [Pyomo Workshop Slides](https://github.com/Pyomo/pyomo-tutorials/blob/main/Pyomo-Workshop-December-2023.pdf)
* [Prof. Jeffrey Kantor's Pyomo Cookbook](https://jckantor.github.io/ND-Pyomo-Cookbook/)
* The [companion notebooks](https://mobook.github.io/MO-book/intro.html)
Expand Down
2 changes: 2 additions & 0 deletions doc/OnlineDocs/bibliography.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Bibliography
John D. Siirola, Jean-Paul Watson, and David L. Woodruff.
Pyomo - Optimization Modeling in Python, 3rd Edition.
Vol. 67. Springer, 2021.
doi: `10.1007/978-3-030-68928-5
<https://doi.org/10.1007/978-3-030-68928-5>`_
.. [PyomoJournal] William E. Hart, Jean-Paul Watson, David L. Woodruff.
"Pyomo: modeling and solving mathematical programs in
Expand Down
17 changes: 10 additions & 7 deletions doc/OnlineDocs/tutorial_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ Pyomo Tutorial Examples

Additional Pyomo tutorials and examples can be found at the following links:

`Pyomo Workshop Slides and Exercises
<https://github.com/Pyomo/pyomo-tutorials>`_
* `Pyomo — Optimization Modeling in Python
<https://link.springer.com/book/10.1007/978-3-030-68928-5>`_ ([PyomoBookIII]_)

`Prof. Jeffrey Kantor's Pyomo Cookbook
<https://jckantor.github.io/ND-Pyomo-Cookbook/>`_
* `Pyomo Workshop Slides and Exercises
<https://github.com/Pyomo/pyomo-tutorials>`_

The `companion notebooks <https://mobook.github.io/MO-book/intro.html>`_
for *Hands-On Mathematical Optimization with Python*
* `Prof. Jeffrey Kantor's Pyomo Cookbook
<https://jckantor.github.io/ND-Pyomo-Cookbook/>`_

`Pyomo Gallery <https://github.com/Pyomo/PyomoGallery>`_
* The `companion notebooks <https://mobook.github.io/MO-book/intro.html>`_
for *Hands-On Mathematical Optimization with Python*

* `Pyomo Gallery <https://github.com/Pyomo/PyomoGallery>`_


1 change: 1 addition & 0 deletions pyomo/contrib/gdpopt/tests/test_LBB.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_infeasible_GDP(self):
self.assertIsNone(m.d.disjuncts[0].indicator_var.value)
self.assertIsNone(m.d.disjuncts[1].indicator_var.value)

@unittest.skipUnless(z3_available, "Z3 SAT solver is not available")
def test_infeasible_GDP_check_sat(self):
"""Test for infeasible GDP with check_sat option True."""
m = ConcreteModel()
Expand Down
16 changes: 14 additions & 2 deletions pyomo/contrib/gdpopt/tests/test_gdpopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from pyomo.common.collections import Bunch
from pyomo.common.config import ConfigDict, ConfigValue
from pyomo.common.fileutils import import_file, PYOMO_ROOT_DIR
from pyomo.contrib.appsi.solvers.gurobi import Gurobi
from pyomo.contrib.gdpopt.create_oa_subproblems import (
add_util_block,
add_disjunct_list,
Expand Down Expand Up @@ -767,6 +766,9 @@ def test_time_limit(self):
results.solver.termination_condition, TerminationCondition.maxTimeLimit
)

@unittest.skipUnless(
license_available, "No BARON license--8PP logical problem exceeds demo size"
)
def test_LOA_8PP_logical_default_init(self):
"""Test logic-based outer approximation with 8PP."""
exfile = import_file(join(exdir, 'eight_process', 'eight_proc_logical.py'))
Expand Down Expand Up @@ -870,6 +872,9 @@ def test_LOA_8PP_maxBinary(self):
)
ct.check_8PP_solution(self, eight_process, results)

@unittest.skipUnless(
license_available, "No BARON license--8PP logical problem exceeds demo size"
)
def test_LOA_8PP_logical_maxBinary(self):
"""Test logic-based OA with max_binary initialization."""
exfile = import_file(join(exdir, 'eight_process', 'eight_proc_logical.py'))
Expand Down Expand Up @@ -1050,7 +1055,11 @@ def assert_correct_disjuncts_active(

self.assertTrue(fabs(value(eight_process.profit.expr) - 68) <= 1e-2)

@unittest.skipUnless(Gurobi().available(), "APPSI Gurobi solver is not available")
@unittest.skipUnless(
SolverFactory('appsi_gurobi').available(exception_flag=False)
and SolverFactory('appsi_gurobi').license_is_valid(),
"Legacy APPSI Gurobi solver is not available",
)
def test_auto_persistent_solver(self):
exfile = import_file(join(exdir, 'eight_process', 'eight_proc_model.py'))
m = exfile.build_eight_process_flowsheet()
Expand Down Expand Up @@ -1126,6 +1135,9 @@ def test_RIC_8PP_default_init(self):
)
ct.check_8PP_solution(self, eight_process, results)

@unittest.skipUnless(
license_available, "No BARON license--8PP logical problem exceeds demo size"
)
def test_RIC_8PP_logical_default_init(self):
"""Test logic-based outer approximation with 8PP."""
exfile = import_file(join(exdir, 'eight_process', 'eight_proc_logical.py'))
Expand Down
9 changes: 8 additions & 1 deletion pyomo/contrib/gdpopt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,13 @@ def _add_bigm_constraint_to_transformed_model(m, constraint, block):
# making a Reference to the ComponentData so that it will look like an
# indexed component for now. If I redesign bigm at some point, then this
# could be prettier.
bigm._transform_constraint(Reference(constraint), parent_disjunct, None, [], [])
bigm._transform_constraint(
Reference(constraint),
parent_disjunct,
None,
[],
[],
1 - parent_disjunct.binary_indicator_var,
)
# Now get rid of it because this is a class attribute!
del bigm._config
7 changes: 7 additions & 0 deletions pyomo/contrib/incidence_analysis/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class IncidenceMethod(enum.Enum):
"""Use ``pyomo.repn.plugins.nl_writer.AMPLRepnVisitor``"""


class IncidenceOrder(enum.Enum):

dulmage_mendelsohn_upper = 0

dulmage_mendelsohn_lower = 1


_include_fixed = ConfigValue(
default=False,
domain=bool,
Expand Down
47 changes: 47 additions & 0 deletions pyomo/contrib/incidence_analysis/tests/test_visualize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2024
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

import pyomo.common.unittest as unittest
from pyomo.common.dependencies import (
matplotlib,
matplotlib_available,
scipy_available,
networkx_available,
)
from pyomo.contrib.incidence_analysis.visualize import spy_dulmage_mendelsohn
from pyomo.contrib.incidence_analysis.tests.models_for_testing import (
make_gas_expansion_model,
make_dynamic_model,
make_degenerate_solid_phase_model,
)


@unittest.skipUnless(matplotlib_available, "Matplotlib is not available")
@unittest.skipUnless(scipy_available, "SciPy is not available")
@unittest.skipUnless(networkx_available, "NetworkX is not available")
class TestSpy(unittest.TestCase):
def test_spy_dulmage_mendelsohn(self):
models = [
make_gas_expansion_model(),
make_dynamic_model(),
make_degenerate_solid_phase_model(),
]
for m in models:
fig, ax = spy_dulmage_mendelsohn(m)
# Note that this is a weak test. We just test that we can call the
# plot method, it doesn't raise an error, and gives us back the
# types we expect. We don't attempt to validate the resulting plot.
self.assertTrue(isinstance(fig, matplotlib.pyplot.Figure))
self.assertTrue(isinstance(ax, matplotlib.pyplot.Axes))


if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit d3d9d6f

Please sign in to comment.