scverse / pertpy

Perturbation Analysis in the scverse ecosystem.
https://pertpy.readthedocs.io/en/latest/
MIT License
92 stars 19 forks source link

Unable to import pertpy due to SymPy error #593

Closed dmj6288 closed 1 month ago

dmj6288 commented 1 month ago

Report

Hi All,

I successfully installed pertpy using pip on my conda environment on my Linux machine. However, I was unable to import it giving a name error for the product function in the SymPy function (see below)


NameError Traceback (most recent call last) Cell In[2], line 1 ----> 1 import pertpy as pt

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pertpy/init.py:20 18 from . import plot as pl 19 from . import preprocessing as pp ---> 20 from . import tools as tl

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pertpy/tools/init.py:5 3 from pertpy.tools._coda._sccoda import Sccoda 4 from pertpy.tools._coda._tasccoda import Tasccoda ----> 5 from pertpy.tools._dialogue import Dialogue 6 from pertpy.tools._differential_gene_expression import DifferentialGeneExpression 7 from pertpy.tools._distances._distance_tests import DistanceTest

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pertpy/tools/_dialogue.py:25 23 from seaborn import PairGrid 24 from sklearn.linear_model import LinearRegression ---> 25 from sparsecca import lp_pmd, multicca_permute, multicca_pmd 26 from statsmodels.sandbox.stats.multicomp import multipletests 28 if TYPE_CHECKING:

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/sparsecca/init.py:5 3 from ._cca_pmd import cca as cca_pmd 4 from ._multicca_pmd import multicca as multicca_pmd ----> 5 from ._multicca_lp import lp_pmd 6 from ._multicca_pmd_permute import multicca_permute 7 from ._pmd import pmd

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/sparsecca/_multicca_lp.py:4 2 from scipy.linalg import svd 3 from collections import defaultdict ----> 4 import pyomo.environ as pyo 6 from ._utils_pmd import scale, preprocess_datasets 7 from ._utils_pmd import soft

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/environ/init.py:86 82 pkg = _sys.modules[pname] 83 pkg.load() ---> 86 _import_packages() 88 # 89 # Expose the symbols from pyomo.core 90 # 91 from pyomo.dataportal import DataPortal

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/environ/init.py:66, in _import_packages() 64 pname = _package + '.plugins' 65 try: ---> 66 _do_import(pname) 67 except ImportError: 68 exctype, err, tb = _sys.exc_info() # BUG?

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/environ/init.py:18, in _do_import(pkg_name) 17 def _do_import(pkg_name): ---> 18 importlib.import_module(pkg_name)

File ~/anaconda3/envs/r_env/lib/python3.10/importlib/init.py:126, in import_module(name, package) 124 break 125 level += 1 --> 126 return _bootstrap._gcd_import(name[level:], package, level)

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/core/init.py:27 12 from pyomo.core.expr.numvalue import ( 13 value, 14 is_constant, (...) 22 polynomial_degree, 23 ) 25 from pyomo.core.expr.boolean_value import BooleanValue ---> 27 from pyomo.core.expr import ( 28 linear_expression, 29 nonlinear_expression, 30 land, 31 lor, 32 equivalent, 33 exactly, 34 atleast, 35 atmost, 36 all_different, 37 count_if, 38 implies, 39 lnot, 40 xor, 41 inequality, 42 log, 43 log10, 44 sin, 45 cos, 46 tan, 47 cosh, 48 sinh, 49 tanh, 50 asin, 51 acos, 52 atan, 53 exp, 54 sqrt, 55 asinh, 56 acosh, 57 atanh, 58 ceil, 59 floor, 60 Expr_if, 61 ) 63 from pyomo.core.expr.calculus.derivatives import differentiate 64 from pyomo.core.expr.taylor_series import taylor_series_expansion

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/core/expr/init.py:203 157 from .template_expr import ( 158 GetItemExpression, 159 Numeric_GetItemExpression, (...) 183 templatize_constraint, 184 ) 185 from .visitor import ( 186 StreamBasedExpressionVisitor, 187 SimpleExpressionVisitor, (...) 200 sizeof_expression, 201 ) --> 203 from .calculus.derivatives import differentiate 204 from .taylor_series import taylor_series_expansion

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/core/expr/calculus/derivatives.py:13 1 # 2 # 3 # Pyomo: Python Optimization Modeling Objects (...) 9 # This software is distributed under the 3-clause BSD License. 10 # 12 import enum ---> 13 from .diff_with_sympy import differentiate as sympy_diff 14 from .diff_with_pyomo import reverse_sd, reverse_ad 17 class Modes(str, enum.Enum):

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/core/expr/calculus/diff_with_sympy.py:12 1 # 2 # 3 # Pyomo: Python Optimization Modeling Objects (...) 9 # This software is distributed under the 3-clause BSD License. 10 # ---> 12 from pyomo.core.expr.sympy_tools import ( 13 sympy_available, 14 sympyify_expression, 15 sympy2pyomo_expression, 16 ) 18 # A "public" attribute indicating that differentiate() can be called 19 # ... this provides a bit of future-proofing for alternative approaches 20 # to symbolic differentiation. 21 differentiate_available = sympy_available

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/core/expr/sympy_tools.py:113 73 _pyomo_operator_map.update( 74 { 75 EXPR.SumExpression: sympy.Add, (...) 86 } 87 ) 89 _functionMap.update( 90 { 91 'exp': sympy.exp, (...) 109 } 110 ) --> 113 sympy, sympy_available = attempt_import('sympy', callback=_configure_sympy) 116 if sys.version_info[:2] < (3, 8): 118 def _prod(args):

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/common/dependencies.py:738, in attempt_import(name, error_message, only_catch_importerror, minimum_version, alt_names, callback, importer, defer_check, defer_import, deferred_submodules, catch_exceptions) 735 if deferred_submodules: 736 raise ValueError("deferred_submodules is only valid if defer_import==True") --> 738 return _perform_import( 739 name=name, 740 error_message=error_message, 741 minimum_version=minimum_version, 742 callback=callback, 743 importer=importer, 744 catch_exceptions=catch_exceptions, 745 package=inspect.currentframe().f_back.f_globals.get('name', ''), 746 )

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/common/dependencies.py:768, in _perform_import(name, error_message, minimum_version, callback, importer, catch_exceptions, package) 766 if minimum_version is None or check_min_version(module, minimum_version): 767 if callback is not None: --> 768 callback(module, True) 769 return module, True 770 else:

File ~/anaconda3/envs/r_env/lib/python3.10/site-packages/pyomo/core/expr/sympy_tools.py:38, in _configure_sympy(sympy, available) 32 if not available: 33 return 35 _operatorMap.update( 36 { 37 sympy.Add: sum, ---> 38 sympy.Mul: _prod, 39 sympy.Pow: lambda x: operator.pow(x), 40 sympy.exp: lambda x: EXPR.exp(x), 41 sympy.log: lambda x: EXPR.log(x), 42 sympy.sin: lambda x: EXPR.sin(x), 43 sympy.asin: lambda x: EXPR.asin(x), 44 sympy.sinh: lambda x: EXPR.sinh(x), 45 sympy.asinh: lambda x: EXPR.asinh(x), 46 sympy.cos: lambda x: EXPR.cos(x), 47 sympy.acos: lambda x: EXPR.acos(x), 48 sympy.cosh: lambda x: EXPR.cosh(x), 49 sympy.acosh: lambda x: EXPR.acosh(x), 50 sympy.tan: lambda x: EXPR.tan(x), 51 sympy.atan: lambda x: EXPR.atan(x), 52 sympy.tanh: lambda x: EXPR.tanh(x), 53 sympy.atanh: lambda x: EXPR.atanh(x), 54 sympy.ceiling: lambda x: EXPR.ceil(x), 55 sympy.floor: lambda x: EXPR.floor(x), 56 sympy.sqrt: lambda x: EXPR.sqrt(x), 57 sympy.Abs: lambda x: abs(x), 58 sympy.Derivative: _nondifferentiable, 59 sympy.Tuple: lambda x: x, 60 sympy.Or: lambda x: EXPR.lor(x), 61 sympy.And: lambda x: EXPR.land(x), 62 sympy.Implies: lambda x: EXPR.implies(x), 63 sympy.Equivalent: lambda x: EXPR.equivalents(x), 64 sympy.Not: lambda x: EXPR.lnot(x), 65 sympy.LessThan: lambda x: operator.le(x), 66 sympy.StrictLessThan: lambda x: operator.lt(x), 67 sympy.GreaterThan: lambda x: operator.ge(x), 68 sympy.StrictGreaterThan: lambda x: operator.gt(x), 69 sympy.Equality: lambda x: operator.eq(*x), 70 } 71 ) 73 _pyomo_operator_map.update( 74 { 75 EXPR.SumExpression: sympy.Add, (...) 86 } 87 ) 89 _functionMap.update( 90 { 91 'exp': sympy.exp, (...) 109 } 110 )

NameError: name '_prod' is not defined

Any help would be greatly appreciated.

Thank you! Dennis

Version information


session_info 1.0.0

Click to view modules imported as dependencies

IPython 8.12.0 jupyter_client 8.1.0 jupyter_core 5.3.0 notebook 6.5.2

Python 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:23:14) [GCC 10.4.0] Linux-5.15.0-83-generic-x86_64-with-glibc2.35

Session information updated at 2024-05-11 20:15

Zethson commented 1 month ago

Hi,

did you use a clean environment or an existing one? Could you please try it with a clean environment if you didn't?

Zethson commented 1 month ago

I can't reproduce this.

Zethson commented 1 month ago

Could you please report this issue to https://github.com/Pyomo/pyomo if you encounter this again? It seems to be upstream

aaronwtr commented 1 month ago

https://github.com/Pyomo/pyomo/pull/3264 fixes this