Serialization

metatensor.torch.save(path: str, data: TensorMap | Labels)[source]

Save the given data (either TensorMap or Labels) to the given file at the given path.

If the file already exists, it is overwritten. When saving a TensorMap, the file extension should be .npz; and when saving Labels it should be .npy

Parameters:
  • path (str) – path of the file where to save the data

  • data (TensorMap | Labels) – data to serialize and save

metatensor.torch.save_buffer(data: TensorMap | Labels) Tensor[source]

Save the given data (either TensorMap or Labels) to an in-memory buffer, represented as 1-dimensional torch.Tensor of uint8.

Parameters:

data (TensorMap | Labels) – data to serialize and save

Return type:

Tensor

metatensor.torch.load(path: str) TensorMap[source]

Load a previously saved TensorMap from the given path.

TensorMap are serialized using numpy’s .npz format, i.e. a ZIP file without compression (storage method is STORED), where each file is stored as a .npy array. See the C API documentation for more information on the format.

Parameters:

path (str) – path of the file to load

Return type:

TensorMap

metatensor.torch.load_block(path: str) TensorBlock[source]

Load previously saved TensorBlock from the given file.

Parameters:

path (str) – path of the file to load

Return type:

TensorBlock

metatensor.torch.load_labels(path: str) Labels[source]

Load previously saved Labels from the given file.

Parameters:

path (str) – path of the file to load

Return type:

Labels

metatensor.torch.load_buffer(buffer: Tensor) TensorMap[source]

Load a previously saved TensorMap from an in-memory buffer, stored inside a 1-dimensional torch.Tensor of uint8.

Parameters:

buffer (Tensor) – CPU tensor of uint8 representing a in-memory buffer

Return type:

TensorMap

metatensor.torch.load_block_buffer(buffer: Tensor) TensorBlock[source]

Load a previously saved TensorBlock from an in-memory buffer, stored inside a 1-dimensional torch.Tensor of uint8.

Parameters:

buffer (Tensor) – CPU tensor of uint8 representing a in-memory buffer

Return type:

TensorBlock

metatensor.torch.load_labels_buffer(buffer: Tensor) Labels[source]

Load a previously saved Labels from an in-memory buffer, stored inside a 1-dimensional torch.Tensor of uint8.

Parameters:

buffer (Tensor) – CPU tensor of uint8 representing a in-memory buffer

Return type:

Labels