metatensor-learn 0.1.0__tar.gz → 0.2.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.1.0/metatensor_learn.egg-info → metatensor-learn-0.2.0}/PKG-INFO +2 -2
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor/learn/data/collate.py +21 -17
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor/learn/data/dataset.py +16 -18
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor/learn/nn/linear.py +2 -3
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor/learn/nn/module_map.py +14 -6
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0/metatensor_learn.egg-info}/PKG-INFO +2 -2
- metatensor-learn-0.2.0/metatensor_learn.egg-info/requires.txt +1 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/setup.py +2 -2
- metatensor-learn-0.1.0/metatensor_learn.egg-info/requires.txt +0 -1
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/AUTHORS +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/LICENSE +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/MANIFEST.in +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/README.rst +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor/learn/__init__.py +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor/learn/_classes.py +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor/learn/data/__init__.py +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor/learn/data/dataloader.py +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor/learn/nn/__init__.py +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor_learn.egg-info/SOURCES.txt +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor_learn.egg-info/dependency_links.txt +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor_learn.egg-info/top_level.txt +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/metatensor_learn.egg-info/zip-safe +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/n_commits_since_last_tag +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/pyproject.toml +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/setup.cfg +0 -0
- {metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/tests/test_dummmy.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: metatensor-learn
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
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
|
=====================
|
|
@@ -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)
|
|
@@ -104,9 +104,9 @@ class Dataset(_BaseDataset):
|
|
|
104
104
|
"""
|
|
105
105
|
|
|
106
106
|
def __init__(self, size: Optional[int] = None, **kwargs):
|
|
107
|
-
if "
|
|
107
|
+
if "sample_id" in kwargs:
|
|
108
108
|
raise ValueError(
|
|
109
|
-
"Keyword argument '
|
|
109
|
+
"Keyword argument 'sample_id' is not accepted by Dataset."
|
|
110
110
|
" For an indexed dataset, use the IndexedDataset class"
|
|
111
111
|
" instead."
|
|
112
112
|
)
|
|
@@ -151,45 +151,43 @@ class IndexedDataset(_BaseDataset):
|
|
|
151
151
|
the keyword is the name of the field, and the value is either a list of data
|
|
152
152
|
objects or a callable.
|
|
153
153
|
|
|
154
|
-
`
|
|
155
|
-
sample ID is assigned an internal numeric index from 0 to `len(
|
|
154
|
+
`sample_id` must be a unique list of any hashable object. Each respective
|
|
155
|
+
sample ID is assigned an internal numeric index from 0 to `len(sample_id)`
|
|
156
156
|
- 1. This is used to internally index the dataset, and can be used to access
|
|
157
157
|
a given sample. For instance, `dataset[0]` returns a named tuple of all data
|
|
158
158
|
fields for the first sample in the dataset, i.e. the one with unique sample
|
|
159
|
-
ID at `
|
|
159
|
+
ID at `sample_id[0]`. In order to access a sample by its ID, use the
|
|
160
160
|
Dataset.get_sample method.
|
|
161
161
|
|
|
162
162
|
A data field kwarg passed as a list must be comprised of the same type of
|
|
163
|
-
object, and its length must be consistent with the length of `
|
|
163
|
+
object, and its length must be consistent with the length of `sample_id`
|
|
164
164
|
and the length of all other data fields passed as lists.
|
|
165
165
|
|
|
166
166
|
Otherwise a data field kwarg passed as a callable must take a single
|
|
167
167
|
argument corresponding to the unique sample ID (i.e. those passed in
|
|
168
|
-
`
|
|
168
|
+
`sample_id`) and return the data object for that sample ID. This data field
|
|
169
169
|
for a given sample is then only lazily loaded into memory when the
|
|
170
170
|
Dataset.__getitem__ or Dataset.get_sample methods are called.
|
|
171
171
|
|
|
172
|
-
:param
|
|
172
|
+
:param sample_id: A list of unique IDs for each sample in the dataset.
|
|
173
173
|
:param kwargs: Keyword arguments specifying the data fields for the dataset.
|
|
174
174
|
"""
|
|
175
175
|
|
|
176
|
-
def __init__(self,
|
|
176
|
+
def __init__(self, sample_id: List, **kwargs):
|
|
177
177
|
if "size" in kwargs:
|
|
178
178
|
raise ValueError(
|
|
179
179
|
"Keyword argument 'size' is not accepted by IndexedDataset."
|
|
180
180
|
" For a dataset defined on size rather than explicit sample IDs,"
|
|
181
181
|
" use the Dataset class instead."
|
|
182
182
|
)
|
|
183
|
-
if len(set(
|
|
183
|
+
if len(set(sample_id)) != len(sample_id):
|
|
184
184
|
raise ValueError("Sample IDs must be unique. Found duplicate sample IDs.")
|
|
185
185
|
|
|
186
186
|
super(IndexedDataset, self).__init__(
|
|
187
|
-
arg_name="
|
|
187
|
+
arg_name="sample_id", size=len(sample_id), **kwargs
|
|
188
188
|
)
|
|
189
|
-
self.
|
|
190
|
-
self._sample_id_to_idx = {
|
|
191
|
-
sample_id: idx for idx, sample_id in enumerate(sample_ids)
|
|
192
|
-
}
|
|
189
|
+
self._sample_id = sample_id
|
|
190
|
+
self._sample_id_to_idx = {smpl_id: idx for idx, smpl_id in enumerate(sample_id)}
|
|
193
191
|
|
|
194
192
|
def __getitem__(self, idx: int) -> NamedTuple:
|
|
195
193
|
"""
|
|
@@ -203,15 +201,15 @@ class IndexedDataset(_BaseDataset):
|
|
|
203
201
|
if idx not in self._indices:
|
|
204
202
|
raise ValueError(f"Index {idx} not in dataset")
|
|
205
203
|
names = ["sample_id"] + self._field_names
|
|
206
|
-
sample_data = [self.
|
|
204
|
+
sample_data = [self._sample_id[idx]]
|
|
207
205
|
for name in self._field_names:
|
|
208
206
|
if callable(self._data[name]): # lazy load using sample ID
|
|
209
207
|
try:
|
|
210
|
-
sample_data.append(self._data[name](self.
|
|
208
|
+
sample_data.append(self._data[name](self._sample_id[idx]))
|
|
211
209
|
except Exception as e:
|
|
212
210
|
raise IOError(
|
|
213
211
|
f"Error loading data field '{name}' for sample"
|
|
214
|
-
f" ID {self.
|
|
212
|
+
f" ID {self._sample_id[idx]}: {e}"
|
|
215
213
|
)
|
|
216
214
|
else:
|
|
217
215
|
assert isinstance(self._data[name], list)
|
|
@@ -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,6 +4,8 @@ from typing import List, Optional, Union
|
|
|
4
4
|
import torch
|
|
5
5
|
from torch.nn import Module, ModuleList
|
|
6
6
|
|
|
7
|
+
from metatensor.operations import _dispatch
|
|
8
|
+
|
|
7
9
|
from .._classes import Labels, LabelsEntry, TensorBlock, TensorMap
|
|
8
10
|
|
|
9
11
|
|
|
@@ -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
|
|
@@ -124,7 +125,7 @@ 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
|
|
@@ -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.
|
|
3
|
+
Version: 0.2.0
|
|
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.
|
|
17
|
+
METATENSOR_LEARN_VERSION = "0.2.0"
|
|
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 +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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{metatensor-learn-0.1.0 → metatensor-learn-0.2.0}/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
|