metatensor-operations 0.3.0__tar.gz → 0.3.2__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.
Files changed (53) hide show
  1. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/AUTHORS +4 -3
  2. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/MANIFEST.in +1 -1
  3. {metatensor_operations-0.3.0/metatensor_operations.egg-info → metatensor_operations-0.3.2}/PKG-INFO +5 -3
  4. metatensor_operations-0.3.2/git_version_info +2 -0
  5. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/__init__.py +1 -0
  6. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/_checks.py +0 -2
  7. metatensor_operations-0.3.2/metatensor/operations/filter_blocks.py +95 -0
  8. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/manipulate_dimension.py +0 -1
  9. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/reduce_over_samples.py +1 -1
  10. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/sort.py +2 -1
  11. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2/metatensor_operations.egg-info}/PKG-INFO +5 -3
  12. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor_operations.egg-info/SOURCES.txt +2 -1
  13. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/pyproject.toml +1 -1
  14. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/setup.py +43 -39
  15. metatensor_operations-0.3.0/n_commits_since_last_tag +0 -1
  16. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/LICENSE +0 -0
  17. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/README.rst +0 -0
  18. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/_backend.py +0 -0
  19. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/_dispatch.py +0 -0
  20. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/_utils.py +0 -0
  21. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/abs.py +0 -0
  22. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/add.py +0 -0
  23. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/allclose.py +0 -0
  24. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/block_from_array.py +0 -0
  25. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/detach.py +0 -0
  26. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/divide.py +0 -0
  27. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/dot.py +0 -0
  28. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/drop_blocks.py +0 -0
  29. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/empty_like.py +0 -0
  30. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/equal.py +0 -0
  31. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/equal_metadata.py +0 -0
  32. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/is_contiguous.py +0 -0
  33. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/join.py +0 -0
  34. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/lstsq.py +0 -0
  35. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/make_contiguous.py +0 -0
  36. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/multiply.py +0 -0
  37. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/one_hot.py +0 -0
  38. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/ones_like.py +0 -0
  39. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/pow.py +0 -0
  40. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/random_like.py +0 -0
  41. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/remove_gradients.py +0 -0
  42. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/requires_grad.py +0 -0
  43. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/slice.py +0 -0
  44. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/solve.py +0 -0
  45. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/split.py +0 -0
  46. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/subtract.py +0 -0
  47. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/unique_metadata.py +0 -0
  48. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor/operations/zeros_like.py +0 -0
  49. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor_operations.egg-info/dependency_links.txt +0 -0
  50. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor_operations.egg-info/requires.txt +0 -0
  51. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor_operations.egg-info/top_level.txt +0 -0
  52. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/metatensor_operations.egg-info/zip-safe +0 -0
  53. {metatensor_operations-0.3.0 → metatensor_operations-0.3.2}/setup.cfg +0 -0
@@ -1,6 +1,7 @@
1
1
  Guillaume Fraux
2
- Davide Tisi
3
2
  Philip Loche
3
+ Filippo Bigi
4
4
  Joseph W. Abbott
5
- Jigyasa Nigam
6
- Chiheb Ben Mahmoud
5
+ Davide Tisi
6
+ Alexander Goscinski
7
+ Michele Ceriotti
@@ -2,4 +2,4 @@ include pyproject.toml
2
2
  include AUTHORS
3
3
  include LICENSE
4
4
 
5
- include n_commits_since_last_tag
5
+ include git_version_info
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: metatensor-operations
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Operations to manipulate metatensor data types
5
- Author: Guillaume Fraux, Davide Tisi, Philip Loche, Joseph W. Abbott, Jigyasa Nigam, Chiheb Ben Mahmoud
5
+ Author: Guillaume Fraux, Philip Loche, Filippo Bigi, Joseph W. Abbott, Davide Tisi, Alexander Goscinski, Michele Ceriotti
6
6
  License: BSD-3-Clause
7
7
  Project-URL: homepage, https://docs.metatensor.org/latest/
8
8
  Project-URL: documentation, https://docs.metatensor.org/latest/
@@ -28,6 +28,8 @@ Description-Content-Type: text/x-rst
28
28
  License-File: LICENSE
29
29
  License-File: AUTHORS
30
30
  Requires-Dist: metatensor-core<0.2.0,>=0.1.10
31
+ Dynamic: author
32
+ Dynamic: requires-dist
31
33
 
32
34
  metatensor-operations
33
35
  =====================
@@ -0,0 +1,2 @@
1
+ 0
2
+ git.81a27ac
@@ -28,6 +28,7 @@ from .equal_metadata import ( # noqa
28
28
  equal_metadata_raise,
29
29
  equal_metadata_block_raise,
30
30
  )
31
+ from .filter_blocks import filter_blocks # noqa
31
32
  from .is_contiguous import ( # noqa: F401
32
33
  is_contiguous,
33
34
  is_contiguous_block,
@@ -66,7 +66,6 @@ class unsafe_enable_checks(_SetChecks):
66
66
  ... with metatensor.unsafe_enable_checks():
67
67
  ... # checks enabled here again
68
68
  ... print(metatensor.checks_enabled())
69
- ...
70
69
  False
71
70
  True
72
71
  >>> print(metatensor.checks_enabled())
@@ -95,7 +94,6 @@ class unsafe_disable_checks(_SetChecks):
95
94
  >>> with metatensor.unsafe_disable_checks():
96
95
  ... # checks are disabled here
97
96
  ... print(metatensor.checks_enabled())
98
- ...
99
97
  False
100
98
  >>> print(metatensor.checks_enabled())
101
99
  True
@@ -0,0 +1,95 @@
1
+ from typing import List
2
+
3
+ from . import _dispatch
4
+ from ._backend import (
5
+ Labels,
6
+ TensorBlock,
7
+ TensorMap,
8
+ is_metatensor_class,
9
+ torch_jit_is_scripting,
10
+ torch_jit_script,
11
+ )
12
+
13
+
14
+ @torch_jit_script
15
+ def filter_blocks(tensor: TensorMap, keys: Labels, copy: bool = False) -> TensorMap:
16
+ """
17
+ Returns a :py:class:`TensorMap` with the blocks filtered according to the
18
+ :py:class:`Labels` key selection passed in ``keys``.
19
+
20
+ :param tensor: the :py:class:`TensorMap` from which the keys will be selected.
21
+ :param keys: the :py:class:`Labels` containing the keys indexing blocks to
22
+ retain from the tensor :py:class:`TensorMap`.
23
+
24
+ :param copy: if :py:obj:`True`, the returned :py:class:`TensorMap` is constructed by
25
+ copying the blocks from the input `tensor`. If :py:obj:`False` (default), the
26
+ values of the blocks in the output :py:class:`TensorMap` reference the same data
27
+ as the input `tensor`. The latter can be useful for limiting memory usage, but
28
+ should be used with caution when manipulating the underlying data.
29
+ """
30
+ # Check arg types
31
+ if not torch_jit_is_scripting():
32
+ if not is_metatensor_class(tensor, TensorMap):
33
+ raise TypeError(
34
+ f"`tensor` must be a metatensor TensorMap, not {type(tensor)}"
35
+ )
36
+
37
+ if not is_metatensor_class(keys, Labels):
38
+ raise TypeError(f"`keys` must be a metatensor Labels, not {type(keys)}")
39
+
40
+ if not isinstance(copy, bool):
41
+ raise TypeError(f"`copy` must be a boolean, not {type(copy)}")
42
+
43
+ tensor_keys = tensor.keys
44
+ to_keep_indices: List[int] = tensor_keys.select(keys).tolist()
45
+
46
+ # Create the new TensorMap
47
+ new_blocks: List[TensorBlock] = []
48
+ new_keys_values = []
49
+ for i in range(len(tensor_keys)):
50
+ if i not in to_keep_indices:
51
+ continue
52
+
53
+ new_keys_values.append(tensor_keys.entry(i).values)
54
+ block = tensor[i]
55
+
56
+ if copy:
57
+ new_blocks.append(block.copy())
58
+ else:
59
+ # just increase the reference count on everything
60
+ new_block = TensorBlock(
61
+ values=block.values,
62
+ samples=block.samples,
63
+ components=block.components,
64
+ properties=block.properties,
65
+ )
66
+
67
+ for parameter, gradient in block.gradients():
68
+ if len(gradient.gradients_list()) != 0:
69
+ raise NotImplementedError(
70
+ "gradients of gradients are not supported"
71
+ )
72
+
73
+ new_block.add_gradient(
74
+ parameter=parameter,
75
+ gradient=TensorBlock(
76
+ values=gradient.values,
77
+ samples=gradient.samples,
78
+ components=gradient.components,
79
+ properties=new_block.properties,
80
+ ),
81
+ )
82
+
83
+ new_blocks.append(new_block)
84
+
85
+ if len(new_keys_values) != 0:
86
+ new_keys = Labels(tensor_keys.names, _dispatch.stack(new_keys_values, 0))
87
+ else:
88
+ new_keys = Labels(
89
+ names=tensor_keys.names,
90
+ values=_dispatch.empty_like(
91
+ tensor_keys.values, (0, len(tensor_keys.names))
92
+ ),
93
+ )
94
+
95
+ return TensorMap(keys=new_keys, blocks=new_blocks)
@@ -334,7 +334,6 @@ def remove_dimension(tensor: TensorMap, axis: str, name: str) -> TensorMap:
334
334
  ... metatensor.remove_dimension(tensor, axis="keys", name="extra")
335
335
  ... except MetatensorError as e:
336
336
  ... print(e)
337
- ...
338
337
  invalid parameter: can not have the same label entry multiple time: [0] is already present
339
338
  """ # noqa E501
340
339
  _check_axis(axis)
@@ -536,7 +536,7 @@ def mean_over_samples_block(
536
536
  """
537
537
 
538
538
  return _reduce_over_samples_block(
539
- block=block, sample_names=sample_names, reduction="sum"
539
+ block=block, sample_names=sample_names, reduction="mean"
540
540
  )
541
541
 
542
542
 
@@ -9,6 +9,7 @@ from ._backend import (
9
9
  torch_jit_is_scripting,
10
10
  torch_jit_script,
11
11
  )
12
+ from .zeros_like import zeros_like_block
12
13
 
13
14
 
14
15
  def _sort_single_gradient_block(
@@ -100,7 +101,7 @@ def _sort_single_block(
100
101
  Sorts a single TensorBlock without the user input checking and sorting of gradients
101
102
  """
102
103
  if len(block) == 0:
103
- return block
104
+ return zeros_like_block(block)
104
105
 
105
106
  sample_names = block.samples.names
106
107
  sample_values = block.samples.values
@@ -1,8 +1,8 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: metatensor-operations
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Operations to manipulate metatensor data types
5
- Author: Guillaume Fraux, Davide Tisi, Philip Loche, Joseph W. Abbott, Jigyasa Nigam, Chiheb Ben Mahmoud
5
+ Author: Guillaume Fraux, Philip Loche, Filippo Bigi, Joseph W. Abbott, Davide Tisi, Alexander Goscinski, Michele Ceriotti
6
6
  License: BSD-3-Clause
7
7
  Project-URL: homepage, https://docs.metatensor.org/latest/
8
8
  Project-URL: documentation, https://docs.metatensor.org/latest/
@@ -28,6 +28,8 @@ Description-Content-Type: text/x-rst
28
28
  License-File: LICENSE
29
29
  License-File: AUTHORS
30
30
  Requires-Dist: metatensor-core<0.2.0,>=0.1.10
31
+ Dynamic: author
32
+ Dynamic: requires-dist
31
33
 
32
34
  metatensor-operations
33
35
  =====================
@@ -2,7 +2,7 @@ AUTHORS
2
2
  LICENSE
3
3
  MANIFEST.in
4
4
  README.rst
5
- n_commits_since_last_tag
5
+ git_version_info
6
6
  pyproject.toml
7
7
  setup.py
8
8
  metatensor/operations/__init__.py
@@ -21,6 +21,7 @@ metatensor/operations/drop_blocks.py
21
21
  metatensor/operations/empty_like.py
22
22
  metatensor/operations/equal.py
23
23
  metatensor/operations/equal_metadata.py
24
+ metatensor/operations/filter_blocks.py
24
25
  metatensor/operations/is_contiguous.py
25
26
  metatensor/operations/join.py
26
27
  metatensor/operations/lstsq.py
@@ -34,7 +34,7 @@ changelog = "https://docs.metatensor.org/latest/operations/CHANGELOG.html"
34
34
  ### ======================================================================== ###
35
35
  [build-system]
36
36
  requires = [
37
- "setuptools >=68",
37
+ "setuptools >=75",
38
38
  "packaging >=23",
39
39
  ]
40
40
  build-backend = "setuptools.build_meta"
@@ -1,7 +1,6 @@
1
1
  import os
2
2
  import subprocess
3
3
  import sys
4
- import uuid
5
4
 
6
5
  import packaging.version
7
6
  from setuptools import setup
@@ -10,9 +9,9 @@ from setuptools.command.sdist import sdist
10
9
 
11
10
 
12
11
  ROOT = os.path.realpath(os.path.dirname(__file__))
13
- METATENSOR_CORE = os.path.realpath(os.path.join(ROOT, "..", "metatensor-core"))
12
+ METATENSOR_CORE = os.path.realpath(os.path.join(ROOT, "..", "metatensor_core"))
14
13
 
15
- METATENSOR_OPERATIONS_VERSION = "0.3.0"
14
+ METATENSOR_OPERATIONS_VERSION = "0.3.2"
16
15
 
17
16
 
18
17
  class bdist_egg_disabled(bdist_egg):
@@ -37,54 +36,62 @@ class sdist_git_version(sdist):
37
36
  """
38
37
 
39
38
  def run(self):
40
- with open("n_commits_since_last_tag", "w") as fd:
41
- fd.write(str(n_commits_since_last_tag()))
39
+ n_commits, git_hash = git_version_info()
40
+ with open("git_version_info", "w") as fd:
41
+ fd.write(f"{n_commits}\n{git_hash}\n")
42
42
 
43
43
  # run original sdist
44
44
  super().run()
45
45
 
46
- os.unlink("n_commits_since_last_tag")
46
+ os.unlink("git_version_info")
47
47
 
48
48
 
49
- def n_commits_since_last_tag():
49
+ def git_version_info():
50
50
  """
51
51
  If git is available and we are building from a checkout, get the number of commits
52
- since the last tag. Otherwise, this always returns 0.
52
+ since the last tag & full hash of the code. Otherwise, this always returns (0, "").
53
53
  """
54
- script = os.path.join(ROOT, "..", "..", "scripts", "n-commits-since-last-tag.py")
55
- assert os.path.exists(script)
56
-
57
54
  TAG_PREFIX = "metatensor-operations-v"
58
- output = subprocess.run(
59
- [sys.executable, script, TAG_PREFIX],
60
- stderr=subprocess.PIPE,
61
- stdout=subprocess.PIPE,
62
- encoding="utf8",
63
- )
64
55
 
65
- if output.returncode != 0:
66
- raise Exception(
67
- "failed to get number of commits since last tag.\n"
68
- f"stdout: {output.stdout}\n"
69
- f"stderr: {output.stderr}\n"
70
- )
71
- elif output.stderr:
72
- print(output.stderr, file=sys.stderr)
73
- return 0
56
+ if os.path.exists("git_version_info"):
57
+ # we are building from a sdist, without git available, but the git
58
+ # version was recorded in the `git_version_info` file
59
+ with open("git_version_info") as fd:
60
+ n_commits = int(fd.readline().strip())
61
+ git_hash = fd.readline().strip()
74
62
  else:
75
- return int(output.stdout)
63
+ script = os.path.join(ROOT, "..", "..", "scripts", "git-version-info.py")
64
+ assert os.path.exists(script)
65
+
66
+ output = subprocess.run(
67
+ [sys.executable, script, TAG_PREFIX],
68
+ stderr=subprocess.PIPE,
69
+ stdout=subprocess.PIPE,
70
+ encoding="utf8",
71
+ )
72
+
73
+ if output.returncode != 0:
74
+ raise Exception(
75
+ "failed to get git version info.\n"
76
+ f"stdout: {output.stdout}\n"
77
+ f"stderr: {output.stderr}\n"
78
+ )
79
+ elif output.stderr:
80
+ print(output.stderr, file=sys.stderr)
81
+ n_commits = 0
82
+ git_hash = ""
83
+ else:
84
+ lines = output.stdout.splitlines()
85
+ n_commits = int(lines[0].strip())
86
+ git_hash = lines[1].strip()
87
+
88
+ return n_commits, git_hash
76
89
 
77
90
 
78
91
  def create_version_number(version):
79
92
  version = packaging.version.parse(version)
80
93
 
81
- if os.path.exists("n_commits_since_last_tag"):
82
- # we are building from a sdist, without git available, but the git
83
- # version was recorded in the `n_commits_since_last_tag` file
84
- with open("n_commits_since_last_tag") as fd:
85
- n_commits = int(fd.read().strip())
86
- else:
87
- n_commits = n_commits_since_last_tag()
94
+ n_commits, git_hash = git_version_info()
88
95
 
89
96
  if n_commits != 0:
90
97
  # if we have commits since the last tag, this mean we are in a pre-release of
@@ -105,6 +112,7 @@ def create_version_number(version):
105
112
  version._version = version._version._replace(release=release)
106
113
  version._version = version._version._replace(pre=pre)
107
114
  version._version = version._version._replace(dev=("dev", n_commits))
115
+ version._version = version._version._replace(local=(git_hash,))
108
116
 
109
117
  return str(version)
110
118
 
@@ -125,11 +133,7 @@ if __name__ == "__main__":
125
133
 
126
134
  if not METATENSOR_NO_LOCAL_DEPS and os.path.exists(METATENSOR_CORE):
127
135
  # we are building from a git checkout or full repo archive
128
-
129
- # add a random uuid to the file url to prevent pip from using a cached
130
- # wheel for metatensor-core, and force it to re-build from scratch
131
- uuid = uuid.uuid4()
132
- install_requires.append(f"metatensor-core @ file://{METATENSOR_CORE}?{uuid}")
136
+ install_requires.append(f"metatensor-core @ file://{METATENSOR_CORE}")
133
137
  else:
134
138
  # we are building from a sdist/installing from a wheel
135
139
  install_requires.append("metatensor-core >=0.1.10,<0.2.0")