the-virtual-brain / tvb-root

Main TVB codebase
https://thevirtualbrain.org
Other
122 stars 105 forks source link

Incompatibility with Numpy 2.0 #726

Open thorstenhater opened 1 month ago

thorstenhater commented 1 month ago

I cannot import tvb in an environment with numpy>=2.0 installed due the use of a removed function. However, tvb does not require numpy<2.0

Describe the bug

See above.

Steps to reproduce

✔❯ pip install numpy==2.0 tvb-library
✘❯  python3 -c 'import tvb.simulator.lab'
/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/datatypes/surfaces.py:60: UserWarning: Geodesic distance module is unavailable; some functionality for surfaces will be unavailable.
  warnings.warn(msg)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/simulator/lab.py", line 55, in <module>
    from tvb.simulator import (simulator, models, coupling, integrators, monitors, noise)
  File "/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/simulator/simulator.py", line 44, in <module>
    from tvb.datatypes import cortex, connectivity, patterns
  File "/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/datatypes/cortex.py", line 30, in <module>
    from tvb.datatypes import local_connectivity, region_mapping, surfaces
  File "/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/datatypes/local_connectivity.py", line 33, in <module>
    from tvb.datatypes import equations, surfaces
  File "/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/datatypes/surfaces.py", line 99, in <module>
    class Surface(HasTraits):
  File "/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/basic/neotraits/_declarative_base.py", line 228, in __new__
    v._post_bind_validate()
  File "/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/basic/neotraits/_attr.py", line 349, in _post_bind_validate
    super(Int, self)._post_bind_validate()
  File "/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/basic/neotraits/_attr.py", line 309, in _post_bind_validate
    self.__validate(self.default)
  File "/Users/hater/src/models/arbor-epilepsy/.direnv/python-3.12/lib/python3.12/site-packages/tvb/basic/neotraits/_attr.py", line 301, in __validate
    if not numpy.can_cast(value, self.field_type, 'safe'):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can_cast() does not support Python ints, floats, and complex because the result used to depend on the value.
This change was part of adopting NEP 50, we may explicitly allow them again in the future.

Expected results

No error.

Actual results

See above.

Additional information

✔❯  pip list | rg tvb
tvb-contrib               2.9
tvb-data                  2.0
tvb-library               2.9
liadomide commented 2 weeks ago

Thanks for pointing this issue. We marked in the latest release tvb-library==2.9.1 the requirement to have numpy<2.0 for now. We will look into numpy 2.0 compatibility sometime in the future (unfortunately I can not say more exactly when).