featomic-torch 0.6.0rc2__py3-none-win_amd64.whl → 0.6.2__py3-none-win_amd64.whl
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.
- featomic/torch/_build_versions.py +1 -1
- featomic/torch/system.py +1 -19
- featomic/torch/torch-2.1/bin/featomic_torch.dll +0 -0
- featomic/torch/torch-2.1/lib/cmake/featomic_torch/featomic_torch-config-version.cmake +3 -3
- featomic/torch/torch-2.1/lib/cmake/featomic_torch/featomic_torch-config.cmake +1 -1
- featomic/torch/torch-2.1/lib/cmake/featomic_torch/featomic_torch-targets.cmake +1 -1
- featomic/torch/torch-2.1/lib/featomic_torch.lib +0 -0
- featomic/torch/torch-2.2/bin/featomic_torch.dll +0 -0
- featomic/torch/torch-2.2/lib/cmake/featomic_torch/featomic_torch-config-version.cmake +3 -3
- featomic/torch/torch-2.2/lib/cmake/featomic_torch/featomic_torch-config.cmake +1 -1
- featomic/torch/torch-2.2/lib/cmake/featomic_torch/featomic_torch-targets.cmake +1 -1
- featomic/torch/torch-2.2/lib/featomic_torch.lib +0 -0
- featomic/torch/torch-2.3/bin/featomic_torch.dll +0 -0
- featomic/torch/torch-2.3/lib/cmake/featomic_torch/featomic_torch-config-version.cmake +3 -3
- featomic/torch/torch-2.3/lib/cmake/featomic_torch/featomic_torch-config.cmake +1 -1
- featomic/torch/torch-2.3/lib/cmake/featomic_torch/featomic_torch-targets.cmake +1 -1
- featomic/torch/torch-2.3/lib/featomic_torch.lib +0 -0
- featomic/torch/torch-2.4/bin/featomic_torch.dll +0 -0
- featomic/torch/torch-2.4/lib/cmake/featomic_torch/featomic_torch-config-version.cmake +3 -3
- featomic/torch/torch-2.4/lib/cmake/featomic_torch/featomic_torch-config.cmake +1 -1
- featomic/torch/torch-2.4/lib/cmake/featomic_torch/featomic_torch-targets.cmake +1 -1
- featomic/torch/torch-2.4/lib/featomic_torch.lib +0 -0
- featomic/torch/torch-2.5/bin/featomic_torch.dll +0 -0
- featomic/torch/torch-2.5/lib/cmake/featomic_torch/featomic_torch-config-version.cmake +3 -3
- featomic/torch/torch-2.5/lib/cmake/featomic_torch/featomic_torch-config.cmake +1 -1
- featomic/torch/torch-2.5/lib/cmake/featomic_torch/featomic_torch-targets.cmake +1 -1
- featomic/torch/torch-2.5/lib/featomic_torch.lib +0 -0
- featomic/torch/torch-2.6/bin/featomic_torch.dll +0 -0
- featomic/torch/torch-2.6/include/featomic/torch/autograd.hpp +58 -0
- featomic/torch/torch-2.6/include/featomic/torch/calculator.hpp +134 -0
- featomic/torch/torch-2.6/include/featomic/torch/exports.h +43 -0
- featomic/torch/torch-2.6/include/featomic/torch/system.hpp +112 -0
- featomic/torch/torch-2.6/include/featomic/torch.hpp +10 -0
- featomic/torch/torch-2.6/lib/cmake/featomic_torch/featomic_torch-config-version.cmake +85 -0
- featomic/torch/torch-2.6/lib/cmake/featomic_torch/featomic_torch-config.cmake +28 -0
- featomic/torch/torch-2.6/lib/cmake/featomic_torch/featomic_torch-targets-release.cmake +19 -0
- featomic/torch/torch-2.6/lib/cmake/featomic_torch/featomic_torch-targets.cmake +108 -0
- featomic/torch/torch-2.6/lib/featomic_torch.lib +0 -0
- featomic/torch/torch-2.7/bin/featomic_torch.dll +0 -0
- featomic/torch/torch-2.7/include/featomic/torch/autograd.hpp +58 -0
- featomic/torch/torch-2.7/include/featomic/torch/calculator.hpp +134 -0
- featomic/torch/torch-2.7/include/featomic/torch/exports.h +43 -0
- featomic/torch/torch-2.7/include/featomic/torch/system.hpp +112 -0
- featomic/torch/torch-2.7/include/featomic/torch.hpp +10 -0
- featomic/torch/torch-2.7/lib/cmake/featomic_torch/featomic_torch-config-version.cmake +85 -0
- featomic/torch/torch-2.7/lib/cmake/featomic_torch/featomic_torch-config.cmake +28 -0
- featomic/torch/torch-2.7/lib/cmake/featomic_torch/featomic_torch-targets-release.cmake +19 -0
- featomic/torch/torch-2.7/lib/cmake/featomic_torch/featomic_torch-targets.cmake +108 -0
- featomic/torch/torch-2.7/lib/featomic_torch.lib +0 -0
- {featomic_torch-0.6.0rc2.dist-info → featomic_torch-0.6.2.dist-info}/METADATA +9 -7
- featomic_torch-0.6.2.dist-info/RECORD +91 -0
- {featomic_torch-0.6.0rc2.dist-info → featomic_torch-0.6.2.dist-info}/WHEEL +1 -1
- featomic_torch-0.6.0rc2.dist-info/RECORD +0 -69
- {featomic_torch-0.6.0rc2.dist-info → featomic_torch-0.6.2.dist-info/licenses}/AUTHORS +0 -0
- {featomic_torch-0.6.0rc2.dist-info → featomic_torch-0.6.2.dist-info/licenses}/LICENSE +0 -0
- {featomic_torch-0.6.0rc2.dist-info → featomic_torch-0.6.2.dist-info}/top_level.txt +0 -0
featomic/torch/system.py
CHANGED
|
@@ -85,22 +85,4 @@ def _is_torch_system(system):
|
|
|
85
85
|
if not isinstance(system, torch.ScriptObject):
|
|
86
86
|
return False
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
if torch_version_tuple >= (2, 1):
|
|
90
|
-
return system._type().name() == "System"
|
|
91
|
-
|
|
92
|
-
# For older torch version, we check that we have the right properties
|
|
93
|
-
properties = system._properties()
|
|
94
|
-
if len(properties) != 3:
|
|
95
|
-
return False
|
|
96
|
-
|
|
97
|
-
if properties[0].name != "species":
|
|
98
|
-
return False
|
|
99
|
-
|
|
100
|
-
if properties[1].name != "positions":
|
|
101
|
-
return False
|
|
102
|
-
|
|
103
|
-
if properties[2].name != "cell":
|
|
104
|
-
return False
|
|
105
|
-
|
|
106
|
-
return True
|
|
88
|
+
return system._type().name() == "System"
|
|
Binary file
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
# The variable CVF_VERSION must be set before calling configure_file().
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
set(PACKAGE_VERSION "0.6.
|
|
13
|
+
set(PACKAGE_VERSION "0.6.2")
|
|
14
14
|
|
|
15
15
|
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
|
16
16
|
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
|
17
17
|
else()
|
|
18
18
|
|
|
19
|
-
if("0.6.
|
|
19
|
+
if("0.6.2" MATCHES "^([0-9]+)\\.([0-9]+)")
|
|
20
20
|
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
|
21
21
|
set(CVF_VERSION_MINOR "${CMAKE_MATCH_2}")
|
|
22
22
|
|
|
@@ -27,7 +27,7 @@ else()
|
|
|
27
27
|
string(REGEX REPLACE "^0+" "" CVF_VERSION_MINOR "${CVF_VERSION_MINOR}")
|
|
28
28
|
endif()
|
|
29
29
|
else()
|
|
30
|
-
set(CVF_VERSION_MAJOR "0.6.
|
|
30
|
+
set(CVF_VERSION_MAJOR "0.6.2")
|
|
31
31
|
set(CVF_VERSION_MINOR "")
|
|
32
32
|
endif()
|
|
33
33
|
|
|
@@ -5,7 +5,7 @@ set(REQUIRED_FEATOMIC_VERSION 0.6)
|
|
|
5
5
|
find_package(featomic ${REQUIRED_FEATOMIC_VERSION} CONFIG REQUIRED)
|
|
6
6
|
|
|
7
7
|
# use the same version for metatensor_torch as the main CMakeLists.txt
|
|
8
|
-
set(REQUIRED_METATENSOR_TORCH_VERSION 0.
|
|
8
|
+
set(REQUIRED_METATENSOR_TORCH_VERSION 0.7)
|
|
9
9
|
find_package(metatensor_torch ${REQUIRED_METATENSOR_TORCH_VERSION} CONFIG REQUIRED)
|
|
10
10
|
|
|
11
11
|
# We can only load metatensorfeatomic_torch with the same minor version of Torch
|
|
@@ -7,7 +7,7 @@ if(CMAKE_VERSION VERSION_LESS "2.8.12")
|
|
|
7
7
|
message(FATAL_ERROR "CMake >= 2.8.12 required")
|
|
8
8
|
endif()
|
|
9
9
|
cmake_policy(PUSH)
|
|
10
|
-
cmake_policy(VERSION 2.8.12...3.
|
|
10
|
+
cmake_policy(VERSION 2.8.12...3.30)
|
|
11
11
|
#----------------------------------------------------------------
|
|
12
12
|
# Generated CMake target import file.
|
|
13
13
|
#----------------------------------------------------------------
|
|
Binary file
|
|
Binary file
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
# The variable CVF_VERSION must be set before calling configure_file().
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
set(PACKAGE_VERSION "0.6.
|
|
13
|
+
set(PACKAGE_VERSION "0.6.2")
|
|
14
14
|
|
|
15
15
|
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
|
16
16
|
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
|
17
17
|
else()
|
|
18
18
|
|
|
19
|
-
if("0.6.
|
|
19
|
+
if("0.6.2" MATCHES "^([0-9]+)\\.([0-9]+)")
|
|
20
20
|
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
|
21
21
|
set(CVF_VERSION_MINOR "${CMAKE_MATCH_2}")
|
|
22
22
|
|
|
@@ -27,7 +27,7 @@ else()
|
|
|
27
27
|
string(REGEX REPLACE "^0+" "" CVF_VERSION_MINOR "${CVF_VERSION_MINOR}")
|
|
28
28
|
endif()
|
|
29
29
|
else()
|
|
30
|
-
set(CVF_VERSION_MAJOR "0.6.
|
|
30
|
+
set(CVF_VERSION_MAJOR "0.6.2")
|
|
31
31
|
set(CVF_VERSION_MINOR "")
|
|
32
32
|
endif()
|
|
33
33
|
|
|
@@ -5,7 +5,7 @@ set(REQUIRED_FEATOMIC_VERSION 0.6)
|
|
|
5
5
|
find_package(featomic ${REQUIRED_FEATOMIC_VERSION} CONFIG REQUIRED)
|
|
6
6
|
|
|
7
7
|
# use the same version for metatensor_torch as the main CMakeLists.txt
|
|
8
|
-
set(REQUIRED_METATENSOR_TORCH_VERSION 0.
|
|
8
|
+
set(REQUIRED_METATENSOR_TORCH_VERSION 0.7)
|
|
9
9
|
find_package(metatensor_torch ${REQUIRED_METATENSOR_TORCH_VERSION} CONFIG REQUIRED)
|
|
10
10
|
|
|
11
11
|
# We can only load metatensorfeatomic_torch with the same minor version of Torch
|
|
@@ -7,7 +7,7 @@ if(CMAKE_VERSION VERSION_LESS "2.8.12")
|
|
|
7
7
|
message(FATAL_ERROR "CMake >= 2.8.12 required")
|
|
8
8
|
endif()
|
|
9
9
|
cmake_policy(PUSH)
|
|
10
|
-
cmake_policy(VERSION 2.8.12...3.
|
|
10
|
+
cmake_policy(VERSION 2.8.12...3.30)
|
|
11
11
|
#----------------------------------------------------------------
|
|
12
12
|
# Generated CMake target import file.
|
|
13
13
|
#----------------------------------------------------------------
|
|
Binary file
|
|
Binary file
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
# The variable CVF_VERSION must be set before calling configure_file().
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
set(PACKAGE_VERSION "0.6.
|
|
13
|
+
set(PACKAGE_VERSION "0.6.2")
|
|
14
14
|
|
|
15
15
|
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
|
16
16
|
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
|
17
17
|
else()
|
|
18
18
|
|
|
19
|
-
if("0.6.
|
|
19
|
+
if("0.6.2" MATCHES "^([0-9]+)\\.([0-9]+)")
|
|
20
20
|
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
|
21
21
|
set(CVF_VERSION_MINOR "${CMAKE_MATCH_2}")
|
|
22
22
|
|
|
@@ -27,7 +27,7 @@ else()
|
|
|
27
27
|
string(REGEX REPLACE "^0+" "" CVF_VERSION_MINOR "${CVF_VERSION_MINOR}")
|
|
28
28
|
endif()
|
|
29
29
|
else()
|
|
30
|
-
set(CVF_VERSION_MAJOR "0.6.
|
|
30
|
+
set(CVF_VERSION_MAJOR "0.6.2")
|
|
31
31
|
set(CVF_VERSION_MINOR "")
|
|
32
32
|
endif()
|
|
33
33
|
|
|
@@ -5,7 +5,7 @@ set(REQUIRED_FEATOMIC_VERSION 0.6)
|
|
|
5
5
|
find_package(featomic ${REQUIRED_FEATOMIC_VERSION} CONFIG REQUIRED)
|
|
6
6
|
|
|
7
7
|
# use the same version for metatensor_torch as the main CMakeLists.txt
|
|
8
|
-
set(REQUIRED_METATENSOR_TORCH_VERSION 0.
|
|
8
|
+
set(REQUIRED_METATENSOR_TORCH_VERSION 0.7)
|
|
9
9
|
find_package(metatensor_torch ${REQUIRED_METATENSOR_TORCH_VERSION} CONFIG REQUIRED)
|
|
10
10
|
|
|
11
11
|
# We can only load metatensorfeatomic_torch with the same minor version of Torch
|
|
@@ -7,7 +7,7 @@ if(CMAKE_VERSION VERSION_LESS "2.8.12")
|
|
|
7
7
|
message(FATAL_ERROR "CMake >= 2.8.12 required")
|
|
8
8
|
endif()
|
|
9
9
|
cmake_policy(PUSH)
|
|
10
|
-
cmake_policy(VERSION 2.8.12...3.
|
|
10
|
+
cmake_policy(VERSION 2.8.12...3.30)
|
|
11
11
|
#----------------------------------------------------------------
|
|
12
12
|
# Generated CMake target import file.
|
|
13
13
|
#----------------------------------------------------------------
|
|
Binary file
|
|
Binary file
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
# The variable CVF_VERSION must be set before calling configure_file().
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
set(PACKAGE_VERSION "0.6.
|
|
13
|
+
set(PACKAGE_VERSION "0.6.2")
|
|
14
14
|
|
|
15
15
|
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
|
16
16
|
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
|
17
17
|
else()
|
|
18
18
|
|
|
19
|
-
if("0.6.
|
|
19
|
+
if("0.6.2" MATCHES "^([0-9]+)\\.([0-9]+)")
|
|
20
20
|
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
|
21
21
|
set(CVF_VERSION_MINOR "${CMAKE_MATCH_2}")
|
|
22
22
|
|
|
@@ -27,7 +27,7 @@ else()
|
|
|
27
27
|
string(REGEX REPLACE "^0+" "" CVF_VERSION_MINOR "${CVF_VERSION_MINOR}")
|
|
28
28
|
endif()
|
|
29
29
|
else()
|
|
30
|
-
set(CVF_VERSION_MAJOR "0.6.
|
|
30
|
+
set(CVF_VERSION_MAJOR "0.6.2")
|
|
31
31
|
set(CVF_VERSION_MINOR "")
|
|
32
32
|
endif()
|
|
33
33
|
|
|
@@ -5,7 +5,7 @@ set(REQUIRED_FEATOMIC_VERSION 0.6)
|
|
|
5
5
|
find_package(featomic ${REQUIRED_FEATOMIC_VERSION} CONFIG REQUIRED)
|
|
6
6
|
|
|
7
7
|
# use the same version for metatensor_torch as the main CMakeLists.txt
|
|
8
|
-
set(REQUIRED_METATENSOR_TORCH_VERSION 0.
|
|
8
|
+
set(REQUIRED_METATENSOR_TORCH_VERSION 0.7)
|
|
9
9
|
find_package(metatensor_torch ${REQUIRED_METATENSOR_TORCH_VERSION} CONFIG REQUIRED)
|
|
10
10
|
|
|
11
11
|
# We can only load metatensorfeatomic_torch with the same minor version of Torch
|
|
@@ -7,7 +7,7 @@ if(CMAKE_VERSION VERSION_LESS "2.8.12")
|
|
|
7
7
|
message(FATAL_ERROR "CMake >= 2.8.12 required")
|
|
8
8
|
endif()
|
|
9
9
|
cmake_policy(PUSH)
|
|
10
|
-
cmake_policy(VERSION 2.8.12...3.
|
|
10
|
+
cmake_policy(VERSION 2.8.12...3.30)
|
|
11
11
|
#----------------------------------------------------------------
|
|
12
12
|
# Generated CMake target import file.
|
|
13
13
|
#----------------------------------------------------------------
|
|
Binary file
|
|
Binary file
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
# The variable CVF_VERSION must be set before calling configure_file().
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
set(PACKAGE_VERSION "0.6.
|
|
13
|
+
set(PACKAGE_VERSION "0.6.2")
|
|
14
14
|
|
|
15
15
|
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
|
|
16
16
|
set(PACKAGE_VERSION_COMPATIBLE FALSE)
|
|
17
17
|
else()
|
|
18
18
|
|
|
19
|
-
if("0.6.
|
|
19
|
+
if("0.6.2" MATCHES "^([0-9]+)\\.([0-9]+)")
|
|
20
20
|
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
|
|
21
21
|
set(CVF_VERSION_MINOR "${CMAKE_MATCH_2}")
|
|
22
22
|
|
|
@@ -27,7 +27,7 @@ else()
|
|
|
27
27
|
string(REGEX REPLACE "^0+" "" CVF_VERSION_MINOR "${CVF_VERSION_MINOR}")
|
|
28
28
|
endif()
|
|
29
29
|
else()
|
|
30
|
-
set(CVF_VERSION_MAJOR "0.6.
|
|
30
|
+
set(CVF_VERSION_MAJOR "0.6.2")
|
|
31
31
|
set(CVF_VERSION_MINOR "")
|
|
32
32
|
endif()
|
|
33
33
|
|
|
@@ -5,7 +5,7 @@ set(REQUIRED_FEATOMIC_VERSION 0.6)
|
|
|
5
5
|
find_package(featomic ${REQUIRED_FEATOMIC_VERSION} CONFIG REQUIRED)
|
|
6
6
|
|
|
7
7
|
# use the same version for metatensor_torch as the main CMakeLists.txt
|
|
8
|
-
set(REQUIRED_METATENSOR_TORCH_VERSION 0.
|
|
8
|
+
set(REQUIRED_METATENSOR_TORCH_VERSION 0.7)
|
|
9
9
|
find_package(metatensor_torch ${REQUIRED_METATENSOR_TORCH_VERSION} CONFIG REQUIRED)
|
|
10
10
|
|
|
11
11
|
# We can only load metatensorfeatomic_torch with the same minor version of Torch
|
|
@@ -7,7 +7,7 @@ if(CMAKE_VERSION VERSION_LESS "2.8.12")
|
|
|
7
7
|
message(FATAL_ERROR "CMake >= 2.8.12 required")
|
|
8
8
|
endif()
|
|
9
9
|
cmake_policy(PUSH)
|
|
10
|
-
cmake_policy(VERSION 2.8.12...3.
|
|
10
|
+
cmake_policy(VERSION 2.8.12...3.30)
|
|
11
11
|
#----------------------------------------------------------------
|
|
12
12
|
# Generated CMake target import file.
|
|
13
13
|
#----------------------------------------------------------------
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// IWYU pragma: private; include "featomic/torch.hpp"
|
|
2
|
+
|
|
3
|
+
#ifndef FEATOMIC_TORCH_AUTOGRAD_HPP
|
|
4
|
+
#define FEATOMIC_TORCH_AUTOGRAD_HPP
|
|
5
|
+
|
|
6
|
+
#include <ATen/core/ivalue.h>
|
|
7
|
+
#include <torch/autograd.h>
|
|
8
|
+
|
|
9
|
+
#include <metatensor/torch.hpp>
|
|
10
|
+
|
|
11
|
+
#include "featomic/torch/exports.h"
|
|
12
|
+
|
|
13
|
+
namespace featomic_torch {
|
|
14
|
+
|
|
15
|
+
/// Custom torch::autograd::Function integrating featomic with torch autograd.
|
|
16
|
+
///
|
|
17
|
+
/// This is a bit more complex than your typical autograd because there is some
|
|
18
|
+
/// impedance mismatch between featomic and torch. Most of it should be taken
|
|
19
|
+
/// care of by the `compute` function below.
|
|
20
|
+
class FEATOMIC_TORCH_EXPORT FeatomicAutograd: public torch::autograd::Function<FeatomicAutograd> {
|
|
21
|
+
public:
|
|
22
|
+
/// Register a pseudo node in Torch's computational graph going from
|
|
23
|
+
/// `all_positions` and `all_cell` to the values in `block`; using the
|
|
24
|
+
/// pre-computed gradients in `block`.
|
|
25
|
+
///
|
|
26
|
+
/// If `all_positions.requires_grad` is True, `block` must have a
|
|
27
|
+
/// `"positions"` gradient; and `systems_start` should contain the index of
|
|
28
|
+
/// the first atom of each system in `all_positions`.
|
|
29
|
+
///
|
|
30
|
+
/// If `all_cells.requires_grad` is True, `block` must have a `"cell"`
|
|
31
|
+
/// gradient, and the block samples must contain a `"stucture"` dimension.
|
|
32
|
+
///
|
|
33
|
+
/// This function returns a vector with one element corresponding to
|
|
34
|
+
/// `block.values`, which should be left unused. It is only there to make
|
|
35
|
+
/// sure torch registers a `grad_fn` for the tensors stored inside the
|
|
36
|
+
/// TensorBlock (the values in the TensorBlock are references to the ones
|
|
37
|
+
/// returned by this function, so when a `grad_fn` is added to one, it is
|
|
38
|
+
/// also added to the other).
|
|
39
|
+
static std::vector<torch::Tensor> forward(
|
|
40
|
+
torch::autograd::AutogradContext *ctx,
|
|
41
|
+
torch::Tensor all_positions,
|
|
42
|
+
torch::Tensor all_cells,
|
|
43
|
+
torch::IValue systems_start,
|
|
44
|
+
metatensor_torch::TorchTensorBlock block
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
/// Backward step: get the gradients of some quantity `A` w.r.t. the outputs
|
|
48
|
+
/// of `forward`; and compute the gradients of the same quantity `A` w.r.t.
|
|
49
|
+
/// the inputs of `forward` (i.e. cell and positions).
|
|
50
|
+
static std::vector<torch::Tensor> backward(
|
|
51
|
+
torch::autograd::AutogradContext *ctx,
|
|
52
|
+
std::vector<torch::Tensor> grad_outputs
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#endif
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#ifndef FEATOMIC_TORCH_CALCULATOR_HPP
|
|
2
|
+
#define FEATOMIC_TORCH_CALCULATOR_HPP
|
|
3
|
+
|
|
4
|
+
#include <torch/script.h>
|
|
5
|
+
|
|
6
|
+
#include <featomic.hpp>
|
|
7
|
+
#include <metatensor/torch.hpp>
|
|
8
|
+
#include <metatensor/torch/atomistic.hpp>
|
|
9
|
+
|
|
10
|
+
#include "featomic/torch/exports.h"
|
|
11
|
+
|
|
12
|
+
namespace featomic_torch {
|
|
13
|
+
class FeatomicAutograd;
|
|
14
|
+
|
|
15
|
+
class CalculatorHolder;
|
|
16
|
+
using TorchCalculator = torch::intrusive_ptr<CalculatorHolder>;
|
|
17
|
+
|
|
18
|
+
class CalculatorOptionsHolder;
|
|
19
|
+
using TorchCalculatorOptions = torch::intrusive_ptr<CalculatorOptionsHolder>;
|
|
20
|
+
|
|
21
|
+
/// Options for a single calculation
|
|
22
|
+
class FEATOMIC_TORCH_EXPORT CalculatorOptionsHolder: public torch::CustomClassHolder {
|
|
23
|
+
public:
|
|
24
|
+
/// get the current selected samples
|
|
25
|
+
torch::IValue selected_samples() const {
|
|
26
|
+
return selected_samples_;
|
|
27
|
+
}
|
|
28
|
+
/// Set the selected samples to `selection`.
|
|
29
|
+
///
|
|
30
|
+
/// The `IValue` can be `None` (no selection), an instance of
|
|
31
|
+
/// `metatensor_torch::TorchLabels`, or an instance of
|
|
32
|
+
/// `metatensor_torch::TorchTensorMap`.
|
|
33
|
+
void set_selected_samples(torch::IValue selection);
|
|
34
|
+
|
|
35
|
+
/// Get the selected samples in the format used by featomic
|
|
36
|
+
featomic::LabelsSelection selected_samples_featomic() const;
|
|
37
|
+
|
|
38
|
+
/// get the current selected properties
|
|
39
|
+
torch::IValue selected_properties() const {
|
|
40
|
+
return selected_properties_;
|
|
41
|
+
}
|
|
42
|
+
/// Set the selected properties to `selection`.
|
|
43
|
+
///
|
|
44
|
+
/// The `IValue` can be `None` (no selection), an instance of
|
|
45
|
+
/// `metatensor_torch::TorchLabels`, or an instance of
|
|
46
|
+
/// `metatensor_torch::TorchTensorMap`.
|
|
47
|
+
void set_selected_properties(torch::IValue selection);
|
|
48
|
+
|
|
49
|
+
/// Get the selected properties in the format used by featomic
|
|
50
|
+
featomic::LabelsSelection selected_properties_featomic() const;
|
|
51
|
+
|
|
52
|
+
/// get the current selected keys
|
|
53
|
+
torch::IValue selected_keys() const {
|
|
54
|
+
return selected_keys_;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Set the selected properties to `selection`.
|
|
58
|
+
///
|
|
59
|
+
/// The `IValue` can be `None` (no selection), or an instance of
|
|
60
|
+
/// `metatensor_torch::TorchLabels`.
|
|
61
|
+
void set_selected_keys(torch::IValue selection);
|
|
62
|
+
|
|
63
|
+
/// which gradients to keep in the output of a calculation
|
|
64
|
+
std::vector<std::string> gradients = {};
|
|
65
|
+
|
|
66
|
+
private:
|
|
67
|
+
torch::IValue selected_samples_ = torch::IValue();
|
|
68
|
+
torch::IValue selected_properties_ = torch::IValue();
|
|
69
|
+
torch::IValue selected_keys_ = torch::IValue();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/// Custom class holder to store, serialize and load featomic calculators
|
|
73
|
+
/// inside Torch(Script) modules.
|
|
74
|
+
class FEATOMIC_TORCH_EXPORT CalculatorHolder: public torch::CustomClassHolder {
|
|
75
|
+
public:
|
|
76
|
+
/// Create a new calculator with the given `name` and JSON `parameters`
|
|
77
|
+
CalculatorHolder(std::string name, std::string parameters):
|
|
78
|
+
c_name_(std::move(name)),
|
|
79
|
+
calculator_(c_name_, std::move(parameters))
|
|
80
|
+
{}
|
|
81
|
+
|
|
82
|
+
/// Get the name of this calculator
|
|
83
|
+
std::string name() const {
|
|
84
|
+
return calculator_.name();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// Get the name used to register this calculator
|
|
88
|
+
std::string c_name() const {
|
|
89
|
+
return c_name_;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// Get the parameters of this calculator
|
|
93
|
+
std::string parameters() const {
|
|
94
|
+
return calculator_.parameters();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// Get all radial cutoffs used by this `Calculator`'s neighbors lists
|
|
98
|
+
std::vector<double> cutoffs() const {
|
|
99
|
+
return calculator_.cutoffs();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// Run a calculation for the given `systems` using the given options
|
|
103
|
+
metatensor_torch::TorchTensorMap compute(
|
|
104
|
+
std::vector<metatensor_torch::System> systems,
|
|
105
|
+
TorchCalculatorOptions options = {}
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
private:
|
|
109
|
+
std::string c_name_;
|
|
110
|
+
featomic::Calculator calculator_;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
/// Register autograd nodes between `system.positions` and `system.cell` for
|
|
115
|
+
/// each of the systems and the values in the `precomputed` TensorMap.
|
|
116
|
+
///
|
|
117
|
+
/// This is an advanced function must users should not need to use.
|
|
118
|
+
///
|
|
119
|
+
/// The autograd nodes `backward()` function will use the gradients already
|
|
120
|
+
/// stored in `precomputed`, meaning that if any of the system's positions
|
|
121
|
+
/// `requires_grad`, `precomputed` must contain `"positions"` gradients.
|
|
122
|
+
/// Similarly, if any of the system's cell `requires_grad`, `precomputed` must
|
|
123
|
+
/// contain `"cell"` gradients.
|
|
124
|
+
///
|
|
125
|
+
/// `forward_gradients` controls which gradients are left inside the TensorMap.
|
|
126
|
+
metatensor_torch::TorchTensorMap FEATOMIC_TORCH_EXPORT register_autograd(
|
|
127
|
+
std::vector<metatensor_torch::System> systems,
|
|
128
|
+
metatensor_torch::TorchTensorMap precomputed,
|
|
129
|
+
std::vector<std::string> forward_gradients
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#endif
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef FEATOMIC_TORCH_EXPORT_H
|
|
3
|
+
#define FEATOMIC_TORCH_EXPORT_H
|
|
4
|
+
|
|
5
|
+
#ifdef FEATOMIC_TORCH_STATIC_DEFINE
|
|
6
|
+
# define FEATOMIC_TORCH_EXPORT
|
|
7
|
+
# define FEATOMIC_TORCH_NO_EXPORT
|
|
8
|
+
#else
|
|
9
|
+
# ifndef FEATOMIC_TORCH_EXPORT
|
|
10
|
+
# ifdef featomic_torch_EXPORTS
|
|
11
|
+
/* We are building this library */
|
|
12
|
+
# define FEATOMIC_TORCH_EXPORT __declspec(dllexport)
|
|
13
|
+
# else
|
|
14
|
+
/* We are using this library */
|
|
15
|
+
# define FEATOMIC_TORCH_EXPORT __declspec(dllimport)
|
|
16
|
+
# endif
|
|
17
|
+
# endif
|
|
18
|
+
|
|
19
|
+
# ifndef FEATOMIC_TORCH_NO_EXPORT
|
|
20
|
+
# define FEATOMIC_TORCH_NO_EXPORT
|
|
21
|
+
# endif
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#ifndef FEATOMIC_TORCH_DEPRECATED
|
|
25
|
+
# define FEATOMIC_TORCH_DEPRECATED __declspec(deprecated)
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
#ifndef FEATOMIC_TORCH_DEPRECATED_EXPORT
|
|
29
|
+
# define FEATOMIC_TORCH_DEPRECATED_EXPORT FEATOMIC_TORCH_EXPORT FEATOMIC_TORCH_DEPRECATED
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#ifndef FEATOMIC_TORCH_DEPRECATED_NO_EXPORT
|
|
33
|
+
# define FEATOMIC_TORCH_DEPRECATED_NO_EXPORT FEATOMIC_TORCH_NO_EXPORT FEATOMIC_TORCH_DEPRECATED
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
/* NOLINTNEXTLINE(readability-avoid-unconditional-preprocessor-if) */
|
|
37
|
+
#if 0 /* DEFINE_NO_DEPRECATED */
|
|
38
|
+
# ifndef FEATOMIC_TORCH_NO_DEPRECATED
|
|
39
|
+
# define FEATOMIC_TORCH_NO_DEPRECATED
|
|
40
|
+
# endif
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
#endif /* FEATOMIC_TORCH_EXPORT_H */
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#ifndef FEATOMIC_TORCH_SYSTEM_HPP
|
|
2
|
+
#define FEATOMIC_TORCH_SYSTEM_HPP
|
|
3
|
+
|
|
4
|
+
#include <vector>
|
|
5
|
+
#include <map>
|
|
6
|
+
|
|
7
|
+
#include <torch/script.h>
|
|
8
|
+
|
|
9
|
+
#include <featomic.hpp>
|
|
10
|
+
#include <metatensor/torch/atomistic.hpp>
|
|
11
|
+
|
|
12
|
+
#include "featomic/torch/exports.h"
|
|
13
|
+
|
|
14
|
+
namespace featomic_torch {
|
|
15
|
+
|
|
16
|
+
/// Implementation of `featomic::System` using `metatensor_torch::System` as
|
|
17
|
+
/// backing memory for all the data.
|
|
18
|
+
///
|
|
19
|
+
/// This can either be used with the Rust neighbor list implementation; or a set
|
|
20
|
+
/// of pre-computed neighbor lists can be added to the system.
|
|
21
|
+
class FEATOMIC_TORCH_EXPORT SystemAdapter final: public featomic::System {
|
|
22
|
+
public:
|
|
23
|
+
/// Create a `SystemAdapter` wrapping an existing `metatensor_torch::System`
|
|
24
|
+
SystemAdapter(metatensor_torch::System system);
|
|
25
|
+
|
|
26
|
+
~SystemAdapter() override = default;
|
|
27
|
+
|
|
28
|
+
/// `SystemAdapter` is copy-constructible
|
|
29
|
+
SystemAdapter(const SystemAdapter&) = default;
|
|
30
|
+
/// `SystemAdapter` is move-constructible
|
|
31
|
+
SystemAdapter(SystemAdapter&&) = default;
|
|
32
|
+
|
|
33
|
+
/// `SystemAdapter` can be copy-assigned
|
|
34
|
+
SystemAdapter& operator=(const SystemAdapter&) = default;
|
|
35
|
+
/// `SystemAdapter` can be move-assigned
|
|
36
|
+
SystemAdapter& operator=(SystemAdapter&&) = default;
|
|
37
|
+
|
|
38
|
+
/*========================================================================*/
|
|
39
|
+
/* Functions to implement featomic::System */
|
|
40
|
+
/*========================================================================*/
|
|
41
|
+
|
|
42
|
+
/// @private
|
|
43
|
+
uintptr_t size() const override {
|
|
44
|
+
return static_cast<uintptr_t>(types_.size(0));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// @private
|
|
48
|
+
const int32_t* types() const override {
|
|
49
|
+
return types_.data_ptr<int32_t>();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// @private
|
|
53
|
+
const double* positions() const override {
|
|
54
|
+
return positions_.data_ptr<double>();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// @private
|
|
58
|
+
CellMatrix cell() const override {
|
|
59
|
+
auto* data = cell_.data_ptr<double>();
|
|
60
|
+
return CellMatrix{{
|
|
61
|
+
{{data[0], data[1], data[2]}},
|
|
62
|
+
{{data[3], data[4], data[5]}},
|
|
63
|
+
{{data[6], data[7], data[8]}},
|
|
64
|
+
}};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// @private
|
|
68
|
+
void compute_neighbors(double cutoff) override;
|
|
69
|
+
|
|
70
|
+
/// @private
|
|
71
|
+
const std::vector<featomic_pair_t>& pairs() const override;
|
|
72
|
+
|
|
73
|
+
/// @private
|
|
74
|
+
const std::vector<featomic_pair_t>& pairs_containing(uintptr_t atom) const override;
|
|
75
|
+
|
|
76
|
+
/*========================================================================*/
|
|
77
|
+
/* Functions to re-use pre-computed pairs */
|
|
78
|
+
/*========================================================================*/
|
|
79
|
+
|
|
80
|
+
/// Should we copy data to featomic internal data structure and compute the
|
|
81
|
+
/// neighbor list there? This is set to `true` by default, or `false` if
|
|
82
|
+
/// a neighbor list has been added with `set_precomputed_pairs`.
|
|
83
|
+
bool use_native_system() const;
|
|
84
|
+
|
|
85
|
+
private:
|
|
86
|
+
// the origin of all the data
|
|
87
|
+
metatensor_torch::System system_;
|
|
88
|
+
|
|
89
|
+
/// atomic types tensor, contiguous and on CPU
|
|
90
|
+
torch::Tensor types_;
|
|
91
|
+
/// positions tensor, contiguous, on CPU and with dtype=float64
|
|
92
|
+
torch::Tensor positions_;
|
|
93
|
+
/// cell tensor, contiguous, on CPU and with dtype=float64
|
|
94
|
+
torch::Tensor cell_;
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
struct PrecomputedPairs {
|
|
98
|
+
std::vector<featomic_pair_t> pairs_;
|
|
99
|
+
std::vector<std::vector<featomic_pair_t>> pairs_by_atom_;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
void set_precomputed_pairs(double cutoff, std::vector<featomic_pair_t> pairs);
|
|
103
|
+
|
|
104
|
+
// all precomputed pairs we know about
|
|
105
|
+
std::map<double, PrecomputedPairs> precomputed_pairs_;
|
|
106
|
+
// last custom requested by `compute_neighbors`
|
|
107
|
+
double last_cutoff_ = -1.0;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#endif
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#ifndef FEATOMIC_TORCH_HPP
|
|
2
|
+
#define FEATOMIC_TORCH_HPP
|
|
3
|
+
|
|
4
|
+
#include "featomic/torch/exports.h" // IWYU pragma: export
|
|
5
|
+
|
|
6
|
+
#include "featomic/torch/system.hpp" // IWYU pragma: export
|
|
7
|
+
#include "featomic/torch/calculator.hpp" // IWYU pragma: export
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
#endif
|