markovmodel / PyEMMA

🚂 Python API for Emma's Markov Model Algorithms 🚂
http://pyemma.org
GNU Lesser General Public License v3.0
306 stars 119 forks source link

Minor issue with newest numpy version #1589

Open pitmanme opened 1 year ago

pitmanme commented 1 year ago

PyEMMA appears to not be compatible with the most recent NumPy version. I detail the version related bug I ran into below and a quick fix I implemented on my installation of PyEMMA so that I didn't have to backtrack my NumPy installation.

Here is the Traceback :

  File "/Users/mpitman/work/rfe/pca_background/pca/tica.py", line 33, in <module>
    tica_obj = coor.tica(inp, lag=lag, dim=2, kinetic_map=False)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/util/annotators.py", line 218, in _deprecated
    return func(*args, **kw)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/coordinates/api.py", line 1287, in tica
    res.estimate(data, chunksize=cs)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/coordinates/transform/tica.py", line 163, in estimate
    return super(TICA, self).estimate(X, **kwargs)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/coordinates/data/_base/transformer.py", line 215, in estimate
    super(StreamingEstimationTransformer, self).estimate(X, **kwargs)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/coordinates/data/_base/streaming_estimator.py", line 44, in estimate
    super(StreamingEstimator, self).estimate(X, **kwargs)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/_base/estimator.py", line 418, in estimate
    self._model = self._estimate(X)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/coordinates/transform/tica.py", line 210, in _estimate
    covar.estimate(iterable, chunksize=self.chunksize, **kw)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/coordinates/data/_base/streaming_estimator.py", line 44, in estimate
    super(StreamingEstimator, self).estimate(X, **kwargs)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/_base/estimator.py", line 418, in estimate
    self._model = self._estimate(X)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/coordinates/estimation/covariance.py", line 240, in _estimate
    self._rc.add(X, Y, weights=weight)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/_ext/variational/estimators/running_moments.py", line 279, in add
    w, s_X, s_Y, C_XX, C_XY = moments_XXXY(X, Y, remove_mean=self.remove_mean, symmetrize=self.symmetrize,
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/_ext/variational/estimators/moments.py", line 785, in moments_XXXY
    X0, mask_X, xconst, Y0, mask_Y, yconst = _sparsify_pair(X, Y, remove_mean=remove_mean, modify_data=modify_data,
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/_ext/variational/estimators/moments.py", line 170, in _sparsify_pair
    X0, mask_X, xconst = _sparsify(X, sparse_mode=sparse_mode, sparse_tol=sparse_tol)
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/_ext/variational/estimators/moments.py", line 149, in _sparsify
    mask = covartools.variable_cols(X, tol=sparse_tol, min_constant=min_const_col_number)  # bool vector
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/pyemma/_ext/variational/estimators/covar_c/covartools.py", line 37, in variable_cols
    cols = numpy.zeros(X.shape[1], dtype=numpy.bool, order='C')
  File "/opt/miniconda3/envs/mdtools/lib/python3.9/site-packages/numpy/__init__.py", line 284, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'bool'

This is with the newest numpy version >>> numpy.__version__ '1.24.1'

The environment file is attached (env.txt) for pyemma version 2.5.12 ran on OS X v. 11.4 (Big Sur).

Minimal example

Get the trj file and structure file:

wget http://www3.mpibpc.mpg.de/groups/de_groot/compbio1/p4/md1_backbone.xtc
wget http://www3.mpibpc.mpg.de/groups/de_groot/compbio1/p4/ref.pdb
echo 0 | gmx trjconv -s ref.pdb -f md1_backbone.xtc -o md1.pdb -e 1000

Produce error:

import pyemma
import pyemma.coordinates as coor

struc = '../md1.pdb'
trj = '../md1_backbone.xtc'

# The trajectory needs to be RMSD aligned already.
feat = coor.featurizer(struc)
feat.add_all()

# Load trajectory.
inp = coor.source(trj, features=feat)

# Do the time-lagged independent component analysis (TICA)
lag = 100
tica_obj = coor.tica(inp, lag=lag, dim=2, kinetic_map=False)

Potential solution:

I edited my installation of covartools.py to replace numpy.bool with numpy.bool_ and that resolved the issue. I believe you can use the standard python bool as well. Alternatively, you could pin the numpy version in the conda install to not allow more recent numpy versions.

env.txt

acadiaconnor commented 1 year ago

@pitmanme I am having the same error but running within a .coordinantes.tica in my Jupyter notebook. I have tried uninstalling and reinstalling early version of numpy, with no success. Your solution worked for me! Thank you.

pitmanme commented 1 year ago

@acadiaconnor if you end up having other issues (I'm not using many of the functions from pyemma) you might double check which numpy loads into your Jupyter notebook.

clonker commented 1 year ago

Depending on what you try to do, you can also have a look at deeptime. That one is still being somewhat maintained and should be compatible to newest bumpy versions :)

slieped commented 1 year ago

Just came here to report the same issue.

In my case it was related to vamp, and I solve it downgrading to numpy 1.23.5 version (vs the 1.24 I was originaly using)

clonker commented 1 year ago

If you have a working version you could also make a PR, i'm happy to review and merge it, just don't have the time right now to do any active development (new job and all...)