qmlcode / qml

QML: Quantum Machine Learning
MIT License
199 stars 84 forks source link

Incompatibiliy numpy & get_slatm_mbtypes #151

Open Mi-chael opened 2 months ago

Mi-chael commented 2 months ago

When calling get_slatm_mbtypes, the following error appears:

File "test_qml.py", line 12, in <module>
    mbtypes = get_slatm_mbtypes([nuclear_charges])
  File "/home/deffner/.local/lib/python3.8/site-packages/qml/representations.py", line 340, in get_slatm_mbtypes
    zsi = np.array(zs[i],np.int)
  File "/home/deffner/.local/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
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

This was caused by this code:

import numpy as np
from qml.representations import get_slatm_mbtypes

coordinates = np.array([[1.464, 0.707, 1.056],
                        [0.878, 1.218, 0.498],
                        [2.319, 1.126, 0.952]])

nuclear_charges = np.array([8, 1, 1])
mbtypes = get_slatm_mbtypes([nuclear_charges])

I've numpy 1.24.4 and qml 0.4.0.27, installed via pip under ubuntu 20.04.6 LTS.

According to the error message, one should be able to fix it with just a small change: zsi = np.array(zs[i],np.int) to zsi = np.array(zs[i], int)

charnley commented 2 months ago

Hi @Mi-chael, qml is currently being applied some spring cleaning, and will be moved over to https://github.com/qmlcode/qmllib . A version will be published in Sep, which also solves the above problem, and will be numpy 2.0 compatible.