Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Not working with numpy 2 (np.obj2sctype was removed in the NumPy 2.0 release.) #7592

Open
mauhcs opened this issue Nov 27, 2024 · 4 comments
Labels

Comments

@mauhcs
Copy link

mauhcs commented Nov 27, 2024

Describe the issue:

When importing pymc with import pymc as pm I get the error message:

AttributeError:np.obj2sctypewas removed in the NumPy 2.0 release. Usenp.dtype(obj).type instead.
(see full error message below).

I think the message is pretty clear, pymc does not support Numpy 2.0 at the moment.

Do we have any plans to support it?

Reproduceable code example:

# you just need to import pymc with numpy 2.1.3 of higher to get the error
import pymc as pm

Error message:

----> 1 import pymc as pm

File ~/miniconda3/lib/python3.12/site-packages/pymc/__init__.py:46
     41     augmented = f"{augmented} -fno-unwind-tables -fno-asynchronous-unwind-tables"
     43     pytensor.config.gcc__cxxflags = augmented
---> 46 __set_compiler_flags()
     48 from pymc import _version, gp, ode, sampling
     49 from pymc.backends import *

File ~/miniconda3/lib/python3.12/site-packages/pymc/__init__.py:29, in __set_compiler_flags()
     27 def __set_compiler_flags():
     28     # Workarounds for PyTensor compiler problems on various platforms
---> 29     import pytensor
     31     current = pytensor.config.gcc__cxxflags
     32     augmented = f"{current} -Wno-c  11-narrowing"

File ~/miniconda3/lib/python3.12/site-packages/pytensor/__init__.py:118
    114     return as_tensor_variable(x, **kwargs)
    117 # isort: off
--> 118 from pytensor import scalar, tensor
    119 from pytensor.compile import (
    120     In,
    121     Mode,
   (...)
    127     shared,
    128 )
    129 from pytensor.compile.function import function, function_dump

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/__init__.py:103
     99     return len(var.data)
    102 import pytensor.tensor.exceptions
--> 103 import pytensor.tensor.rewriting
    104 from pytensor.gradient import grad, hessian, jacobian
    106 # adds shared-variable constructors

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/rewriting/__init__.py:1
----> 1 import pytensor.tensor.rewriting.basic
      2 import pytensor.tensor.rewriting.blas
      3 import pytensor.tensor.rewriting.blas_c

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/rewriting/basic.py:43
     34 from pytensor.graph.rewriting.basic import (
     35     NodeRewriter,
     36     RemovalNodeRewriter,
   (...)
     40     node_rewriter,
     41 )
     42 from pytensor.graph.rewriting.db import RewriteDatabase
---> 43 from pytensor.raise_op import Assert, CheckAndRaise, assert_op
     44 from pytensor.tensor.basic import (
     45     Alloc,
     46     AllocEmpty,
   (...)
     64     zeros_like,
     65 )
     66 from pytensor.tensor.elemwise import DimShuffle, Elemwise

File ~/miniconda3/lib/python3.12/site-packages/pytensor/raise_op.py:14
     12 from pytensor.link.c.type import Generic
     13 from pytensor.scalar.basic import ScalarType
---> 14 from pytensor.tensor.type import DenseTensorType
     17 class ExceptionType(Generic):
     18     def __eq__(self, other):

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/type.py:801
    796         dtype = config.floatX
    798     return TensorType(dtype=dtype, shape=shape, **kwargs)(name=name)
--> 801 cscalar = TensorType("complex64", ())
    802 zscalar = TensorType("complex128", ())
    803 fscalar = TensorType("float32", ())

File ~/miniconda3/lib/python3.12/site-packages/pytensor/tensor/type.py:105, in TensorType.__init__(self, dtype, shape, name, broadcastable)
    103     self.dtype = config.floatX
    104 else:
--> 105     if np.obj2sctype(dtype) is None:
    106         raise TypeError(f"Invalid dtype: {dtype}")
    108     self.dtype = np.dtype(dtype).name

File ~/miniconda3/lib/python3.12/site-packages/numpy/__init__.py:400, in __getattr__(attr)
    397     raise AttributeError(__former_attrs__[attr], name=None)
    399 if attr in __expired_attributes__:
--> 400     raise AttributeError(
    401         f"`np.{attr}` was removed in the NumPy 2.0 release. "
    402         f"{__expired_attributes__[attr]}",
    403         name=None
    404     )
    406 if attr == "chararray":
    407     warnings.warn(
    408         "`np.chararray` is deprecated and will be removed from "
    409         "the main namespace in the future. Use an array with a string "
    410         "or bytes dtype instead.", DeprecationWarning, stacklevel=2)

AttributeError: `np.obj2sctype` was removed in the NumPy 2.0 release. Use `np.dtype(obj).type` instead.

PyMC version information:

pip install pymc
versions:
pymc-5.15.0
numpy-2.1.3

Context for the issue:

No response

@mauhcs mauhcs added the bug label Nov 27, 2024
Copy link

welcome bot commented Nov 27, 2024

Welcome Banner]
🎉 Welcome to PyMC! 🎉 We're really excited to have your input into the project! 💖

If you haven't done so already, please make sure you check out our Contributing Guidelines and Code of Conduct.

@mauhcs
Copy link
Author

mauhcs commented Nov 27, 2024

I forced installed pymc version 5.18.2 with pip install pymc==5.18.2 and the problem went away

@mauhcs mauhcs closed this as completed Nov 27, 2024
@mauhcs mauhcs reopened this Nov 27, 2024
@mauhcs
Copy link
Author

mauhcs commented Nov 27, 2024

Sorry,
I am reopening because I just realised that the installation with pip install pymc==5.18.2 changed my numpy to version 1.26.4

@mauhcs mauhcs changed the title BUG: Not wirking with numpy 2 (np.obj2sctype was removed in the NumPy 2.0 release.) BUG: Not working with numpy 2 (np.obj2sctype was removed in the NumPy 2.0 release.) Nov 27, 2024
@ricardoV94
Copy link
Member

@mauhcs pymc is not compatible with numpy 2.0, due to PyTensor not being compatible with it. Relevant issue to track: pymc-devs/pytensor#688

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants