Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When loading tensor map that requires use_numpy=True the error message is unclear #469

Closed
agoscinski opened this issue Feb 1, 2024 · 1 comment · Fixed by #671
Closed
Labels
core Related to the core implementation, in Rust

Comments

@agoscinski
Copy link
Contributor

When I load the tensor map

In [1]: import metatensor
In [2]: metatensor.load("./python/metatensor-operations/tests/data/qm7-power-spectrum.npz")
---------------------------------------------------------------------------
MetatensorError                           Traceback (most recent call last)
Cell In[2], line 1
----> 1 metatensor.load("./python/metatensor-operations/tests/data/qm7-power-spectrum.npz")

File /opt/anaconda3/envs/metatensor-dev/lib/python3.11/site-packages/metatensor/io.py:72, in load(file, use_numpy)
     70 else:
     71     if isinstance(file, (str, pathlib.Path)):
---> 72         return load_custom_array(file, create_numpy_array)
     73     else:
     74         # assume we have a file-like object
     75         buffer = file.read()

File /opt/anaconda3/envs/metatensor-dev/lib/python3.11/site-packages/metatensor/io.py:118, in load_custom_array(path, create_array)
    114     path = bytes(path)
    116 ptr = lib.mts_tensormap_load(path, mts_create_array_callback_t(create_array))
--> 118 return TensorMap._from_ptr(ptr)

File /opt/anaconda3/envs/metatensor-dev/lib/python3.11/site-packages/metatensor/tensor.py:121, in TensorMap._from_ptr(ptr)
    118 @staticmethod
    119 def _from_ptr(ptr):
    120     """Create a tensor map from a pointer owning its data"""
--> 121     _check_pointer(ptr)
    122     obj = TensorMap.__new__(TensorMap)
    123     obj._lib = _get_library()

File /opt/anaconda3/envs/metatensor-dev/lib/python3.11/site-packages/metatensor/status.py:48, in _check_pointer(pointer)
     46     raise MetatensorError(last_error()) from e
     47 else:
---> 48     raise MetatensorError(last_error())

MetatensorError: serialization format error: unsupported Zip archive: Compression method not supported: at 'keys.npy'

Correct usage

metatensor.load("./python/metatensor-operations/tests/data/qm7-power-spectrum.npz", use_numpy=True)

But I cannot understand from the first error message that this is the issue. I am not sure what the right solution would be, but anything would help. For example, checking the file ending and add something to the error message if npz is identified (or just always add this to the message). Or if this fails trying to also load it with use_numpy option to give user more informative error message.

@Luthaf
Copy link
Contributor

Luthaf commented Feb 1, 2024

Right. I think the best solution is to add support for DEFLATE storage in the non-numpy implementation. We currently only support STORED (which should enable memory-mapping), but giving both options would be good!

@Luthaf Luthaf added the core Related to the core implementation, in Rust label Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the core implementation, in Rust
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants