metatensor-learn 0.2.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.2.0/metatensor_learn.egg-info → metatensor-learn-0.2.1}/PKG-INFO +1 -1
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor/learn/__init__.py +3 -5
- metatensor-learn-0.2.1/metatensor/learn/data/dataloader.py +25 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor/learn/data/dataset.py +68 -64
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor/learn/nn/linear.py +1 -1
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor/learn/nn/module_map.py +7 -7
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1/metatensor_learn.egg-info}/PKG-INFO +1 -1
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/SOURCES.txt +1 -1
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/setup.py +1 -1
- metatensor-learn-0.2.0/metatensor/learn/data/dataloader.py +0 -30
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/AUTHORS +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/LICENSE +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/MANIFEST.in +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/README.rst +0 -0
- /metatensor-learn-0.2.0/metatensor/learn/_classes.py → /metatensor-learn-0.2.1/metatensor/learn/_backend.py +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor/learn/data/__init__.py +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor/learn/data/collate.py +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor/learn/nn/__init__.py +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/dependency_links.txt +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/requires.txt +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/top_level.txt +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/metatensor_learn.egg-info/zip-safe +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/n_commits_since_last_tag +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/pyproject.toml +0 -0
- {metatensor-learn-0.2.0 → metatensor-learn-0.2.1}/setup.cfg +0 -0
- {metatensor-learn-0.2.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.2.
|
|
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
|
|
@@ -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
|
|
@@ -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,37 +70,44 @@ 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):
|
|
@@ -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,30 +150,30 @@ 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
|
-
|
|
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.
|
|
171
177
|
|
|
172
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.
|
|
@@ -191,12 +197,11 @@ class IndexedDataset(_BaseDataset):
|
|
|
191
197
|
|
|
192
198
|
def __getitem__(self, idx: int) -> NamedTuple:
|
|
193
199
|
"""
|
|
194
|
-
Returns the data for each field corresponding to the internal index
|
|
195
|
-
`idx`.
|
|
200
|
+
Returns the data for each field corresponding to the internal index ``idx``.
|
|
196
201
|
|
|
197
|
-
Each item can be accessed with
|
|
198
|
-
|
|
199
|
-
|
|
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.
|
|
200
205
|
"""
|
|
201
206
|
if idx not in self._indices:
|
|
202
207
|
raise ValueError(f"Index {idx} not in dataset")
|
|
@@ -219,8 +224,7 @@ class IndexedDataset(_BaseDataset):
|
|
|
219
224
|
|
|
220
225
|
def get_sample(self, sample_id) -> NamedTuple:
|
|
221
226
|
"""
|
|
222
|
-
Returns a named tuple for the sample corresponding to the given
|
|
223
|
-
`sample_id`.
|
|
227
|
+
Returns a named tuple for the sample corresponding to the given ``sample_id``.
|
|
224
228
|
"""
|
|
225
229
|
if sample_id not in self._sample_id_to_idx:
|
|
226
230
|
raise ValueError(f"Sample ID '{sample_id}' not in dataset")
|
|
@@ -6,7 +6,7 @@ from torch.nn import Module, ModuleList
|
|
|
6
6
|
|
|
7
7
|
from metatensor.operations import _dispatch
|
|
8
8
|
|
|
9
|
-
from ..
|
|
9
|
+
from .._backend import Labels, LabelsEntry, TensorBlock, TensorMap
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
@torch.jit.interface
|
|
@@ -67,7 +67,7 @@ class ModuleMap(ModuleList):
|
|
|
67
67
|
... ]
|
|
68
68
|
... ),
|
|
69
69
|
... samples=Labels(
|
|
70
|
-
... ["
|
|
70
|
+
... ["system", "atom"],
|
|
71
71
|
... np.array(
|
|
72
72
|
... [
|
|
73
73
|
... [0, 0],
|
|
@@ -86,7 +86,7 @@ class ModuleMap(ModuleList):
|
|
|
86
86
|
... ]
|
|
87
87
|
... ),
|
|
88
88
|
... samples=Labels(
|
|
89
|
-
... ["
|
|
89
|
+
... ["system", "atom"],
|
|
90
90
|
... np.array(
|
|
91
91
|
... [
|
|
92
92
|
... [0, 0],
|
|
@@ -129,13 +129,13 @@ class ModuleMap(ModuleList):
|
|
|
129
129
|
|
|
130
130
|
>>> tensor[0]
|
|
131
131
|
TensorBlock
|
|
132
|
-
samples (2): ['
|
|
132
|
+
samples (2): ['system', 'atom']
|
|
133
133
|
components (): []
|
|
134
134
|
properties (3): ['properties']
|
|
135
135
|
gradients: None
|
|
136
136
|
>>> out[0]
|
|
137
137
|
TensorBlock
|
|
138
|
-
samples (2): ['
|
|
138
|
+
samples (2): ['system', 'atom']
|
|
139
139
|
components (): []
|
|
140
140
|
properties (1): ['_']
|
|
141
141
|
gradients: None
|
|
@@ -194,7 +194,7 @@ class ModuleMap(ModuleList):
|
|
|
194
194
|
... ]
|
|
195
195
|
... ),
|
|
196
196
|
... samples=Labels(
|
|
197
|
-
... ["
|
|
197
|
+
... ["system", "atom"],
|
|
198
198
|
... np.array(
|
|
199
199
|
... [
|
|
200
200
|
... [0, 0],
|
|
@@ -213,7 +213,7 @@ class ModuleMap(ModuleList):
|
|
|
213
213
|
... ]
|
|
214
214
|
... ),
|
|
215
215
|
... samples=Labels(
|
|
216
|
-
... ["
|
|
216
|
+
... ["system", "atom"],
|
|
217
217
|
... np.array(
|
|
218
218
|
... [
|
|
219
219
|
... [0, 0],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: metatensor-learn
|
|
3
|
-
Version: 0.2.
|
|
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
|
|
@@ -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)
|
|
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.2.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
|
|
File without changes
|