From ec4ce9a5f953dd6a5e233108b0de416a07f0168e Mon Sep 17 00:00:00 2001 From: Miranda Mundt Date: Tue, 7 Jan 2025 07:31:00 -0700 Subject: [PATCH] Change import paths; add supremely unnecessary printing for extra info --- pyomo/contrib/pynumero/linalg/__init__.py | 2 +- pyomo/contrib/pynumero/sparse/__init__.py | 30 ++++++++++++++++--- pyomo/contrib/pynumero/sparse/base_block.py | 2 +- pyomo/contrib/pynumero/sparse/block_vector.py | 4 +-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pyomo/contrib/pynumero/linalg/__init__.py b/pyomo/contrib/pynumero/linalg/__init__.py index c1d9ff38825..0810db49e42 100644 --- a/pyomo/contrib/pynumero/linalg/__init__.py +++ b/pyomo/contrib/pynumero/linalg/__init__.py @@ -9,4 +9,4 @@ # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -from ..dependencies import numpy_available, scipy_available +from pyomo.common.dependencies import numpy_available, scipy_available diff --git a/pyomo/contrib/pynumero/sparse/__init__.py b/pyomo/contrib/pynumero/sparse/__init__.py index ee8196566db..010d316241c 100644 --- a/pyomo/contrib/pynumero/sparse/__init__.py +++ b/pyomo/contrib/pynumero/sparse/__init__.py @@ -9,8 +9,30 @@ # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ -from ..dependencies import numpy_available, scipy_available +from pyomo.common.dependencies import numpy_available, scipy_available -if numpy_available and scipy_available: - from .block_vector import BlockVector, NotFullyDefinedBlockVectorError - from .block_matrix import BlockMatrix, NotFullyDefinedBlockMatrixError +try: + if numpy_available and scipy_available: + from .block_vector import BlockVector, NotFullyDefinedBlockVectorError + from .block_matrix import BlockMatrix, NotFullyDefinedBlockMatrixError +except ImportError as e: + print("IMPORT ERROR: ", e) + print("Current environment information...") + import sys + import platform + import pkg_resources + + print(f"Python version: {platform.python_version()}") + print(f"Python executable: {sys.executable}") + print(f"Platform: {platform.system()} {platform.release()} ({platform.platform()})") + + print("\nInstalled packages:") + installed_packages = pkg_resources.working_set + installed_packages_list = sorted( + [f"{pkg.key}=={pkg.version}" for pkg in installed_packages] + ) + print("\n".join(installed_packages_list)) + + print("\nImported packages:") + imported_packages = sorted(sys.modules.keys()) + print("\n".join(imported_packages)) diff --git a/pyomo/contrib/pynumero/sparse/base_block.py b/pyomo/contrib/pynumero/sparse/base_block.py index 1baa10e1f73..00f6c87ecf7 100644 --- a/pyomo/contrib/pynumero/sparse/base_block.py +++ b/pyomo/contrib/pynumero/sparse/base_block.py @@ -11,7 +11,7 @@ # These classes are for checking types consistently and raising errors -from ..dependencies import numpy as np +from pyomo.common.dependencies import numpy as np class BaseBlockVector(object): diff --git a/pyomo/contrib/pynumero/sparse/block_vector.py b/pyomo/contrib/pynumero/sparse/block_vector.py index 53fa1d6518c..8d676392243 100644 --- a/pyomo/contrib/pynumero/sparse/block_vector.py +++ b/pyomo/contrib/pynumero/sparse/block_vector.py @@ -182,7 +182,7 @@ import operator -from ..dependencies import numpy as np +from pyomo.common.dependencies import numpy as np from .base_block import ( BaseBlockVector, vec_unary_ufuncs, @@ -621,7 +621,7 @@ def compress(self, condition, axis=None, out=None): accum += nelements return result else: - if other.__class__.__name__ == 'MPIBlockVector': + if condition.__class__.__name__ == 'MPIBlockVector': raise RuntimeError('Operation not supported by BlockVector') raise NotImplementedError()