Skip to content

Commit

Permalink
Merge branch 'main' into benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bernalde authored Jan 24, 2024
2 parents 601ec30 + 85b63ab commit 76acc80
Show file tree
Hide file tree
Showing 38 changed files with 1,109 additions and 914 deletions.
34 changes: 16 additions & 18 deletions .github/workflows/test_branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ jobs:
python: 3.9
TARGET: win
PYENV: conda
PACKAGES: glpk
PACKAGES: glpk pytest-qt

- os: ubuntu-latest
python: '3.11'
other: /conda
skip_doctest: 1
TARGET: linux
PYENV: conda
PACKAGES:
PACKAGES: pytest-qt

- os: ubuntu-latest
python: 3.9
Expand Down Expand Up @@ -213,6 +213,15 @@ jobs:
auto-update-conda: false
python-version: ${{ matrix.python }}

# This is necessary for qt (UI) tests; the package utilized here does not
# have support for OSX.
- name: Set up UI testing infrastructure
if: ${{ matrix.TARGET != 'osx' }}
uses: pyvista/setup-headless-display-action@v2
with:
qt: true
pyvista: false

# GitHub actions is very fragile when it comes to setting up various
# Python interpreters, expecially the setup-miniconda interface.
# Per the setup-miniconda documentation, it is important to always
Expand Down Expand Up @@ -309,7 +318,7 @@ jobs:
fi
# HACK: Remove problem packages on conda+Linux
if test "${{matrix.TARGET}}" == linux; then
EXCLUDE="casadi numdifftools pint $EXCLUDE"
EXCLUDE="casadi numdifftools $EXCLUDE"
fi
EXCLUDE=`echo "$EXCLUDE" | xargs`
if test -n "$EXCLUDE"; then
Expand Down Expand Up @@ -346,10 +355,11 @@ jobs:
| sed -r 's/\s+/ /g' | cut -d\ -f3) || echo ""
if test -n "$_BUILDS"; then
_ISPY=$(echo "$_BUILDS" | grep "^py") \
|| echo "No python build detected"
_PYOK=$(echo "$_BUILDS" | grep "^$PYVER") \
|| echo "No python build matching $PYVER detected"
|| echo "INFO: No python build detected."
_PYOK=$(echo "$_BUILDS" | grep -E "^($PYVER|pyh)") \
|| echo "INFO: No python build matching $PYVER detected."
if test -z "$_ISPY" -o -n "$_PYOK"; then
echo ""
echo "... INSTALLING $PKG"
conda install -y "$PKG" || _BUILDS=""
fi
Expand All @@ -358,18 +368,6 @@ jobs:
echo "WARNING: $PKG is not available"
fi
done
# TODO: This is a hack to stop test_qt.py from running until we
# can better troubleshoot why it fails on GHA
for QTPACKAGE in qt pyqt; do
# Because conda is insane, removing packages can cause
# unrelated packages to be updated (breaking version
# specifications specified previously, e.g., in
# setup.py). There doesn't appear to be a good
# workaround, so we will just force-remove (recognizing
# that it may break other conda cruft).
conda remove --force-remove $QTPACKAGE \
|| echo "$QTPACKAGE not in this environment"
done
fi
# Re-try Pyomo (optional) dependencies with pip
if test -n "$PYPI_DEPENDENCIES"; then
Expand Down
34 changes: 16 additions & 18 deletions .github/workflows/test_pr_and_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ jobs:
- os: windows-latest
TARGET: win
PYENV: conda
PACKAGES: glpk
PACKAGES: glpk pytest-qt

- os: ubuntu-latest
python: '3.11'
other: /conda
skip_doctest: 1
TARGET: linux
PYENV: conda
PACKAGES:
PACKAGES: pytest-qt

- os: ubuntu-latest
python: 3.9
Expand Down Expand Up @@ -243,6 +243,15 @@ jobs:
auto-update-conda: false
python-version: ${{ matrix.python }}

# This is necessary for qt (UI) tests; the package utilized here does not
# have support for OSX.
- name: Set up UI testing infrastructure
if: ${{ matrix.TARGET != 'osx' }}
uses: pyvista/setup-headless-display-action@v2
with:
qt: true
pyvista: false

# GitHub actions is very fragile when it comes to setting up various
# Python interpreters, expecially the setup-miniconda interface.
# Per the setup-miniconda documentation, it is important to always
Expand Down Expand Up @@ -339,7 +348,7 @@ jobs:
fi
# HACK: Remove problem packages on conda+Linux
if test "${{matrix.TARGET}}" == linux; then
EXCLUDE="casadi numdifftools pint $EXCLUDE"
EXCLUDE="casadi numdifftools $EXCLUDE"
fi
EXCLUDE=`echo "$EXCLUDE" | xargs`
if test -n "$EXCLUDE"; then
Expand Down Expand Up @@ -376,10 +385,11 @@ jobs:
| sed -r 's/\s+/ /g' | cut -d\ -f3) || echo ""
if test -n "$_BUILDS"; then
_ISPY=$(echo "$_BUILDS" | grep "^py") \
|| echo "No python build detected"
_PYOK=$(echo "$_BUILDS" | grep "^$PYVER") \
|| echo "No python build matching $PYVER detected"
|| echo "INFO: No python build detected."
_PYOK=$(echo "$_BUILDS" | grep -E "^($PYVER|pyh)") \
|| echo "INFO: No python build matching $PYVER detected."
if test -z "$_ISPY" -o -n "$_PYOK"; then
echo ""
echo "... INSTALLING $PKG"
conda install -y "$PKG" || _BUILDS=""
fi
Expand All @@ -388,18 +398,6 @@ jobs:
echo "WARNING: $PKG is not available"
fi
done
# TODO: This is a hack to stop test_qt.py from running until we
# can better troubleshoot why it fails on GHA
for QTPACKAGE in qt pyqt; do
# Because conda is insane, removing packages can cause
# unrelated packages to be updated (breaking version
# specifications specified previously, e.g., in
# setup.py). There doesn't appear to be a good
# workaround, so we will just force-remove (recognizing
# that it may break other conda cruft).
conda remove --force-remove $QTPACKAGE \
|| echo "$QTPACKAGE not in this environment"
done
fi
# Re-try Pyomo (optional) dependencies with pip
if test -n "$PYPI_DEPENDENCIES"; then
Expand Down
8 changes: 5 additions & 3 deletions doc/OnlineDocs/advanced_topics/linearexpression.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ LinearExpression
================

Significant speed
improvements can be obtained using the ``LinearExpression`` object
improvements can sometimes be obtained using the ``LinearExpression`` object
when there are long, dense, linear expressions. The arguments are

::
Expand All @@ -11,7 +11,9 @@ when there are long, dense, linear expressions. The arguments are

where the second and third arguments are lists that must be of the
same length. Here is a simple example that illustrates the
syntax. This example creates two constraints that are the same:
syntax. This example creates two constraints that are the same; in this
particular case the LinearExpression component would offer very little improvement
because Pyomo would be able to detect that `campe2` is a linear expression:

.. doctest::

Expand All @@ -38,5 +40,5 @@ syntax. This example creates two constraints that are the same:

.. warning::

The lists that are passed to ``LinearModel`` are not copied, so caution must
The lists that are passed to ``LinearExpression`` are not copied, so caution must
be exercised if they are modified after the component is constructed.
43 changes: 20 additions & 23 deletions doc/OnlineDocs/contributed_packages/pyros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,11 @@ For this example, we obtain the following price of robustness results:
+==========================================+==============================+=============================+
| 0.00 | 35,837,659.18 | 0.00 % |
+------------------------------------------+------------------------------+-----------------------------+
| 0.10 | 36,135,191.59 | 0.82 % |
| 0.10 | 36,135,182.66 | 0.83 % |
+------------------------------------------+------------------------------+-----------------------------+
| 0.20 | 36,437,979.81 | 1.64 % |
| 0.20 | 36,437,979.81 | 1.68 % |
+------------------------------------------+------------------------------+-----------------------------+
| 0.30 | 43,478,190.92 | 17.57 % |
| 0.30 | 43,478,190.91 | 21.32 % |
+------------------------------------------+------------------------------+-----------------------------+
| 0.40 | ``robust_infeasible`` | :math:`\text{-----}` |
+------------------------------------------+------------------------------+-----------------------------+
Expand Down Expand Up @@ -854,10 +854,10 @@ Observe that the log contains the following information:
:linenos:
==============================================================================
PyROS: The Pyomo Robust Optimization Solver, v1.2.8.
PyROS: The Pyomo Robust Optimization Solver, v1.2.9.
Pyomo version: 6.7.0
Commit hash: unknown
Invoked at UTC 2023-11-03T04:27:42.954101
Invoked at UTC 2023-12-16T00:00:00.000000
Developed by: Natalie M. Isenberg (1), Jason A. F. Sherman (1),
John D. Siirola (2), Chrysanthos E. Gounaris (1)
Expand Down Expand Up @@ -914,37 +914,34 @@ Observe that the log contains the following information:
------------------------------------------------------------------------------
Itn Objective 1-Stg Shift 2-Stg Shift #CViol Max Viol Wall Time (s)
------------------------------------------------------------------------------
0 3.5838e+07 - - 5 1.8832e+04 1.555
1 3.5838e+07 2.2045e-12 2.7854e-12 7 3.7766e+04 2.991
2 3.6116e+07 1.2324e-01 3.9256e-01 8 1.3466e+06 4.881
3 3.6285e+07 5.1968e-01 4.5604e-01 6 4.8734e+03 6.908
4 3.6285e+07 2.6524e-13 1.3909e-13 1 3.5036e+01 9.176
5 3.6285e+07 2.0167e-13 5.4357e-02 6 2.9103e+00 11.457
6 3.6285e+07 2.2335e-12 1.2150e-01 5 4.1726e-01 13.868
7 3.6285e+07 2.2340e-12 1.1422e-01 0 9.3279e-10g 20.917
0 3.5838e+07 - - 5 1.8832e+04 1.741
1 3.5838e+07 3.5184e-15 3.9404e-15 10 4.2516e+06 3.766
2 3.5993e+07 1.8105e-01 7.1406e-01 13 5.2004e+06 6.288
3 3.6285e+07 5.1968e-01 7.7753e-01 4 1.7892e+04 8.247
4 3.6285e+07 9.1166e-13 1.9702e-15 0 7.1157e-10g 11.456
------------------------------------------------------------------------------
Robust optimal solution identified.
------------------------------------------------------------------------------
Timing breakdown:
Identifier ncalls cumtime percall %
-----------------------------------------------------------
main 1 20.918 20.918 100.0
main 1 11.457 11.457 100.0
------------------------------------------------------
dr_polishing 7 1.472 0.210 7.0
global_separation 47 1.239 0.026 5.9
local_separation 376 9.244 0.025 44.2
master 8 5.259 0.657 25.1
master_feasibility 7 0.486 0.069 2.3
preprocessing 1 0.403 0.403 1.9
other n/a 2.815 n/a 13.5
dr_polishing 4 0.682 0.171 6.0
global_separation 47 1.109 0.024 9.7
local_separation 235 5.810 0.025 50.7
master 5 1.353 0.271 11.8
master_feasibility 4 0.247 0.062 2.2
preprocessing 1 0.429 0.429 3.7
other n/a 1.828 n/a 16.0
======================================================
===========================================================
------------------------------------------------------------------------------
Termination stats:
Iterations : 8
Solve time (wall s) : 20.918
Iterations : 5
Solve time (wall s) : 11.457
Final objective value : 3.6285e+07
Termination condition : pyrosTerminationCondition.robust_optimal
------------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion doc/OnlineDocs/src/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class TestOnlineDocExamples(unittest.BaselineTestDriver, unittest.TestCase):
list(filter(os.path.isdir, glob.glob(os.path.join(currdir, '*'))))
)

solver_dependencies = {}
solver_dependencies = {
'test_data_pyomo_diet1': ['glpk'],
'test_data_pyomo_diet2': ['glpk'],
'test_kernel_examples': ['glpk'],
}
# Note on package dependencies: two tests actually need
# pyutilib.excel.spreadsheet; however, the pyutilib importer is
# broken on Python>=3.12, so instead of checking for spreadsheet, we
Expand Down
4 changes: 2 additions & 2 deletions pyomo/common/numeric_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def check_if_numeric_type(obj):
# trigger the resolution of numpy_available and check if this
# type was automatically registered
bool(numpy_available)
if obj_class in native_numeric_types:
return True
if obj_class in native_types:
return obj_class in native_numeric_types

try:
obj_plus_0 = obj + 0
Expand Down
14 changes: 14 additions & 0 deletions pyomo/common/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,20 @@ def assertRaisesRegex(self, expected_exception, expected_regex, *args, **kwargs)
context = contextClass(expected_exception, self, expected_regex)
return context.handle('assertRaisesRegex', args, kwargs)

def assertExpressionsEqual(self, a, b, include_named_exprs=True, places=None):
from pyomo.core.expr.compare import assertExpressionsEqual

return assertExpressionsEqual(self, a, b, include_named_exprs, places)

def assertExpressionsStructurallyEqual(
self, a, b, include_named_exprs=True, places=None
):
from pyomo.core.expr.compare import assertExpressionsStructurallyEqual

return assertExpressionsStructurallyEqual(
self, a, b, include_named_exprs, places
)


class BaselineTestDriver(object):
"""Generic driver for performing baseline tests in bulk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

import pandas as pd
from pyomo.common.dependencies import pandas as pd
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

import numpy as np
import pandas as pd
from pyomo.common.dependencies import numpy as np, pandas as pd
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
reactor_design_model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

import numpy as np
import pandas as pd
from pyomo.common.dependencies import numpy as np, pandas as pd
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

import numpy as np
import pandas as pd
from pyomo.common.dependencies import numpy as np, pandas as pd
from itertools import product
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

import pandas as pd
from pyomo.common.dependencies import pandas as pd
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

import pandas as pd
from pyomo.common.dependencies import pandas as pd
from os.path import join, abspath, dirname
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.reactor_design.reactor_design import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Continuously stirred tank reactor model, based on
pyomo/examples/doc/pyomobook/nonlinear-ch/react_design/ReactorDesign.py
"""
import pandas as pd
from pyomo.common.dependencies import pandas as pd
from pyomo.environ import (
ConcreteModel,
Param,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

import pandas as pd
from pyomo.common.dependencies import pandas as pd
from os.path import join, abspath, dirname

import pyomo.contrib.parmest.parmest as parmest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

import pandas as pd
from pyomo.common.dependencies import pandas as pd
import pyomo.contrib.parmest.parmest as parmest
from pyomo.contrib.parmest.examples.rooney_biegler.rooney_biegler import (
rooney_biegler_model,
Expand Down
Loading

0 comments on commit 76acc80

Please sign in to comment.