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

theano compatibility issue with numpy>1.20? #104

Open
shadden opened this issue Jan 31, 2024 · 6 comments
Open

theano compatibility issue with numpy>1.20? #104

shadden opened this issue Jan 31, 2024 · 6 comments

Comments

@shadden
Copy link

shadden commented Jan 31, 2024

Attempting to import the pymc3 ops causes an error that appears to be related to theano compatibility issues with newer numpy versions. specifically,

from exoplanet_core.pymc3 import ops

leads to the error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/0y/0wb96bc544s1wvz3qvx484qh0000gn/T/ipykernel_62450/835514745.py in <module>
----> 1 from exoplanet_core.pymc3 import ops

~/anaconda/envs/celmech/lib/python3.9/site-packages/exoplanet_core/pymc3/__init__.py in <module>
     20 
     21 
---> 22 __set_compiler_flags()
     23 
     24 

~/anaconda/envs/celmech/lib/python3.9/site-packages/exoplanet_core/pymc3/__init__.py in __set_compiler_flags()
      5 
      6 def __set_compiler_flags():
----> 7     import theano
      8 
      9     def add_flag(current, new):

~/anaconda/envs/celmech/lib/python3.9/site-packages/Theano-1.0.5-py3.9.egg/theano/__init__.py in <module>
    122 from theano.printing import pprint, pp
    123 
--> 124 from theano.scan_module import (scan, map, reduce, foldl, foldr, clone,
    125                                 scan_checkpoints)
    126 

~/anaconda/envs/celmech/lib/python3.9/site-packages/Theano-1.0.5-py3.9.egg/theano/scan_module/__init__.py in <module>
     39 __contact__ = "Razvan Pascanu <r.pascanu@gmail>"
     40 
---> 41 from theano.scan_module import scan_opt
     42 from theano.scan_module.scan import scan
     43 from theano.scan_module.scan_checkpoints import scan_checkpoints

~/anaconda/envs/celmech/lib/python3.9/site-packages/Theano-1.0.5-py3.9.egg/theano/scan_module/scan_opt.py in <module>
     58 
     59 import theano
---> 60 from theano import tensor, scalar
     61 from theano.tensor import opt, get_scalar_constant_value, Alloc, AllocEmpty
     62 from theano import gof

~/anaconda/envs/celmech/lib/python3.9/site-packages/Theano-1.0.5-py3.9.egg/theano/tensor/__init__.py in <module>
      6 import warnings
      7 
----> 8 from theano.tensor.basic import *
      9 from theano.tensor.subtensor import *
     10 from theano.tensor.type_other import *

~/anaconda/envs/celmech/lib/python3.9/site-packages/Theano-1.0.5-py3.9.egg/theano/tensor/basic.py in <module>
     18 from theano.gof.type import Generic
     19 
---> 20 from theano.scalar import int32 as int32_t
     21 from theano.tensor import elemwise
     22 from theano.tensor.var import (AsTensorError, TensorVariable,

~/anaconda/envs/celmech/lib/python3.9/site-packages/Theano-1.0.5-py3.9.egg/theano/scalar/__init__.py in <module>
      1 from __future__ import absolute_import, print_function, division
      2 
----> 3 from .basic import *
      4 
      5 from .basic_scipy import *

~/anaconda/envs/celmech/lib/python3.9/site-packages/Theano-1.0.5-py3.9.egg/theano/scalar/basic.py in <module>
   2368             return s
   2369 
-> 2370 convert_to_bool = Cast(bool, name='convert_to_bool')
   2371 convert_to_int8 = Cast(int8, name='convert_to_int8')
   2372 convert_to_int16 = Cast(int16, name='convert_to_int16')

~/anaconda/envs/celmech/lib/python3.9/site-packages/Theano-1.0.5-py3.9.egg/theano/scalar/basic.py in __init__(self, o_type, name)
   2321         super(Cast, self).__init__(specific_out(o_type), name=name)
   2322         self.o_type = o_type
-> 2323         self.ctor = getattr(np, o_type.dtype)
   2324 
   2325     def __str__(self):

~/anaconda/envs/celmech/lib/python3.9/site-packages/numpy/__init__.py in __getattr__(attr)
    322 
    323         if attr in __former_attrs__:
--> 324             raise AttributeError(__former_attrs__[attr])
    325 
    326         if attr == 'testing':

AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
@dfm
Copy link
Member

dfm commented Jan 31, 2024

Thanks for raising this @shadden! This incompatibility is known (albeit annoying) and we handle it here by restricting the numpy version <1.22 for the PyMC3 extension:

"pymc3": ["pymc3>=3.9", "numpy<1.22"],

There's not much we can do about this since Theano is long deprecated and a full overhaul of that code base is beyond my capabilities!

Your options include:

  1. Restricting the numpy version like we do here (and like we do in exoplanet), or
  2. Switch to one of the other interfaces (PyMC v5 or JAX).

In my work I've completely switched to JAX, but the PyMC (v5) interface will probably be the most backwards compatible. One note: to get PyMC support you'll need to install the release candidate from PyPI (pip install exoplanet-core==0.3.0rc2), but this reminds me that I really need to do a proper v0.3.0 release!

@shadden
Copy link
Author

shadden commented Jan 31, 2024

Thanks! Sounds like a headache-- I'm mainly just interested in having an implementation of a differentiable Kepler solver. I was hoping for a solution that basically amounted to finding and replacing instances of 'theano' with something like 'aesara' or 'pytensor' or something similar in the code here. However, if JAX is really the way of the future, maybe I should bite the bullet and go with a major overhaul...

@dfm
Copy link
Member

dfm commented Jan 31, 2024

I expect that your lowest barrier change here would be to change theano to pytensor and switch to pymc.ops from here.

Pinging @vandalt who did all the hard work of updating this repo with pymc support. Any tips for @shadden?

@dfm
Copy link
Member

dfm commented Jan 31, 2024

Also: I prefer JAX, but I do think that PyMC/PyTensor seem to be well maintained, and I don't think it would be a mistake to go down that path!

@shadden
Copy link
Author

shadden commented Feb 1, 2024

I've managed a solution for my particular problems by swapping out theano for pytensor as suggested. I've made exoplanet-core==0.3.0rc2 a celmech dependency for now (I'm not really sure how "release candidates" play with version requirements, e.g., if I made exoplanet-core>=0.3.0 a requirement would it work?). I'll keep an eye out for the next release. Thanks for the help!

@vandalt
Copy link
Contributor

vandalt commented Mar 9, 2024

Hi @shadden! Sorry for the delay. I think swapping theano for pytensor is the way to go (and then fix the incompatibilities if there are any). Also, @dfm released exoplanet-core v0.3.0 earlier this week, so making exoplanet-core>=0.3.0 would definitely work now!

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

No branches or pull requests

3 participants