MannLabs / alphapeptdeep

Deep learning framework for proteomics
Apache License 2.0
105 stars 20 forks source link

peptdeep 1.2.1 not compatible with numpy 2.0.1 #190

Open xgwang-uw opened 1 month ago

xgwang-uw commented 1 month ago

Description peptdeep library command failing with error:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.1 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 "multiprocessing\pool.py", line 125, in worker
  File "C:\Users\Jason\workspaces\pwiz\pwiz_tools\Skyline\bin\x64\Debug\Tools\Python\3.12.4\alphapeptdeep\Lib\site-packages\peptdeep\pretrained_models.py", line 936, in _predict_func_for_mp
    return self.predict_all(
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\Jason\workspaces\pwiz\pwiz_tools\Skyline\bin\x64\Debug\Tools\Python\3.12.4\alphapeptdeep\Lib\site-packages\peptdeep\pretrained_models.py", line 1112, in predict_all
    self.predict_rt(precursor_df,
  File "C:\Users\Jason\workspaces\pwiz\pwiz_tools\Skyline\bin\x64\Debug\Tools\Python\3.12.4\alphapeptdeep\Lib\site-packages\peptdeep\pretrained_models.py", line 898, in predict_rt
    df = self.rt_model.predict(precursor_df,
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Jason\workspaces\pwiz\pwiz_tools\Skyline\bin\x64\Debug\Tools\Python\3.12.4\alphapeptdeep\Lib\site-packages\peptdeep\model\model_interface.py", line 548, in predict
    predicts = self._predict_one_batch(*features)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Jason\workspaces\pwiz\pwiz_tools\Skyline\bin\x64\Debug\Tools\Python\3.12.4\alphapeptdeep\Lib\site-packages\peptdeep\model\model_interface.py", line 855, in _predict_one_batch
    ).cpu().detach().numpy()
                     ^^^^^^^
RuntimeError: Numpy is not available

To Reproduce Steps to reproduce the behavior:

  1. In terminal, run pip install peptdeep
  2. With a prepared alphapeptdeep settings.yaml file, run <path-to>\peptdeep.exe library <path-to>\settings.yaml

Workaround Downgrading numpy to 1.26.4 gets rid of this issue. This can be considered a workaround.

Expected behavior Successfully predict a spectral library and output a predict.speclib.hdf file.

Logs peptdeep_library.log

Version (please complete the following information):

Additional context This issue is due to a known pytorch and numpy compatability issue: https://github.com/pytorch/pytorch/issues/107302. Specifically, the .numpy() method stopped working in pytorch (for numpy 2.0).

Although the issue claimed to have the numpy backward compatibility added after pytorch 2.2, and the issue is already closed, there are still reports of the same issue very recently (eg1, eg2). Plus there is a similar issue still open with the same failure in Windows (eg3).

As we wait for the pytorch fix, I suggest to add numpy < 2.0 to the requirement.txt file, to bake the workaround into the stable version of peptdeep package, so that users don't experience the error with the peptdeep CLI.

jalew188 commented 1 month ago

Yes, this is because some of dependent packages are not compiled by numpy2 yet. I have add numpy<2 in the requirement.txt in the latest development branch

jalew188 commented 1 month ago

Tested on #193, fixed by the stable installation