metatensor-learn 0.3.2__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0}/AUTHORS +1 -0
- {metatensor_learn-0.3.2/metatensor_learn.egg-info → metatensor_learn-0.5.0}/PKG-INFO +5 -4
- metatensor_learn-0.5.0/git_version_info +2 -0
- {metatensor_learn-0.3.2/metatensor/learn → metatensor_learn-0.5.0/metatensor_learn}/__init__.py +6 -1
- {metatensor_learn-0.3.2/metatensor/learn → metatensor_learn-0.5.0/metatensor_learn}/_backend.py +4 -0
- metatensor_learn-0.5.0/metatensor_learn/data/__init__.py +12 -0
- metatensor_learn-0.3.2/metatensor/learn/data/collate.py → metatensor_learn-0.5.0/metatensor_learn/data/_collate.py +9 -7
- metatensor_learn-0.3.2/metatensor/learn/data/dataloader.py → metatensor_learn-0.5.0/metatensor_learn/data/_dataloader.py +1 -1
- {metatensor_learn-0.3.2/metatensor/learn → metatensor_learn-0.5.0/metatensor_learn}/data/_namedtuple.py +1 -1
- metatensor_learn-0.5.0/metatensor_learn/nn/__init__.py +9 -0
- metatensor_learn-0.3.2/metatensor/learn/nn/equivariant_transformation.py → metatensor_learn-0.5.0/metatensor_learn/nn/_equivariant.py +11 -11
- metatensor_learn-0.3.2/metatensor/learn/nn/layer_norm.py → metatensor_learn-0.5.0/metatensor_learn/nn/_layer_norm.py +10 -11
- metatensor_learn-0.3.2/metatensor/learn/nn/linear.py → metatensor_learn-0.5.0/metatensor_learn/nn/_linear.py +6 -6
- metatensor_learn-0.5.0/metatensor_learn/nn/_module.py +410 -0
- metatensor_learn-0.3.2/metatensor/learn/nn/module_map.py → metatensor_learn-0.5.0/metatensor_learn/nn/_module_map.py +30 -76
- metatensor_learn-0.3.2/metatensor/learn/nn/relu.py → metatensor_learn-0.5.0/metatensor_learn/nn/_relu.py +7 -7
- metatensor_learn-0.3.2/metatensor/learn/nn/sequential.py → metatensor_learn-0.5.0/metatensor_learn/nn/_sequential.py +5 -3
- metatensor_learn-0.3.2/metatensor/learn/nn/silu.py → metatensor_learn-0.5.0/metatensor_learn/nn/_silu.py +7 -7
- metatensor_learn-0.3.2/metatensor/learn/nn/tanh.py → metatensor_learn-0.5.0/metatensor_learn/nn/_tanh.py +7 -7
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0/metatensor_learn.egg-info}/PKG-INFO +5 -4
- metatensor_learn-0.5.0/metatensor_learn.egg-info/SOURCES.txt +33 -0
- metatensor_learn-0.5.0/metatensor_learn.egg-info/requires.txt +2 -0
- metatensor_learn-0.5.0/metatensor_learn.egg-info/top_level.txt +1 -0
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0}/pyproject.toml +8 -5
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0}/setup.py +23 -21
- metatensor_learn-0.3.2/git_version_info +0 -2
- metatensor_learn-0.3.2/metatensor/learn/data/__init__.py +0 -12
- metatensor_learn-0.3.2/metatensor/learn/nn/__init__.py +0 -8
- metatensor_learn-0.3.2/metatensor_learn.egg-info/SOURCES.txt +0 -32
- metatensor_learn-0.3.2/metatensor_learn.egg-info/requires.txt +0 -1
- metatensor_learn-0.3.2/metatensor_learn.egg-info/top_level.txt +0 -1
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0}/LICENSE +0 -0
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0}/MANIFEST.in +0 -0
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0}/README.rst +0 -0
- {metatensor_learn-0.3.2/metatensor/learn → metatensor_learn-0.5.0/metatensor_learn}/_dispatch.py +0 -0
- /metatensor_learn-0.3.2/metatensor/learn/data/dataset.py → /metatensor_learn-0.5.0/metatensor_learn/data/_dataset.py +0 -0
- {metatensor_learn-0.3.2/metatensor/learn → metatensor_learn-0.5.0/metatensor_learn}/nn/_utils.py +0 -0
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0}/metatensor_learn.egg-info/dependency_links.txt +0 -0
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0}/metatensor_learn.egg-info/zip-safe +0 -0
- {metatensor_learn-0.3.2 → metatensor_learn-0.5.0}/setup.cfg +0 -0
- /metatensor_learn-0.3.2/tests/test_dummmy.py → /metatensor_learn-0.5.0/tests/test_dummy.py +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: metatensor-learn
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Building blocks for the atomistic machine learning models based on PyTorch and NumPy
|
|
5
|
-
Author: Guillaume Fraux, Philip Loche, Filippo Bigi, Joseph W. Abbott, Davide Tisi, Alexander Goscinski, Michele Ceriotti
|
|
5
|
+
Author: Guillaume Fraux, Rohit Goswami, Philip Loche, Filippo Bigi, Joseph W. Abbott, Davide Tisi, Alexander Goscinski, Michele Ceriotti
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
7
7
|
Project-URL: homepage, https://docs.metatensor.org/latest/
|
|
8
8
|
Project-URL: documentation, https://docs.metatensor.org/latest/
|
|
@@ -22,11 +22,12 @@ Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
|
22
22
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
23
23
|
Classifier: Topic :: Software Development :: Libraries
|
|
24
24
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
-
Requires-Python: >=3.
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
26
|
Description-Content-Type: text/x-rst
|
|
27
27
|
License-File: LICENSE
|
|
28
28
|
License-File: AUTHORS
|
|
29
|
-
Requires-Dist: metatensor-operations<0.
|
|
29
|
+
Requires-Dist: metatensor-operations<0.6,>=0.5.0
|
|
30
|
+
Requires-Dist: metatensor-core<0.3,>=0.2.0
|
|
30
31
|
Dynamic: author
|
|
31
32
|
Dynamic: license-file
|
|
32
33
|
Dynamic: requires-dist
|
{metatensor_learn-0.3.2/metatensor/learn → metatensor_learn-0.5.0/metatensor_learn}/__init__.py
RENAMED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import importlib.metadata
|
|
2
|
+
import sys
|
|
2
3
|
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
sys.modules["metatensor.learn"] = sys.modules[__name__]
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
try:
|
|
7
9
|
import torch # noqa
|
|
@@ -15,3 +17,6 @@ if HAS_TORCH:
|
|
|
15
17
|
from . import data, nn # noqa: F401
|
|
16
18
|
from .data import DataLoader, Dataset, IndexedDataset # noqa: F401
|
|
17
19
|
from .nn import Linear, ModuleMap # noqa: F401
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
__version__ = importlib.metadata.version("metatensor-learn")
|
{metatensor_learn-0.3.2/metatensor/learn → metatensor_learn-0.5.0/metatensor_learn}/_backend.py
RENAMED
|
@@ -43,6 +43,10 @@ def _version_at_least(version, expected):
|
|
|
43
43
|
return version >= expected
|
|
44
44
|
|
|
45
45
|
|
|
46
|
+
# Warning: this function (as all functions in this module) is part of the public API of
|
|
47
|
+
# metatensor-learn, updating it means that new versions of metatensor-torch will not be
|
|
48
|
+
# able to work with old versions of metatensor-learn, so any update should be treated as
|
|
49
|
+
# a breaking change.
|
|
46
50
|
def isinstance_metatensor(value, typename):
|
|
47
51
|
assert typename in ("Labels", "TensorBlock", "TensorMap")
|
|
48
52
|
|
|
@@ -31,7 +31,7 @@ def group(batch: List[NamedTuple]) -> NamedTuple:
|
|
|
31
31
|
:return: a named tuple, with the named fields the same as in the original
|
|
32
32
|
samples in the batch, but with the samples grouped by data field.
|
|
33
33
|
"""
|
|
34
|
-
return namedtuple("Batch", batch[0]._fields)(*list(zip(*batch)))
|
|
34
|
+
return namedtuple("Batch", batch[0]._fields)(*list(zip(*batch, strict=True)))
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
def group_and_join(
|
|
@@ -87,20 +87,22 @@ def group_and_join(
|
|
|
87
87
|
fields_to_join = names
|
|
88
88
|
if join_kwargs is None:
|
|
89
89
|
join_kwargs = {}
|
|
90
|
-
for name, field in zip(names, list(zip(*batch))):
|
|
90
|
+
for name, field in zip(names, list(zip(*batch, strict=True)), strict=True):
|
|
91
91
|
if name == "sample_id": # special case, keep as is
|
|
92
92
|
data.append(field)
|
|
93
93
|
continue
|
|
94
94
|
|
|
95
95
|
if name in fields_to_join: # Join tensors if requested
|
|
96
96
|
if isinstance(field[0], TensorMap):
|
|
97
|
-
# metatensor.TensorMap
|
|
97
|
+
# metatensor.TensorMap
|
|
98
98
|
data.append(metatensor.join(field, axis="samples", **join_kwargs))
|
|
99
|
-
elif
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
elif (
|
|
100
|
+
isinstance(field[0], torch.ScriptObject)
|
|
101
|
+
and field[0]._type().name() == "TensorMap"
|
|
102
|
+
):
|
|
103
|
+
# metatensor.torch.TensorMap
|
|
102
104
|
data.append(metatensor.torch.join(field, axis="samples", **join_kwargs))
|
|
103
|
-
elif isinstance(field[0], torch.Tensor):
|
|
105
|
+
elif isinstance(field[0], torch.Tensor):
|
|
104
106
|
data.append(torch.vstack(field))
|
|
105
107
|
else:
|
|
106
108
|
data.append(field)
|
|
@@ -83,7 +83,7 @@ def namedtuple(typename, field_names):
|
|
|
83
83
|
|
|
84
84
|
def _asdict(self):
|
|
85
85
|
"Return a new dict which maps field names to their values."
|
|
86
|
-
return _dict(_zip(self._fields, self))
|
|
86
|
+
return _dict(_zip(self._fields, self, strict=True))
|
|
87
87
|
|
|
88
88
|
def __getnewargs__(self):
|
|
89
89
|
"Return self as a plain tuple. Used by copy and pickle."
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from ._equivariant import EquivariantTransformation # noqa: F401
|
|
2
|
+
from ._layer_norm import InvariantLayerNorm, LayerNorm # noqa: F401
|
|
3
|
+
from ._linear import EquivariantLinear, Linear # noqa: F401
|
|
4
|
+
from ._module import Module # noqa: F401
|
|
5
|
+
from ._module_map import ModuleMap # noqa: F401
|
|
6
|
+
from ._relu import InvariantReLU, ReLU # noqa: F401
|
|
7
|
+
from ._sequential import Sequential # noqa: F401
|
|
8
|
+
from ._silu import InvariantSiLU, SiLU # noqa: F401
|
|
9
|
+
from ._tanh import InvariantTanh, Tanh # noqa: F401
|
|
@@ -4,13 +4,14 @@ import torch
|
|
|
4
4
|
|
|
5
5
|
from .._backend import Labels, TensorMap
|
|
6
6
|
from .._dispatch import int_array_like
|
|
7
|
+
from ._module import Module
|
|
8
|
+
from ._module_map import ModuleMap
|
|
7
9
|
from ._utils import _check_module_map_parameter
|
|
8
|
-
from .module_map import ModuleMap
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
class EquivariantTransformation(
|
|
12
|
+
class EquivariantTransformation(Module):
|
|
12
13
|
"""
|
|
13
|
-
A custom :py:class:`
|
|
14
|
+
A custom :py:class:`metatensor.learn.nn.Module` that applies an arbitrary shape- and
|
|
14
15
|
equivariance-preserving transformation to an input :py:class:`TensorMap`.
|
|
15
16
|
|
|
16
17
|
For invariant blocks (specified with ``invariant_keys``), the respective
|
|
@@ -18,19 +19,18 @@ class EquivariantTransformation(torch.nn.Module):
|
|
|
18
19
|
an invariant multiplier is created, applying the transformation to the norm of the
|
|
19
20
|
block over the component dimensions.
|
|
20
21
|
|
|
21
|
-
:param modules: a :py:class:`list` of :py:class:`torch.nn.Module`
|
|
22
|
-
transformations to be applied to
|
|
23
|
-
:param in_keys:. Transformations for invariant and
|
|
24
|
-
above.
|
|
22
|
+
:param modules: a :py:class:`list` of :py:class:`torch.nn.Module` or
|
|
23
|
+
:py:class:`metatensor.nn.Module` containing the transformations to be applied to
|
|
24
|
+
each block indexed by :param in_keys:. Transformations for invariant and
|
|
25
|
+
covariant blocks differ. See above.
|
|
25
26
|
:param in_keys: :py:class:`Labels`, the keys that are assumed to be in the input
|
|
26
27
|
:py:class:`TensorMap` in the :py:meth:`forward` method.
|
|
27
28
|
:param in_features: :py:class:`list` of :py:class:`int`, the number of features in
|
|
28
29
|
the input tensor for each block indexed by the keys in :param in_keys:. If
|
|
29
30
|
passed as a single value, the same number of features is assumed for all blocks.
|
|
30
31
|
:param out_properties: :py:class:`list` of :py:class`Labels` (optional), the
|
|
31
|
-
properties labels
|
|
32
|
-
|
|
33
|
-
Labels.range.
|
|
32
|
+
properties labels of the output. By default the output properties are relabeled
|
|
33
|
+
using ``Labels.range``.
|
|
34
34
|
:param invariant_keys: a :py:class:`Labels` object that is used to select the
|
|
35
35
|
invariant keys from ``in_keys``. If not provided, the invariant keys are assumed
|
|
36
36
|
to be those where key dimensions ``["o3_lambda", "o3_sigma"]`` are equal to
|
|
@@ -169,7 +169,7 @@ class EquivariantTransformation(torch.nn.Module):
|
|
|
169
169
|
return self.module_map(tensor)
|
|
170
170
|
|
|
171
171
|
|
|
172
|
-
class _CovariantTransform(
|
|
172
|
+
class _CovariantTransform(Module):
|
|
173
173
|
"""
|
|
174
174
|
Applies an arbitrary shape-preserving transformation defined in ``module`` to a
|
|
175
175
|
3-dimensional tensor in a way that preserves equivariance. The transformation is
|
|
@@ -7,13 +7,12 @@ respectively.
|
|
|
7
7
|
from typing import List, Optional
|
|
8
8
|
|
|
9
9
|
import torch
|
|
10
|
-
from torch.nn import Module, init
|
|
11
|
-
from torch.nn.parameter import Parameter
|
|
12
10
|
|
|
13
11
|
from .._backend import Labels, TensorMap
|
|
14
12
|
from .._dispatch import int_array_like
|
|
13
|
+
from ._module import Module
|
|
14
|
+
from ._module_map import ModuleMap
|
|
15
15
|
from ._utils import _check_module_map_parameter
|
|
16
|
-
from .module_map import ModuleMap
|
|
17
16
|
|
|
18
17
|
|
|
19
18
|
class LayerNorm(Module):
|
|
@@ -32,7 +31,7 @@ class LayerNorm(Module):
|
|
|
32
31
|
The extra parameter :param mean: controls whether or not the mean over these
|
|
33
32
|
dimensions is subtracted from the input tensor in the transformation.
|
|
34
33
|
|
|
35
|
-
Refer to the :py:class
|
|
34
|
+
Refer to the :py:class:`torch.nn.LayerNorm` documentation for a more detailed
|
|
36
35
|
description of the other parameters.
|
|
37
36
|
|
|
38
37
|
Each parameter is passed as a single value of its expected type, which is used
|
|
@@ -43,7 +42,7 @@ class LayerNorm(Module):
|
|
|
43
42
|
:param in_features: list of int, the number of features in the input tensor for each
|
|
44
43
|
block indexed by the keys in :param in_keys:. If passed as a single value, the
|
|
45
44
|
same number of features is assumed for all blocks.
|
|
46
|
-
:param out_properties: list of :py:class
|
|
45
|
+
:param out_properties: list of :py:class:`Labels` (optional), the properties labels
|
|
47
46
|
of the output. By default (if none) the output properties are relabeled using
|
|
48
47
|
Labels.range.
|
|
49
48
|
:mean bool: whether or not to subtract the mean over all dimensions except the
|
|
@@ -126,7 +125,7 @@ class InvariantLayerNorm(Module):
|
|
|
126
125
|
The extra parameter :param mean: controls whether or not the mean over these
|
|
127
126
|
dimensions is subtracted from the input tensor in the transformation.
|
|
128
127
|
|
|
129
|
-
Refer to the :py:class
|
|
128
|
+
Refer to the :py:class:`torch.nn.LayerNorm` documentation for a more detailed
|
|
130
129
|
description of the other parameters.
|
|
131
130
|
|
|
132
131
|
Each parameter is passed as a single value of its expected type, which is used
|
|
@@ -137,7 +136,7 @@ class InvariantLayerNorm(Module):
|
|
|
137
136
|
:param in_features: list of int, the number of features in the input tensor for each
|
|
138
137
|
block indexed by the keys in :param in_keys:. If passed as a single value, the
|
|
139
138
|
same number of features is assumed for all blocks.
|
|
140
|
-
:param out_properties: list of :py:class
|
|
139
|
+
:param out_properties: list of :py:class:`Labels` (optional), the properties labels
|
|
141
140
|
of the output. By default (if none) the output properties are relabeled using
|
|
142
141
|
Labels.range.
|
|
143
142
|
:param invariant_keys: a :py:class:`Labels` object that is used to select the
|
|
@@ -277,11 +276,11 @@ class _LayerNorm(Module):
|
|
|
277
276
|
self.elementwise_affine = elementwise_affine
|
|
278
277
|
self.mean = mean
|
|
279
278
|
if self.elementwise_affine:
|
|
280
|
-
self.weight = Parameter(
|
|
279
|
+
self.weight = torch.nn.Parameter(
|
|
281
280
|
torch.empty(in_features, device=device, dtype=dtype)
|
|
282
281
|
)
|
|
283
282
|
if bias:
|
|
284
|
-
self.bias = Parameter(
|
|
283
|
+
self.bias = torch.nn.Parameter(
|
|
285
284
|
torch.empty(in_features, device=device, dtype=dtype)
|
|
286
285
|
)
|
|
287
286
|
else:
|
|
@@ -294,9 +293,9 @@ class _LayerNorm(Module):
|
|
|
294
293
|
|
|
295
294
|
def reset_parameters(self) -> None:
|
|
296
295
|
if self.elementwise_affine:
|
|
297
|
-
init.ones_(self.weight)
|
|
296
|
+
torch.nn.init.ones_(self.weight)
|
|
298
297
|
if self.bias is not None:
|
|
299
|
-
init.zeros_(self.bias)
|
|
298
|
+
torch.nn.init.zeros_(self.bias)
|
|
300
299
|
|
|
301
300
|
def forward(self, input: torch.Tensor) -> torch.Tensor:
|
|
302
301
|
return _layer_norm(
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
from typing import List, Optional, Union
|
|
2
2
|
|
|
3
3
|
import torch
|
|
4
|
-
from torch.nn import Module
|
|
5
4
|
|
|
6
5
|
from .._backend import Labels, TensorMap
|
|
7
6
|
from .._dispatch import int_array_like
|
|
7
|
+
from ._module import Module
|
|
8
|
+
from ._module_map import ModuleMap
|
|
8
9
|
from ._utils import _check_module_map_parameter
|
|
9
|
-
from .module_map import ModuleMap
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class Linear(Module):
|
|
@@ -17,7 +17,7 @@ class Linear(Module):
|
|
|
17
17
|
Applies a linear transformation to each block of a :py:class:`TensorMap` passed to
|
|
18
18
|
its forward method, indexed by :param in_keys:.
|
|
19
19
|
|
|
20
|
-
Refer to the :py:class
|
|
20
|
+
Refer to the :py:class:`torch.nn.Linear` documentation for a more detailed
|
|
21
21
|
description of the other parameters.
|
|
22
22
|
|
|
23
23
|
Each parameter is passed as a single value of its expected type, which is used
|
|
@@ -31,7 +31,7 @@ class Linear(Module):
|
|
|
31
31
|
:param out_features: :py:class:`int` or :py:class:`lint` of :py:class:`int`, the
|
|
32
32
|
number of output features for each block. If passed as a single value, the same
|
|
33
33
|
feature size is taken for all blocks.
|
|
34
|
-
:param out_properties: list of :py:class
|
|
34
|
+
:param out_properties: list of :py:class:`Labels` (optional), the properties labels
|
|
35
35
|
of the output. By default the output properties are relabeled using
|
|
36
36
|
Labels.range. If provided, :param out_features: can be inferred and need not be
|
|
37
37
|
provided.
|
|
@@ -97,7 +97,7 @@ class EquivariantLinear(Module):
|
|
|
97
97
|
Applies a linear transformation to each block of a :py:class:`TensorMap` passed to
|
|
98
98
|
its forward method, indexed by :param in_keys:.
|
|
99
99
|
|
|
100
|
-
Refer to the :py:class
|
|
100
|
+
Refer to the :py:class:`torch.nn.Linear` documentation for a more detailed
|
|
101
101
|
description of the other parameters.
|
|
102
102
|
|
|
103
103
|
For :py:class:`EquivariantLinear`, by contrast to :py:class:`Linear`, the parameter
|
|
@@ -112,7 +112,7 @@ class EquivariantLinear(Module):
|
|
|
112
112
|
:param out_features: :py:class:`int` or :py:class:`lint` of :py:class:`int`, the
|
|
113
113
|
number of output features for each block. If passed as a single value, the same
|
|
114
114
|
feature size is taken for all blocks.
|
|
115
|
-
:param out_properties: list of :py:class
|
|
115
|
+
:param out_properties: list of :py:class:`Labels` (optional), the properties labels
|
|
116
116
|
of the output. By default the output properties are relabeled using
|
|
117
117
|
Labels.range. If provided, :param out_features: can be inferred and need not be
|
|
118
118
|
provided.
|