Skip to content

Commit

Permalink
Merge pull request #3018 from jsiirola/conda-setup-error
Browse files Browse the repository at this point in the history
Resolve build infrastructure errors (with mpi4py, gams, networkx)
  • Loading branch information
jsiirola authored Oct 20, 2023
2 parents 4267cbd + 0593891 commit 40c3dae
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/test_branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
skip_doctest: 1
TARGET: linux
PYENV: conda
PACKAGES: mpi4py openmpi
PACKAGES: mpi4py

- os: ubuntu-latest
python: '3.10'
Expand Down Expand Up @@ -318,6 +318,8 @@ jobs:
fi
done
echo "*** Install Pyomo dependencies ***"
# Note: this will fail the build if any installation fails (or
# possibly if it outputs messages to stderr)
conda install --update-deps -q -y $CONDA_DEPENDENCIES
if test -z "${{matrix.slim}}"; then
PYVER=$(echo "py${{matrix.python}}" | sed 's/\.//g')
Expand All @@ -334,7 +336,7 @@ jobs:
echo "$_PKGLIST"
_BASE=$(echo "$PKG" | sed 's/[=<>].*//')
_BUILDS=$(echo "$_PKGLIST" | grep "^$_BASE " \
| sed -r 's/\s+/ /g' | cut -d\ -f3) || echo ""x
| sed -r 's/\s+/ /g' | cut -d\ -f3) || echo ""
if test -n "$_BUILDS"; then
_ISPY=$(echo "$_BUILDS" | grep "^py") \
|| echo "No python build detected"
Expand Down Expand Up @@ -623,7 +625,8 @@ jobs:
# is fully generated by a single process before invoking MPI
$PYTHON_EXE -c "from pyomo.dataportal.parse_datacmds import \
parse_data_commands; parse_data_commands(data='')"
mpirun -np ${{matrix.mpi}} --oversubscribe pytest -v \
# Note: if we are testing with openmpi, add '--oversubscribe'
mpirun -np ${{matrix.mpi}} pytest -v \
--junit-xml=TEST-pyomo-mpi.xml \
-m "mpi" -W ignore::Warning \
pyomo `pwd`/pyomo-model-libraries
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test_pr_and_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
skip_doctest: 1
TARGET: linux
PYENV: conda
PACKAGES: mpi4py openmpi
PACKAGES: mpi4py

- os: ubuntu-latest
python: 3.11
Expand Down Expand Up @@ -348,6 +348,8 @@ jobs:
fi
done
echo "*** Install Pyomo dependencies ***"
# Note: this will fail the build if any installation fails (or
# possibly if it outputs messages to stderr)
conda install --update-deps -q -y $CONDA_DEPENDENCIES
if test -z "${{matrix.slim}}"; then
PYVER=$(echo "py${{matrix.python}}" | sed 's/\.//g')
Expand Down Expand Up @@ -653,7 +655,8 @@ jobs:
# is fully generated by a single process before invoking MPI
$PYTHON_EXE -c "from pyomo.dataportal.parse_datacmds import \
parse_data_commands; parse_data_commands(data='')"
mpirun -np ${{matrix.mpi}} --oversubscribe pytest -v \
# Note: if we are testing with openmpi, add '--oversubscribe'
mpirun -np ${{matrix.mpi}} pytest -v \
--junit-xml=TEST-pyomo-mpi.xml \
-m "mpi" -W ignore::Warning \
pyomo `pwd`/pyomo-model-libraries
Expand Down
16 changes: 9 additions & 7 deletions pyomo/contrib/pynumero/examples/tests/test_mpi_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@
)

SKIPTESTS = []
if numpy_available and scipy_available:
pass
else:
SKIPTESTS.append("Pynumero needs scipy and numpy>=1.13.0 to run BlockMatrix tests")
if not numpy_available:
SKIPTESTS.append("Pynumero needs numpy>=1.13.0 to run BlockMatrix tests")
if not scipy_available:
SKIPTESTS.append("Pynumero needs scipy to run BlockMatrix tests")

try:
from mpi4py import MPI

comm = MPI.COMM_WORLD
if comm.Get_size() != 3:
SKIPTESTS.append("Pynumero MPI examples require exactly 3 processes")
SKIPTESTS.append(
f"Pynumero MPI examples require 3 MPI processes (got {comm.Get_size()})"
)
except ImportError:
SKIPTESTS.append("Pynumero MPI examples require exactly 3 processes")
SKIPTESTS.append("Pynumero MPI examples require mpi4py")

if not SKIPTESTS:
from pyomo.contrib.pynumero.examples import parallel_vector_ops, parallel_matvec


@unittest.pytest.mark.mpi
@unittest.skipIf(SKIPTESTS, SKIPTESTS)
@unittest.skipIf(SKIPTESTS, "\n".join(SKIPTESTS))
class TestExamples(unittest.TestCase):
def test_parallel_vector_ops(self):
z1_local, z2, z3 = parallel_vector_ops.main()
Expand Down
6 changes: 5 additions & 1 deletion pyomo/solvers/plugins/solvers/GAMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ def solve(self, *args, **kwds):
self.available()

from gams import GamsWorkspace, DebugLevel
from gams.workspace import GamsExceptionExecution

try:
from gams import GamsExceptionExecution
except ImportError:
from gams.workspace import GamsExceptionExecution

if len(args) != 1:
raise ValueError(
Expand Down
5 changes: 4 additions & 1 deletion pyomo/solvers/tests/checks/test_GAMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
opt_py = SolverFactory('gams', solver_io='python')
gamspy_available = opt_py.available(exception_flag=False)
if gamspy_available:
from gams.workspace import GamsExceptionExecution
try:
from gams import GamsExceptionExecution
except:
from gams.workspace import GamsExceptionExecution

opt_gms = SolverFactory('gams', solver_io='gms')
gamsgms_available = opt_gms.available(exception_flag=False)
Expand Down
30 changes: 28 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,30 @@ def run(self):
print(' '.join(deps))

def _print_deps(self, deplist):
class version_cmp(object):
ver = tuple(map(int, platform.python_version_tuple()[:2]))

def __lt__(self, other):
return self.ver < tuple(map(int, other.split('.')))

def __le__(self, other):
return self.ver <= tuple(map(int, other.split('.')))

def __gt__(self, other):
return not self.__le__(other)

def __ge__(self, other):
return not self.__lt__(other)

def __eq__(self, other):
return self.ver == tuple(map(int, other.split('.')))

def __ne__(self, other):
return not self.__eq__(other)

implementation_name = sys.implementation.name
platform_system = platform.system()
python_version = '.'.join(platform.python_version_tuple()[:2])
python_version = version_cmp()
for entry in deplist:
dep, _, condition = (_.strip() for _ in entry.partition(';'))
if condition and not eval(condition):
Expand Down Expand Up @@ -242,7 +263,12 @@ def _print_deps(self, deplist):
# Note: matplotlib 3.6.1 has bug #24127, which breaks
# seaborn's histplot (triggering parmest failures)
'matplotlib!=3.6.1',
'networkx', # network, incidence_analysis, community_detection
# network, incidence_analysis, community_detection
# Note: networkx 3.2 is Python>-3.9, but there is a broken
# 3.2 package on conda-forgethat will get implicitly
# installed on python 3.8
'networkx<3.2; python_version<"3.9"',
'networkx; python_version>="3.9"',
'numpy',
'openpyxl', # dataportals
#'pathos', # requested for #963, but PR currently closed
Expand Down

0 comments on commit 40c3dae

Please sign in to comment.