Closed lbianchi-lbl closed 8 months ago
Some preliminary testing:
EDIT Running git bisect
on Pyomo/pyomo between 6.7.0 and 6.7.1 (using git bisect run bash -c "cd ../idaes-pse/ && pytest -m 'not integration' -k test_functions_unit"
) points to Pyomo/pyomo@cfa6ff49:
cfa6ff49f5d20c07af63faaba0b0877e1e327cb5 is the first bad commit
commit cfa6ff49f5d20c07af63faaba0b0877e1e327cb5
Author: John Siirola <jsiirola@users.noreply.github.com>
Date: Sat Dec 23 16:14:05 2023 -0700
Defer resolution of numpy import
pyomo/common/dependencies.py | 3 ++-
pyomo/common/env.py | 1 +
pyomo/common/numeric_types.py | 8 ++++++
pyomo/core/base/indexed_component.py | 12 +++++----
pyomo/core/expr/numeric_expr.py | 38 ++++++-----------------------
pyomo/core/tests/unit/test_numpy_expr.py | 2 +-
pyomo/core/tests/unit/test_numvalue.py | 42 ++++++++++++++++++++++----------
pyomo/environ/tests/test_environ.py | 2 --
8 files changed, 55 insertions(+), 53 deletions(-)
EDIT I've also attached a snapshot of list(sys.modules.keys())
when the AttributeError
is raised obtained by running pytest
with --pdb
for that commit: sys-modules.json
OK - there is a lot going on here, but it boils down to a logic error in how ExternalFunctions handle unrecognized types. Pyomo 6.7.1 removed the automatic import / registration of numpy types (if numpy was present), which - while cutting the time to import pyomo in half - is exposing holes in the type detection routines. It passes when the whole test suite is run because some other test encounters numpy first and correctly handles the type registration.
There are several workarounds that are possible:
pyomo.common.dependencies.numpy
(this guarantees that the registration is triggered)from pyomo.common.dependencies import numpy_available
bool(numpy_available)
(which triggers the type registrations)
I am working on a PR to Pyomo to close this particular hole in the type detection logic.
I've run into an error that seems to occur when I try to run only part of the IDAES test suite.
In the same environment (Ubuntu 20.04, Python 3.12.1, idaes-pse in dev mode from #1346), I get two different outcomes depending on the arguments passed to pytest:
pytest -m 'not integration'
: the tests passpytest -m 'not integration' -k test_functions_unit
: the tests fail (output below)