PythonOT/POT

Incompatibility with numpy 2.0

Closed this issue · 2 comments

Describe the bug

pot cannot be imported in an environment where numpy 2.0 is installed.

To Reproduce

Steps to reproduce the behavior:

  1. In a clean environment, install the latest version of numpy (2.0.0) and of pot (0.9.3)
  2. import pot in a python file
  3. The following error should show up

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last): File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "c:\venv\Lib\site-packages\ipykernel_launcher.py", line 18, in
app.launch_new_instance()
File "c:\venv\Lib\site-packages\traitlets\config\application.py", line 1075, in launch_instance
app.start()
File "c:\venv\Lib\site-packages\ipykernel\kernelapp.py", line 739, in start
self.io_loop.start()
File "c:\venv\Lib\site-packages\tornado\platform\asyncio.py", line 205, in start
self.asyncio_loop.run_forever()
File "C:\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 641, in run_forever
self._run_once()
File "C:\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 1987, in _run_once
handle._run()
File "C:\Local\Programs\Python\Python312\Lib\asyncio\events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "c:\project\Lib\site-packages\ipykernel\kernelbase.py", line 545, in dispatch_queue
await self.process_one()
File "c:\venv\Lib\site-packages\ipykernel\kernelbase.py", line 534, in process_one
await dispatch(*args)
File "c:\venv\Lib\site-packages\ipykernel\kernelbase.py", line 437, in dispatch_shell
await result
File "c:\venv\Lib\site-packages\ipykernel\ipkernel.py", line 362, in execute_request
await super().execute_request(stream, ident, parent)
File "c:\venv\Lib\site-packages\ipykernel\kernelbase.py", line 778, in execute_request
reply_content = await reply_content
File "c:\venv\Lib\site-packages\ipykernel\ipkernel.py", line 449, in do_execute
res = shell.run_cell(
File "c:\venv\Lib\site-packages\ipykernel\zmqshell.py", line 549, in run_cell
return super().run_cell(*args, **kwargs)
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3075, in run_cell
result = self.run_cell(
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3130, in run_cell
result = runner(coro)
File "c:\venv\Lib\site-packages\IPython\core\async_helpers.py", line 129, in pseudo_sync_runner
coro.send(None)
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3334, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3517, in run_ast_nodes
if await self.run_code(code, result, async
=asy):
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3577, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "C:\Local\Temp\ipykernel_15256\4029766171.py", line 2, in
import ot
File "c:\venv\Lib\site-packages\ot_init
.py", line 21, in
from . import lp
File "c:\venv\Lib\site-packages\ot\lp_init
.py", line 23, in
from .emd_wrap import emd_c, check_result, emd_1d_sorted

Code sample

import ot

Expected behavior

The package should load properly

Environment (please complete the following information):

  • Tested on both Windows and Linux:
  • Python version: 3.12.3
  • How was POT installed (source, pip, conda): pip
  • Build command you used (if compiling from source): NA
  • Only for GPU related bugs:
    • CUDA version:
    • GPU models and configuration:
    • Any other relevant information:

Output of the following code snippet:

import platform; print(platform.platform())
import sys; print("Python", sys.version)
import numpy; print("NumPy", numpy.__version__)
import scipy; print("SciPy", scipy.__version__)
import ot; print("POT", ot.__version__)

Windows-10-10.0.19045-SP0
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]
NumPy 2.0.0
SciPy 1.13.1

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last): File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "c:\venv\Lib\site-packages\ipykernel_launcher.py", line 18, in
app.launch_new_instance()
File "c:\venv\Lib\site-packages\traitlets\config\application.py", line 1075, in launch_instance
app.start()
File "c:\venv\Lib\site-packages\ipykernel\kernelapp.py", line 739, in start
self.io_loop.start()
File "c:\venv\Lib\site-packages\tornado\platform\asyncio.py", line 205, in start
self.asyncio_loop.run_forever()
File "C:\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 641, in run_forever
self._run_once()
File "C:\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 1987, in _run_once
handle._run()
File "C:\Local\Programs\Python\Python312\Lib\asyncio\events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "c:\project\Lib\site-packages\ipykernel\kernelbase.py", line 545, in dispatch_queue
await self.process_one()
File "c:\venv\Lib\site-packages\ipykernel\kernelbase.py", line 534, in process_one
await dispatch(*args)
File "c:\venv\Lib\site-packages\ipykernel\kernelbase.py", line 437, in dispatch_shell
await result
File "c:\venv\Lib\site-packages\ipykernel\ipkernel.py", line 362, in execute_request
await super().execute_request(stream, ident, parent)
File "c:\venv\Lib\site-packages\ipykernel\kernelbase.py", line 778, in execute_request
reply_content = await reply_content
File "c:\venv\Lib\site-packages\ipykernel\ipkernel.py", line 449, in do_execute
res = shell.run_cell(
File "c:\venv\Lib\site-packages\ipykernel\zmqshell.py", line 549, in run_cell
return super().run_cell(*args, **kwargs)
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3075, in run_cell
result = self.run_cell(
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3130, in run_cell
result = runner(coro)
File "c:\venv\Lib\site-packages\IPython\core\async_helpers.py", line 129, in pseudo_sync_runner
coro.send(None)
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3334, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3517, in run_ast_nodes
if await self.run_code(code, result, async
=asy):
File "c:\venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3577, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "C:\Local\Temp\ipykernel_15256\4029766171.py", line 2, in
import ot
File "c:\venv\Lib\site-packages\ot_init
.py", line 21, in
from . import lp
File "c:\venv\Lib\site-packages\ot\lp_init
.py", line 23, in
from .emd_wrap import emd_c, check_result, emd_1d_sorted

Hello @XLoizeau ,
We will soon release a new version of POT that deals with this recent numpy upgrade, see PR #640

Best,
Cédric

Hello @cedricvincentcuaz ,
Thank you for your answer. Apologies for this issue then. I had checked the open issues but not the merge requests! That is great news, thank you.
Best,
Zhav