metatensor-learn 0.1.0__tar.gz → 0.2.1__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.1.0/metatensor_learn.egg-info → metatensor-learn-0.2.1}/PKG-INFO +2 -2
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor/learn/__init__.py +3 -5
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor/learn/data/collate.py +21 -17
- metatensor-learn-0.2.1/metatensor/learn/data/dataloader.py +25 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor/learn/data/dataset.py +80 -78
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor/learn/nn/linear.py +3 -4
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor/learn/nn/module_map.py +21 -13
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1/metatensor_learn.egg-info}/PKG-INFO +2 -2
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/SOURCES.txt +1 -1
- metatensor-learn-0.2.1/metatensor_learn.egg-info/requires.txt +1 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/setup.py +2 -2
- metatensor-learn-0.1.0/metatensor/learn/data/dataloader.py +0 -30
- metatensor-learn-0.1.0/metatensor_learn.egg-info/requires.txt +0 -1
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/AUTHORS +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/LICENSE +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/MANIFEST.in +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/README.rst +0 -0
- /metatensor-learn-0.1.0/metatensor/learn/_classes.py → /metatensor-learn-0.2.1/metatensor/learn/_backend.py +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor/learn/data/__init__.py +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor/learn/nn/__init__.py +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/dependency_links.txt +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/top_level.txt +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/zip-safe +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/n_commits_since_last_tag +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/pyproject.toml +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/setup.cfg +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/tests/test_dummmy.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: metatensor-learn
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Building blocks for the atomistic machine learning models based on PyTorch and NumPy
|
|
5
5
|
Author: Guillaume Fraux, Davide Tisi, Philip Loche, Joseph W. Abbott, Jigyasa Nigam, Chiheb Ben Mahmoud
|
|
6
6
|
License: BSD-3-Clause
|
|
@@ -27,7 +27,7 @@ Requires-Python: >=3.7
|
|
|
27
27
|
Description-Content-Type: text/x-rst
|
|
28
28
|
License-File: LICENSE
|
|
29
29
|
License-File: AUTHORS
|
|
30
|
-
Requires-Dist: metatensor-operations<0.
|
|
30
|
+
Requires-Dist: metatensor-operations<0.3.0,>=0.2.0
|
|
31
31
|
|
|
32
32
|
metatensor-learn
|
|
33
33
|
=====================
|
|
@@ -12,8 +12,6 @@ except ImportError:
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
if HAS_TORCH:
|
|
15
|
-
from . import data, nn # noqa
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
__all__ = []
|
|
15
|
+
from . import data, nn # noqa: F401
|
|
16
|
+
from .data import DataLoader, Dataset, IndexedDataset # noqa: F401
|
|
17
|
+
from .nn import ModuleMap, Linear # noqa: F401
|
|
@@ -30,8 +30,7 @@ def group(batch: List[NamedTuple]) -> NamedTuple:
|
|
|
30
30
|
:return: a named tuple, with the named fields the same as in the original
|
|
31
31
|
samples in the batch, but with the samples grouped by data field.
|
|
32
32
|
"""
|
|
33
|
-
|
|
34
|
-
return namedtuple("Batch", names)(*list(zip(*batch)))
|
|
33
|
+
return namedtuple("Batch", batch[0]._fields)(*list(zip(*batch)))
|
|
35
34
|
|
|
36
35
|
|
|
37
36
|
def group_and_join(
|
|
@@ -71,10 +70,10 @@ def group_and_join(
|
|
|
71
70
|
passed that are either invalid or are names of fields that aren't these
|
|
72
71
|
types will be silently ignored.
|
|
73
72
|
:param join_kwargs: keyword arguments passed to the
|
|
74
|
-
:py:func:`metatensor.join` function, to be used when joining data
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
:py:func:`metatensor.join` function, to be used when joining data fields
|
|
74
|
+
comprised of :py:class:`TensorMap` objects. If none, the defaults are
|
|
75
|
+
used - see the function documentation for details. The `axis="samples"`
|
|
76
|
+
arg is set by default.
|
|
78
77
|
|
|
79
78
|
:return: a named tuple, with the named fields the same as in the original
|
|
80
79
|
samples in the batch, but with the samples collated for each respective
|
|
@@ -82,25 +81,30 @@ def group_and_join(
|
|
|
82
81
|
:py:class:`TensorMap` objects, they are joined along the samples axis.
|
|
83
82
|
"""
|
|
84
83
|
data: List[Union[TensorMap, torch.Tensor]] = []
|
|
85
|
-
names =
|
|
84
|
+
names = batch[0]._fields
|
|
86
85
|
if fields_to_join is None:
|
|
87
86
|
fields_to_join = names
|
|
88
87
|
if join_kwargs is None:
|
|
89
88
|
join_kwargs = {}
|
|
90
89
|
for name, field in zip(names, list(zip(*batch))):
|
|
91
|
-
if name == "
|
|
90
|
+
if name == "sample_id": # special case, keep as is
|
|
92
91
|
data.append(field)
|
|
93
92
|
continue
|
|
94
|
-
|
|
95
|
-
if
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
|
|
94
|
+
if name in fields_to_join: # Join tensors if requested
|
|
95
|
+
if isinstance(field[0], TensorMap):
|
|
96
|
+
# metatensor.TensorMap type
|
|
97
|
+
data.append(metatensor.join(field, axis="samples", **join_kwargs))
|
|
98
|
+
elif isinstance(field[0], torch.ScriptObject) and field[0]._has_method(
|
|
99
|
+
"keys_to_properties"
|
|
100
|
+
): # inferred metatensor.torch.TensorMap type
|
|
100
101
|
data.append(metatensor.torch.join(field, axis="samples", **join_kwargs))
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
elif isinstance(field[0], torch.Tensor): # torch.Tensor type
|
|
103
|
+
data.append(torch.vstack(field))
|
|
104
|
+
else:
|
|
105
|
+
data.append(field)
|
|
106
|
+
|
|
107
|
+
else: # otherwise just keep as a list
|
|
104
108
|
data.append(field)
|
|
105
109
|
|
|
106
110
|
return namedtuple("Batch", names)(*data)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module containing the DataLoader.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import torch
|
|
6
|
+
|
|
7
|
+
from .collate import group_and_join
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DataLoader(torch.utils.data.DataLoader):
|
|
11
|
+
"""
|
|
12
|
+
Class for loading data from an :py:class:`torch.utils.data.Dataset` object with a
|
|
13
|
+
default collate function (:py:func:`metatensor.learn.data.group_and_join`) that
|
|
14
|
+
supports :py:class:`torch.Tensor`, :py:class:`metatensor.torch.atomistic.System`,
|
|
15
|
+
:py:class:`metatensor.TensorMap`, and :py:class:`metatensor.torch.TensorMap`.
|
|
16
|
+
|
|
17
|
+
The dataset wil typically be :py:class:`metatensor.learn.Dataset` or
|
|
18
|
+
:py:class:`metatensor.learn.IndexedDataset`.
|
|
19
|
+
|
|
20
|
+
Any argument as accepted by the torch :py:class:`torch.utils.data.DataLoader` parent
|
|
21
|
+
class is supported.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, dataset, collate_fn=group_and_join, **kwargs):
|
|
25
|
+
super().__init__(dataset, collate_fn=collate_fn, **kwargs)
|
|
@@ -70,43 +70,50 @@ class _BaseDataset(torch.utils.data.Dataset):
|
|
|
70
70
|
"""
|
|
71
71
|
return self._size
|
|
72
72
|
|
|
73
|
+
def __iter__(self):
|
|
74
|
+
"""
|
|
75
|
+
Returns an iterator over the dataset.
|
|
76
|
+
"""
|
|
77
|
+
for idx in self._indices:
|
|
78
|
+
yield self[idx]
|
|
79
|
+
|
|
73
80
|
|
|
74
81
|
class Dataset(_BaseDataset):
|
|
75
82
|
"""
|
|
76
|
-
Defines a
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
in the dataset.
|
|
90
|
-
|
|
91
|
-
A data field kwarg passed as a list must be comprised of the same type of
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
Otherwise a data field kwarg passed as a callable must take a single
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
:param size: Optional, an integer indicating the size of the dataset, i.e.
|
|
101
|
-
|
|
102
|
-
:param kwargs: List or Callable. Keyword arguments specifying the data
|
|
103
|
-
|
|
83
|
+
Defines a PyTorch compatible :py:class:`torch.data.Dataset` class for various named
|
|
84
|
+
data fields.
|
|
85
|
+
|
|
86
|
+
The data fields are specified as keyword arguments to the constructor, where the
|
|
87
|
+
keyword is the name of the field, and the value is either a list of data objects or
|
|
88
|
+
a callable.
|
|
89
|
+
|
|
90
|
+
``size`` specifies the number of samples in the dataset. This only needs to be
|
|
91
|
+
passed if all data fields are passed as callables. Otherwise, the size is inferred
|
|
92
|
+
from the length of the data fields passed as lists.
|
|
93
|
+
|
|
94
|
+
Every sample in the dataset is assigned a numeric ID from 0 to ``size - 1``. This ID
|
|
95
|
+
can be used to access the corresponding sample. For instance, ``dataset[0]`` returns
|
|
96
|
+
a named tuple of all data fields for the first sample in the dataset.
|
|
97
|
+
|
|
98
|
+
A data field kwarg passed as a list must be comprised of the same type of object,
|
|
99
|
+
and its length must be consistent with the ``size`` argument (if specified) and the
|
|
100
|
+
length of all other data fields passed as lists.
|
|
101
|
+
|
|
102
|
+
Otherwise a data field kwarg passed as a callable must take a single argument
|
|
103
|
+
corresponding to the numeric sample ID and return the data object for that sample
|
|
104
|
+
ID. This data field for a given sample is then only lazily loaded into memory when
|
|
105
|
+
the :py:meth:`Dataset.__getitem__` method is called.
|
|
106
|
+
|
|
107
|
+
:param size: Optional, an integer indicating the size of the dataset, i.e. the
|
|
108
|
+
number of samples. This only needs to be specified if all data
|
|
109
|
+
:param kwargs: List or Callable. Keyword arguments specifying the data fields for
|
|
110
|
+
the dataset.
|
|
104
111
|
"""
|
|
105
112
|
|
|
106
113
|
def __init__(self, size: Optional[int] = None, **kwargs):
|
|
107
|
-
if "
|
|
114
|
+
if "sample_id" in kwargs:
|
|
108
115
|
raise ValueError(
|
|
109
|
-
"Keyword argument '
|
|
116
|
+
"Keyword argument 'sample_id' is not accepted by Dataset."
|
|
110
117
|
" For an indexed dataset, use the IndexedDataset class"
|
|
111
118
|
" instead."
|
|
112
119
|
)
|
|
@@ -115,12 +122,11 @@ class Dataset(_BaseDataset):
|
|
|
115
122
|
|
|
116
123
|
def __getitem__(self, idx: int) -> NamedTuple:
|
|
117
124
|
"""
|
|
118
|
-
Returns the data for each field corresponding to the internal index
|
|
119
|
-
`idx`.
|
|
125
|
+
Returns the data for each field corresponding to the internal index ``idx``.
|
|
120
126
|
|
|
121
|
-
Each item can be accessed with
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
Each item can be accessed with ``self[idx]``. Returned is a named tuple with
|
|
128
|
+
fields corresponding to those passed (in order) to the constructor upon class
|
|
129
|
+
initialization.
|
|
124
130
|
"""
|
|
125
131
|
if idx not in self._indices:
|
|
126
132
|
raise ValueError(f"Index {idx} not in dataset")
|
|
@@ -144,74 +150,71 @@ class Dataset(_BaseDataset):
|
|
|
144
150
|
|
|
145
151
|
class IndexedDataset(_BaseDataset):
|
|
146
152
|
"""
|
|
147
|
-
Defines a
|
|
148
|
-
by a list of unique sample IDs.
|
|
149
|
-
|
|
150
|
-
The data fields are specified as keyword arguments to the constructor, where
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
A data field kwarg passed as a list must be comprised of the same type of
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
Otherwise a data field kwarg passed as a callable must take a single
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
:param
|
|
153
|
+
Defines a PyTorch compatible :py:class:`torch.data.Dataset` class for various named
|
|
154
|
+
data fields, with sample indexed by a list of unique sample IDs.
|
|
155
|
+
|
|
156
|
+
The data fields are specified as keyword arguments to the constructor, where the
|
|
157
|
+
keyword is the name of the field, and the value is either a list of data objects or
|
|
158
|
+
a callable.
|
|
159
|
+
|
|
160
|
+
``sample_id`` must be a unique list of any hashable object. Each respective sample
|
|
161
|
+
ID is assigned an internal numeric index from 0 to ``len(sample_id) - 1``. This is
|
|
162
|
+
used to internally index the dataset, and can be used to access a given sample. For
|
|
163
|
+
instance, ``dataset[0]`` returns a named tuple of all data fields for the first
|
|
164
|
+
sample in the dataset, i.e. the one with unique sample ID at ``sample_id[0]``. In
|
|
165
|
+
order to access a sample by its ID, use the :py:meth:`IndexedDataset.get_sample`
|
|
166
|
+
method.
|
|
167
|
+
|
|
168
|
+
A data field kwarg passed as a list must be comprised of the same type of object,
|
|
169
|
+
and its length must be consistent with the length of ``sample_id`` and the length of
|
|
170
|
+
all other data fields passed as lists.
|
|
171
|
+
|
|
172
|
+
Otherwise a data field kwarg passed as a callable must take a single argument
|
|
173
|
+
corresponding to the unique sample ID (i.e. those passed in ``sample_id``) and
|
|
174
|
+
return the data object for that sample ID. This data field for a given sample is
|
|
175
|
+
then only lazily loaded into memory when :py:meth:`IndexedDataset.__getitem__` or
|
|
176
|
+
:py:meth:`IndexedDataset.get_sample` methods are called.
|
|
177
|
+
|
|
178
|
+
:param sample_id: A list of unique IDs for each sample in the dataset.
|
|
173
179
|
:param kwargs: Keyword arguments specifying the data fields for the dataset.
|
|
174
180
|
"""
|
|
175
181
|
|
|
176
|
-
def __init__(self,
|
|
182
|
+
def __init__(self, sample_id: List, **kwargs):
|
|
177
183
|
if "size" in kwargs:
|
|
178
184
|
raise ValueError(
|
|
179
185
|
"Keyword argument 'size' is not accepted by IndexedDataset."
|
|
180
186
|
" For a dataset defined on size rather than explicit sample IDs,"
|
|
181
187
|
" use the Dataset class instead."
|
|
182
188
|
)
|
|
183
|
-
if len(set(
|
|
189
|
+
if len(set(sample_id)) != len(sample_id):
|
|
184
190
|
raise ValueError("Sample IDs must be unique. Found duplicate sample IDs.")
|
|
185
191
|
|
|
186
192
|
super(IndexedDataset, self).__init__(
|
|
187
|
-
arg_name="
|
|
193
|
+
arg_name="sample_id", size=len(sample_id), **kwargs
|
|
188
194
|
)
|
|
189
|
-
self.
|
|
190
|
-
self._sample_id_to_idx = {
|
|
191
|
-
sample_id: idx for idx, sample_id in enumerate(sample_ids)
|
|
192
|
-
}
|
|
195
|
+
self._sample_id = sample_id
|
|
196
|
+
self._sample_id_to_idx = {smpl_id: idx for idx, smpl_id in enumerate(sample_id)}
|
|
193
197
|
|
|
194
198
|
def __getitem__(self, idx: int) -> NamedTuple:
|
|
195
199
|
"""
|
|
196
|
-
Returns the data for each field corresponding to the internal index
|
|
197
|
-
`idx`.
|
|
200
|
+
Returns the data for each field corresponding to the internal index ``idx``.
|
|
198
201
|
|
|
199
|
-
Each item can be accessed with
|
|
200
|
-
|
|
201
|
-
|
|
202
|
+
Each item can be accessed with ``self[idx]``. Returned is a named tuple, whose
|
|
203
|
+
first field is the sample ID, and the remaining fields correspond those passed
|
|
204
|
+
(in order) to the constructor upon class initialization.
|
|
202
205
|
"""
|
|
203
206
|
if idx not in self._indices:
|
|
204
207
|
raise ValueError(f"Index {idx} not in dataset")
|
|
205
208
|
names = ["sample_id"] + self._field_names
|
|
206
|
-
sample_data = [self.
|
|
209
|
+
sample_data = [self._sample_id[idx]]
|
|
207
210
|
for name in self._field_names:
|
|
208
211
|
if callable(self._data[name]): # lazy load using sample ID
|
|
209
212
|
try:
|
|
210
|
-
sample_data.append(self._data[name](self.
|
|
213
|
+
sample_data.append(self._data[name](self._sample_id[idx]))
|
|
211
214
|
except Exception as e:
|
|
212
215
|
raise IOError(
|
|
213
216
|
f"Error loading data field '{name}' for sample"
|
|
214
|
-
f" ID {self.
|
|
217
|
+
f" ID {self._sample_id[idx]}: {e}"
|
|
215
218
|
)
|
|
216
219
|
else:
|
|
217
220
|
assert isinstance(self._data[name], list)
|
|
@@ -221,8 +224,7 @@ class IndexedDataset(_BaseDataset):
|
|
|
221
224
|
|
|
222
225
|
def get_sample(self, sample_id) -> NamedTuple:
|
|
223
226
|
"""
|
|
224
|
-
Returns a named tuple for the sample corresponding to the given
|
|
225
|
-
`sample_id`.
|
|
227
|
+
Returns a named tuple for the sample corresponding to the given ``sample_id``.
|
|
226
228
|
"""
|
|
227
229
|
if sample_id not in self._sample_id_to_idx:
|
|
228
230
|
raise ValueError(f"Sample ID '{sample_id}' not in dataset")
|
|
@@ -2,7 +2,7 @@ from typing import List, Optional, Union
|
|
|
2
2
|
|
|
3
3
|
import torch
|
|
4
4
|
|
|
5
|
-
from ..
|
|
5
|
+
from .._backend import Labels, TensorMap
|
|
6
6
|
from .module_map import ModuleMap
|
|
7
7
|
|
|
8
8
|
|
|
@@ -112,7 +112,7 @@ class Linear(ModuleMap):
|
|
|
112
112
|
Construct a linear module map from a tensor map for the weights and bias.
|
|
113
113
|
|
|
114
114
|
:param weights:
|
|
115
|
-
The weight tensor map from which we create the linear modules.
|
|
115
|
+
The weight tensor map from which we create the linear modules. The
|
|
116
116
|
properties of the tensor map describe the input dimension and the samples
|
|
117
117
|
describe the output dimension.
|
|
118
118
|
|
|
@@ -125,8 +125,7 @@ class Linear(ModuleMap):
|
|
|
125
125
|
out_features=[len(weights[i].properties) for i in range(len(weights))],
|
|
126
126
|
bias=False,
|
|
127
127
|
device=weights.device,
|
|
128
|
-
dtype=weights[0].values.dtype, #
|
|
129
|
-
# we use the dtype of the values
|
|
128
|
+
dtype=weights[0].values.dtype, # dtype is consistent over blocks in map
|
|
130
129
|
out_properties=[weights[i].properties for i in range(len(weights))],
|
|
131
130
|
)
|
|
132
131
|
for i in range(len(weights)):
|
|
@@ -4,7 +4,9 @@ from typing import List, Optional, Union
|
|
|
4
4
|
import torch
|
|
5
5
|
from torch.nn import Module, ModuleList
|
|
6
6
|
|
|
7
|
-
from
|
|
7
|
+
from metatensor.operations import _dispatch
|
|
8
|
+
|
|
9
|
+
from .._backend import Labels, LabelsEntry, TensorBlock, TensorMap
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
@torch.jit.interface
|
|
@@ -33,9 +35,8 @@ class ModuleMap(ModuleList):
|
|
|
33
35
|
tensor block that corresponding to the`i`th key in :param in_keys:.
|
|
34
36
|
|
|
35
37
|
:param in_keys:
|
|
36
|
-
A :py:class:`metatensor.Labels` object
|
|
37
|
-
|
|
38
|
-
in the :py:meth:`forward` function.
|
|
38
|
+
A :py:class:`metatensor.Labels` object with the keys of the module map that are
|
|
39
|
+
assumed to be in the input tensor map in the :py:meth:`forward` function.
|
|
39
40
|
|
|
40
41
|
:param modules:
|
|
41
42
|
A sequence of modules applied in the :py:meth:`forward` function on the input
|
|
@@ -66,7 +67,7 @@ class ModuleMap(ModuleList):
|
|
|
66
67
|
... ]
|
|
67
68
|
... ),
|
|
68
69
|
... samples=Labels(
|
|
69
|
-
... ["
|
|
70
|
+
... ["system", "atom"],
|
|
70
71
|
... np.array(
|
|
71
72
|
... [
|
|
72
73
|
... [0, 0],
|
|
@@ -85,7 +86,7 @@ class ModuleMap(ModuleList):
|
|
|
85
86
|
... ]
|
|
86
87
|
... ),
|
|
87
88
|
... samples=Labels(
|
|
88
|
-
... ["
|
|
89
|
+
... ["system", "atom"],
|
|
89
90
|
... np.array(
|
|
90
91
|
... [
|
|
91
92
|
... [0, 0],
|
|
@@ -124,17 +125,17 @@ class ModuleMap(ModuleList):
|
|
|
124
125
|
tensor([[15.],
|
|
125
126
|
[11.]], grad_fn=<MmBackward0>)
|
|
126
127
|
|
|
127
|
-
|
|
128
|
+
Let's look at the metadata
|
|
128
129
|
|
|
129
130
|
>>> tensor[0]
|
|
130
131
|
TensorBlock
|
|
131
|
-
samples (2): ['
|
|
132
|
+
samples (2): ['system', 'atom']
|
|
132
133
|
components (): []
|
|
133
134
|
properties (3): ['properties']
|
|
134
135
|
gradients: None
|
|
135
136
|
>>> out[0]
|
|
136
137
|
TensorBlock
|
|
137
|
-
samples (2): ['
|
|
138
|
+
samples (2): ['system', 'atom']
|
|
138
139
|
components (): []
|
|
139
140
|
properties (1): ['_']
|
|
140
141
|
gradients: None
|
|
@@ -193,7 +194,7 @@ class ModuleMap(ModuleList):
|
|
|
193
194
|
... ]
|
|
194
195
|
... ),
|
|
195
196
|
... samples=Labels(
|
|
196
|
-
... ["
|
|
197
|
+
... ["system", "atom"],
|
|
197
198
|
... np.array(
|
|
198
199
|
... [
|
|
199
200
|
... [0, 0],
|
|
@@ -212,7 +213,7 @@ class ModuleMap(ModuleList):
|
|
|
212
213
|
... ]
|
|
213
214
|
... ),
|
|
214
215
|
... samples=Labels(
|
|
215
|
-
... ["
|
|
216
|
+
... ["system", "atom"],
|
|
216
217
|
... np.array(
|
|
217
218
|
... [
|
|
218
219
|
... [0, 0],
|
|
@@ -249,7 +250,8 @@ class ModuleMap(ModuleList):
|
|
|
249
250
|
|
|
250
251
|
def forward(self, tensor: TensorMap) -> TensorMap:
|
|
251
252
|
"""
|
|
252
|
-
|
|
253
|
+
Apply the modules on each block in ``tensor``. ``tensor`` must have the same
|
|
254
|
+
set of keys as the modules used to initialize this :py:class:`ModuleMap`.
|
|
253
255
|
|
|
254
256
|
:param tensor:
|
|
255
257
|
input tensor map
|
|
@@ -280,7 +282,13 @@ class ModuleMap(ModuleList):
|
|
|
280
282
|
|
|
281
283
|
out_values = module.forward(block.values)
|
|
282
284
|
if self._out_properties is None:
|
|
283
|
-
|
|
285
|
+
# we do not use range because of metatensor/issues/410
|
|
286
|
+
properties = Labels(
|
|
287
|
+
"_",
|
|
288
|
+
_dispatch.int_array_like(
|
|
289
|
+
list(range(out_values.shape[-1])), block.samples.values
|
|
290
|
+
).reshape(-1, 1),
|
|
291
|
+
)
|
|
284
292
|
else:
|
|
285
293
|
properties = self._out_properties[module_idx]
|
|
286
294
|
return TensorBlock(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: metatensor-learn
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Building blocks for the atomistic machine learning models based on PyTorch and NumPy
|
|
5
5
|
Author: Guillaume Fraux, Davide Tisi, Philip Loche, Joseph W. Abbott, Jigyasa Nigam, Chiheb Ben Mahmoud
|
|
6
6
|
License: BSD-3-Clause
|
|
@@ -27,7 +27,7 @@ Requires-Python: >=3.7
|
|
|
27
27
|
Description-Content-Type: text/x-rst
|
|
28
28
|
License-File: LICENSE
|
|
29
29
|
License-File: AUTHORS
|
|
30
|
-
Requires-Dist: metatensor-operations<0.
|
|
30
|
+
Requires-Dist: metatensor-operations<0.3.0,>=0.2.0
|
|
31
31
|
|
|
32
32
|
metatensor-learn
|
|
33
33
|
=====================
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
metatensor-operations<0.3.0,>=0.2.0
|
|
@@ -14,7 +14,7 @@ METATENSOR_OPERATIONS = os.path.realpath(
|
|
|
14
14
|
os.path.join(ROOT, "..", "metatensor-operations")
|
|
15
15
|
)
|
|
16
16
|
|
|
17
|
-
METATENSOR_LEARN_VERSION = "0.1
|
|
17
|
+
METATENSOR_LEARN_VERSION = "0.2.1"
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class bdist_egg_disabled(bdist_egg):
|
|
@@ -136,7 +136,7 @@ if __name__ == "__main__":
|
|
|
136
136
|
)
|
|
137
137
|
else:
|
|
138
138
|
# we are building from a sdist/installing from a wheel
|
|
139
|
-
install_requires.append("metatensor-operations >=0.
|
|
139
|
+
install_requires.append("metatensor-operations >=0.2.0,<0.3.0")
|
|
140
140
|
|
|
141
141
|
setup(
|
|
142
142
|
version=create_version_number(METATENSOR_LEARN_VERSION),
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Module containing the DataLoader.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from typing import Callable
|
|
6
|
-
|
|
7
|
-
import torch
|
|
8
|
-
|
|
9
|
-
from .collate import group_and_join
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class DataLoader(torch.utils.data.DataLoader):
|
|
13
|
-
"""
|
|
14
|
-
Class for loading data from an `:py:class:`torch.utils.data.Dataset` object
|
|
15
|
-
with a default collate function that supports :py:class:`torch.Tensor`,
|
|
16
|
-
:py:class:`atomistic.Systems`, or :py:class:`TensorMap`.
|
|
17
|
-
|
|
18
|
-
Any argument as accepted by the torch
|
|
19
|
-
:py:class:`torch.utils.data.DataLoader` parent class is supported. Please
|
|
20
|
-
refer to
|
|
21
|
-
https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
def __init__(
|
|
25
|
-
self,
|
|
26
|
-
dataset: torch.utils.data.Dataset,
|
|
27
|
-
collate_fn: Callable = group_and_join,
|
|
28
|
-
**kwargs,
|
|
29
|
-
):
|
|
30
|
-
super().__init__(dataset, collate_fn=collate_fn, **kwargs)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
metatensor-operations<0.2.0,>=0.1.0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metatensor-learn-0.1.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|