kernelforge 0.3.1.dev51__cp315-cp315-macosx_26_0_arm64.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.
Files changed (53) hide show
  1. kernelforge/.dylibs/libomp.dylib +0 -0
  2. kernelforge/__init__.py +73 -0
  3. kernelforge/_cuda_hints.py +10 -0
  4. kernelforge/ase_calculator.py +174 -0
  5. kernelforge/cli.py +2259 -0
  6. kernelforge/cuda_fchl18_kernel.pyi +454 -0
  7. kernelforge/cuda_fchl18_repr.pyi +32 -0
  8. kernelforge/cuda_fchl19_repr.pyi +103 -0
  9. kernelforge/cuda_global_kernels.pyi +177 -0
  10. kernelforge/cuda_invdist_repr.pyi +51 -0
  11. kernelforge/cuda_local_kernels.pyi +376 -0
  12. kernelforge/cuda_rff_features.pyi +173 -0
  13. kernelforge/cuda_solvers.pyi +73 -0
  14. kernelforge/fchl18_kernel.cpython-315-darwin.so +0 -0
  15. kernelforge/fchl18_kernel.pyi +400 -0
  16. kernelforge/fchl18_repr.cpython-315-darwin.so +0 -0
  17. kernelforge/fchl18_repr.pyi +35 -0
  18. kernelforge/fchl19_repr.cpython-315-darwin.so +0 -0
  19. kernelforge/fchl19_repr.pyi +36 -0
  20. kernelforge/fchl19v2_repr.cpython-315-darwin.so +0 -0
  21. kernelforge/fchl19v2_repr.pyi +67 -0
  22. kernelforge/global_kernels.cpython-315-darwin.so +0 -0
  23. kernelforge/global_kernels.pyi +85 -0
  24. kernelforge/invdist_repr.cpython-315-darwin.so +0 -0
  25. kernelforge/invdist_repr.pyi +9 -0
  26. kernelforge/kernelcli.py +1034 -0
  27. kernelforge/kernelmath.cpython-315-darwin.so +0 -0
  28. kernelforge/kernelmath.pyi +46 -0
  29. kernelforge/kernelmd.py +255 -0
  30. kernelforge/kitchen_sinks.cpython-315-darwin.so +0 -0
  31. kernelforge/kitchen_sinks.pyi +146 -0
  32. kernelforge/local_kernels.cpython-315-darwin.so +0 -0
  33. kernelforge/local_kernels.pyi +218 -0
  34. kernelforge/md.py +189 -0
  35. kernelforge/models/__init__.py +60 -0
  36. kernelforge/models/base.py +424 -0
  37. kernelforge/models/cuda_fchl18_krr.py +407 -0
  38. kernelforge/models/cuda_global_krr.py +564 -0
  39. kernelforge/models/cuda_global_rff.py +377 -0
  40. kernelforge/models/cuda_local_krr.py +1085 -0
  41. kernelforge/models/cuda_local_rff.py +889 -0
  42. kernelforge/models/fchl18_krr.py +295 -0
  43. kernelforge/models/global_krr.py +313 -0
  44. kernelforge/models/global_rff.py +248 -0
  45. kernelforge/models/krr.py +324 -0
  46. kernelforge/models/representations.py +201 -0
  47. kernelforge/models/rff.py +299 -0
  48. kernelforge/py.typed +0 -0
  49. kernelforge-0.3.1.dev51.dist-info/METADATA +318 -0
  50. kernelforge-0.3.1.dev51.dist-info/RECORD +53 -0
  51. kernelforge-0.3.1.dev51.dist-info/WHEEL +6 -0
  52. kernelforge-0.3.1.dev51.dist-info/entry_points.txt +5 -0
  53. kernelforge-0.3.1.dev51.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,177 @@
1
+ """Type stub for the cuda_global_kernels CUDA extension module.
2
+
3
+ cuda_global_kernels is built only when both a CUDA compiler and PyTorch
4
+ are available at build time. Import it with a try/except guard.
5
+
6
+ All tensors must be float32 and on the same CUDA device.
7
+ """
8
+
9
+ import torch
10
+
11
+ def kernel_gaussian_full_symm(
12
+ X: torch.Tensor, # (N, M) float32 CUDA
13
+ dX: torch.Tensor, # (N, D, M) float32 CUDA
14
+ sigma: float,
15
+ ) -> torch.Tensor:
16
+ """Build the symmetric energy+force training kernel matrix on GPU.
17
+
18
+ Parameters
19
+ ----------
20
+ X : torch.Tensor, shape (N, M), float32 CUDA
21
+ Training descriptors.
22
+ dX : torch.Tensor, shape (N, D, M), float32 CUDA
23
+ Training Jacobians.
24
+ sigma : float
25
+ Gaussian length-scale.
26
+
27
+ Returns
28
+ -------
29
+ K_full : torch.Tensor, shape (N*(1+D), N*(1+D)), float32 CUDA
30
+ Fully symmetric kernel matrix (both triangles filled).
31
+
32
+ Block layout (full = N*(1+D)):
33
+ K_full[0:N, 0:N] -- scalar K_EE[a,b] = exp(-||x_a-x_b||^2/(2*sigma^2))
34
+ K_full[N:, 0:N] -- Jacobian K_FE[a*D+d, b]
35
+ K_full[0:N, N:] -- Jacobian K_EF (transpose of K_FE)
36
+ K_full[N:, N:] -- Hessian K_FF[a*D+d1, b*D+d2]
37
+ """
38
+ ...
39
+
40
+ def kernel_gaussian_full_symm_rfp(
41
+ X: torch.Tensor, # (N, M) float32 CUDA
42
+ dX: torch.Tensor, # (N, D, M) float32 CUDA
43
+ sigma: float,
44
+ ) -> torch.Tensor:
45
+ """Build the energy+force kernel matrix directly in RFP packed format.
46
+
47
+ Like kernel_gaussian_full_symm but stores the result as a 1-D RFP
48
+ packed buffer (TRANSR=N, UPLO=L) instead of a dense BIG x BIG matrix.
49
+ Each lower-triangle element is written once via rfp_index_lower_N;
50
+ no dense intermediate is allocated and no mirror step is performed.
51
+
52
+ Parameters
53
+ ----------
54
+ X : torch.Tensor, shape (N, M), float32 CUDA
55
+ Training descriptors.
56
+ dX : torch.Tensor, shape (N, D, M), float32 CUDA
57
+ Training Jacobians.
58
+ sigma : float
59
+ Gaussian length-scale.
60
+
61
+ Returns
62
+ -------
63
+ K_rfp : torch.Tensor, shape (BIG*(BIG+1)//2,), float32 CUDA
64
+ Lower-triangular RFP packed kernel matrix (TRANSR=N, UPLO=L),
65
+ where BIG = N*(1+D).
66
+ """
67
+ ...
68
+
69
+ def kernel_gaussian_full_matvec(
70
+ X_q: torch.Tensor, # (N_q, M) float32 CUDA
71
+ dX_q: torch.Tensor, # (N_q, D, M) float32 CUDA
72
+ X_t: torch.Tensor, # (N_t, M) float32 CUDA
73
+ alpha_E: torch.Tensor, # (N_t,) float32 CUDA
74
+ alpha_desc_F: torch.Tensor, # (N_t, M) float32 CUDA
75
+ sigma: float,
76
+ ) -> tuple[torch.Tensor, torch.Tensor]:
77
+ """Contracted energy+force inference (J^T·alpha trick).
78
+
79
+ Computes E and F predictions without materialising the full test-train
80
+ kernel matrix. Uses the same J^T·alpha contraction as the CPU
81
+ ``kernel_gaussian_full_matvec``.
82
+
83
+ ``alpha_desc_F`` must be precomputed once after training::
84
+
85
+ alpha_desc_F = torch.einsum('ndm,nd->nm', dX_train, alpha_F)
86
+
87
+ Parameters
88
+ ----------
89
+ X_q : torch.Tensor, shape (N_q, M), float32 CUDA
90
+ Query descriptors.
91
+ dX_q : torch.Tensor, shape (N_q, D, M), float32 CUDA
92
+ Query Jacobians.
93
+ X_t : torch.Tensor, shape (N_t, M), float32 CUDA
94
+ Training descriptors.
95
+ alpha_E : torch.Tensor, shape (N_t,), float32 CUDA
96
+ Energy dual coefficients.
97
+ alpha_desc_F : torch.Tensor, shape (N_t, M), float32 CUDA
98
+ Contracted force weights: ``Σ_d J_train[m,d,:] * alpha_F[m,d]``.
99
+ sigma : float
100
+ Gaussian length-scale.
101
+
102
+ Returns
103
+ -------
104
+ E_pred : torch.Tensor, shape (N_q,), float32 CUDA
105
+ F_pred : torch.Tensor, shape (N_q, D), float32 CUDA
106
+ Physical forces F = -dE/dR.
107
+ """
108
+ ...
109
+
110
+ def kernel_gaussian_symm_rfp(
111
+ X: torch.Tensor, # (N, M) float32 CUDA
112
+ sigma: float,
113
+ ) -> torch.Tensor:
114
+ """Build the energy-only NxN Gaussian kernel matrix in RFP packed format.
115
+
116
+ Uses TRANSR=N, UPLO=L convention. The packed buffer has N*(N+1)//2
117
+ elements and is compatible with rfp_potrf / rfp_potrs.
118
+
119
+ Parameters
120
+ ----------
121
+ X : torch.Tensor, shape (N, M), float32 CUDA
122
+ Training descriptors.
123
+ sigma : float
124
+ Gaussian length-scale.
125
+
126
+ Returns
127
+ -------
128
+ K_rfp : torch.Tensor, shape (N*(N+1)//2,), float32 CUDA
129
+ Lower-triangular RFP packed kernel matrix (TRANSR=N, UPLO=L).
130
+ """
131
+ ...
132
+
133
+ def rfp_potrf(
134
+ K_rfp: torch.Tensor, # (N*(N+1)//2,) float32 CUDA, modified in-place
135
+ N: int,
136
+ l2: float = 0.0,
137
+ ) -> int:
138
+ """Cholesky factorisation of an RFP-packed symmetric positive definite matrix.
139
+
140
+ Optionally adds l2 to the diagonal (Tikhonov regularisation) before
141
+ factorising. The input buffer is overwritten with the lower Cholesky factor L.
142
+ Convention: TRANSR=N, UPLO=L.
143
+
144
+ Parameters
145
+ ----------
146
+ K_rfp : torch.Tensor, shape (N*(N+1)//2,), float32 CUDA
147
+ RFP-packed matrix. Modified in-place.
148
+ N : int
149
+ Matrix dimension.
150
+ l2 : float, default 0.0
151
+ Diagonal regularisation added before factorisation.
152
+
153
+ Returns
154
+ -------
155
+ info : int
156
+ 0 on success; positive value k means the k-th leading minor is not
157
+ positive definite.
158
+ """
159
+ ...
160
+
161
+ def rfp_potrs(
162
+ L_rfp: torch.Tensor, # (N*(N+1)//2,) float32 CUDA
163
+ B: torch.Tensor, # (N, nrhs) float32 CUDA, modified in-place
164
+ ) -> None:
165
+ """Triangular solve using a Cholesky factor from rfp_potrf.
166
+
167
+ Solves (L * L^T) * X = B, overwriting B with the solution X.
168
+ Convention: TRANSR=N, UPLO=L.
169
+
170
+ Parameters
171
+ ----------
172
+ L_rfp : torch.Tensor, shape (N*(N+1)//2,), float32 CUDA
173
+ Lower Cholesky factor in RFP format (output of rfp_potrf).
174
+ B : torch.Tensor, shape (N, nrhs), float32 CUDA
175
+ Right-hand side. Overwritten with the solution on exit.
176
+ """
177
+ ...
@@ -0,0 +1,51 @@
1
+ """Type stubs for cuda_invdist_repr — GPU batched inverse-distance representation (FP32)."""
2
+
3
+ import torch
4
+
5
+ def inverse_distance_upper(
6
+ coords: torch.Tensor,
7
+ n_atoms: int,
8
+ eps: float = 1e-6,
9
+ ) -> torch.Tensor:
10
+ """Compute batched inverse-distance representation on GPU.
11
+
12
+ Parameters
13
+ ----------
14
+ coords : torch.Tensor, shape (nm, n_atoms, 3), float32, CUDA
15
+ Batched Cartesian coordinates. All molecules must have the same n_atoms.
16
+ n_atoms : int
17
+ Number of atoms per molecule.
18
+ eps : float, default 1e-6
19
+ Distance floor: r is clamped to max(r, eps) before inversion.
20
+
21
+ Returns
22
+ -------
23
+ X : torch.Tensor, shape (nm, M), float32, CUDA
24
+ M = n_atoms*(n_atoms-1)//2. Entry [m, p] = 1/r_{ij} for pair p=(i<j).
25
+ """
26
+ ...
27
+
28
+ def inverse_distance_upper_and_jacobian(
29
+ coords: torch.Tensor,
30
+ n_atoms: int,
31
+ eps: float = 1e-6,
32
+ ) -> tuple[torch.Tensor, torch.Tensor]:
33
+ """Compute batched inverse-distance representation and Jacobian on GPU.
34
+
35
+ Parameters
36
+ ----------
37
+ coords : torch.Tensor, shape (nm, n_atoms, 3), float32, CUDA
38
+ Batched Cartesian coordinates. All molecules must have the same n_atoms.
39
+ n_atoms : int
40
+ Number of atoms per molecule.
41
+ eps : float, default 1e-6
42
+ Distance floor: r is clamped to max(r, eps) before inversion.
43
+
44
+ Returns
45
+ -------
46
+ X : torch.Tensor, shape (nm, M), float32, CUDA
47
+ M = n_atoms*(n_atoms-1)//2.
48
+ dX : torch.Tensor, shape (nm, D, M), float32, CUDA
49
+ D = 3*n_atoms. dX[m, 3*a+d, p] = d(1/r_ij)/d(R_{a,d}) for pair p=(i<j).
50
+ """
51
+ ...
@@ -0,0 +1,376 @@
1
+ """Type stubs for cuda_local_kernels — CUDA Gaussian kernels for FCHL19 local descriptors.
2
+
3
+ Implements atom-pair-wise kernels with label-based screening (z1 == z2).
4
+ All functions operate on CUDA (GPU) tensors.
5
+ """
6
+
7
+ import torch
8
+
9
+ def kernel_gaussian_rect(
10
+ X_q: torch.Tensor,
11
+ Q_q: torch.Tensor,
12
+ N_q: torch.Tensor,
13
+ X_t: torch.Tensor,
14
+ Q_t: torch.Tensor,
15
+ N_t: torch.Tensor,
16
+ sigma: float,
17
+ ) -> torch.Tensor:
18
+ """Build kernel matrix for two molecule sets (asymmetric/rectangular case).
19
+
20
+ Parameters
21
+ ----------
22
+ X_q : torch.Tensor, shape (nm_q, max_atoms_q, rep), float32, CUDA
23
+ Query descriptor vectors.
24
+ Q_q : torch.Tensor, shape (nm_q, max_atoms_q), int32, CUDA
25
+ Query atomic labels.
26
+ N_q : torch.Tensor, shape (nm_q,), int32, CUDA
27
+ Query active atom counts.
28
+ X_t : torch.Tensor, shape (nm_t, max_atoms_t, rep), float32, CUDA
29
+ Training descriptor vectors.
30
+ Q_t : torch.Tensor, shape (nm_t, max_atoms_t), int32, CUDA
31
+ Training atomic labels.
32
+ N_t : torch.Tensor, shape (nm_t,), int32, CUDA
33
+ Training active atom counts.
34
+ sigma : float
35
+ Gaussian kernel length-scale.
36
+
37
+ Returns
38
+ -------
39
+ K : torch.Tensor, shape (nm1, nm2), float64, CUDA
40
+ Kernel matrix aggregated by label-matching atom pairs.
41
+ """
42
+ ...
43
+
44
+ def kernel_gaussian_symm(
45
+ X: torch.Tensor,
46
+ Q: torch.Tensor,
47
+ N: torch.Tensor,
48
+ sigma: float,
49
+ ) -> torch.Tensor:
50
+ """Build symmetric kernel matrix for a single molecule set.
51
+
52
+ Parameters
53
+ ----------
54
+ X : torch.Tensor, shape (nm, max_atoms, rep), float32, CUDA
55
+ Descriptor vectors.
56
+ Q : torch.Tensor, shape (nm, max_atoms), int32, CUDA
57
+ Atomic labels.
58
+ N : torch.Tensor, shape (nm,), int32, CUDA
59
+ Active atom counts per molecule.
60
+ sigma : float
61
+ Gaussian kernel length-scale.
62
+
63
+ Returns
64
+ -------
65
+ K_symm : torch.Tensor, shape (nm, nm), float64, CUDA
66
+ Symmetric kernel matrix (both triangles filled).
67
+ """
68
+ ...
69
+
70
+ def kernel_gaussian_symm_rfp(
71
+ X: torch.Tensor,
72
+ Q: torch.Tensor,
73
+ N: torch.Tensor,
74
+ sigma: float,
75
+ ) -> torch.Tensor:
76
+ """Build the symmetric energy-only kernel matrix K_EE in RFP packed format.
77
+
78
+ Uses TRANSR=N, UPLO=L convention.
79
+ Unpack with: kernelmath.rfp_to_full(K_rfp, nm, uplo='U', transr='N')
80
+
81
+ Parameters
82
+ ----------
83
+ X : torch.Tensor, shape (nm, max_atoms, rep), float32, CUDA
84
+ Descriptor vectors.
85
+ Q : torch.Tensor, shape (nm, max_atoms), int32, CUDA
86
+ Atomic labels.
87
+ N : torch.Tensor, shape (nm,), int32, CUDA
88
+ Active atom counts per molecule.
89
+ sigma : float
90
+ Gaussian kernel length-scale.
91
+
92
+ Returns
93
+ -------
94
+ K_rfp : torch.Tensor, shape (nm*(nm+1)//2,), float32, CUDA
95
+ Lower-triangle kernel packed in RFP format.
96
+ """
97
+ ...
98
+
99
+ def kernel_gaussian_full_symm(
100
+ X: torch.Tensor,
101
+ dX: torch.Tensor,
102
+ Q: torch.Tensor,
103
+ N: torch.Tensor,
104
+ sigma: float,
105
+ ) -> torch.Tensor:
106
+ """Build the symmetric (nm+naq)² energy+force training kernel matrix.
107
+
108
+ Parameters
109
+ ----------
110
+ X : torch.Tensor, shape (nm, max_atoms, rep), float32, CUDA
111
+ Training atom descriptors (padded with zeros beyond N[m]).
112
+ dX : torch.Tensor, shape (nm, max_atoms, rep, 3*max_atoms), float32, CUDA
113
+ Training Jacobians (padded).
114
+ Q : torch.Tensor, shape (nm, max_atoms), int32, CUDA
115
+ Atomic labels (nuclear charges; zero-padded).
116
+ N : torch.Tensor, shape (nm,), int32, CUDA
117
+ Active atom counts per molecule.
118
+ sigma : float
119
+ Gaussian kernel length-scale.
120
+
121
+ Returns
122
+ -------
123
+ K_full : torch.Tensor, shape (nm+naq, nm+naq), float32, CUDA
124
+ Fully symmetric kernel matrix. naq = 3 * sum(N).
125
+ """
126
+ ...
127
+
128
+ def kernel_gaussian_full_symm_rfp(
129
+ X: torch.Tensor,
130
+ dX: torch.Tensor,
131
+ Q: torch.Tensor,
132
+ N: torch.Tensor,
133
+ sigma: float,
134
+ ) -> torch.Tensor:
135
+ """Build the symmetric energy+force training kernel matrix in RFP packed format.
136
+
137
+ Uses TRANSR=N, UPLO=L convention. BIG = nm + naq, naq = 3*sum(N).
138
+ Unpack with: kernelmath.rfp_to_full(K_rfp, BIG, uplo='U', transr='N')
139
+
140
+ Parameters
141
+ ----------
142
+ X : torch.Tensor, shape (nm, max_atoms, rep), float32, CUDA
143
+ Training atom descriptors (padded with zeros beyond N[m]).
144
+ dX : torch.Tensor, shape (nm, max_atoms, rep, 3*max_atoms), float32, CUDA
145
+ Training Jacobians (padded).
146
+ Q : torch.Tensor, shape (nm, max_atoms), int32, CUDA
147
+ Atomic labels (nuclear charges; zero-padded).
148
+ N : torch.Tensor, shape (nm,), int32, CUDA
149
+ Active atom counts per molecule.
150
+ sigma : float
151
+ Gaussian kernel length-scale.
152
+
153
+ Returns
154
+ -------
155
+ K_rfp : torch.Tensor, shape (BIG*(BIG+1)//2,), float32, CUDA
156
+ Lower-triangle kernel packed in RFP format.
157
+ """
158
+ ...
159
+
160
+ def compute_alpha_desc(
161
+ dX: torch.Tensor,
162
+ N: torch.Tensor,
163
+ alpha_F: torch.Tensor,
164
+ ) -> torch.Tensor:
165
+ """Precompute descriptor-space force weights for the J^T·alpha trick.
166
+
167
+ alpha_desc[b, i2, k] = sum_{c=0}^{3*N[b]-1} dX[b, i2, k, c] * alpha_F[offs[b]+c]
168
+
169
+ Call once after the KRR solve. Pass the result to
170
+ ``kernel_gaussian_full_matvec`` at inference time.
171
+
172
+ Parameters
173
+ ----------
174
+ dX : torch.Tensor, shape (nm, max_atoms, rep, 3*max_atoms), float32, CUDA
175
+ Training Jacobians.
176
+ N : torch.Tensor, shape (nm,), int32, CUDA
177
+ Active atom counts.
178
+ alpha_F : torch.Tensor, shape (naq,), float32, CUDA
179
+ Force dual coefficients from the KRR solve (alpha[nm:]).
180
+
181
+ Returns
182
+ -------
183
+ alpha_desc : torch.Tensor, shape (nm, max_atoms, rep), float32, CUDA
184
+ """
185
+ ...
186
+
187
+ def kernel_gaussian_full_matvec(
188
+ X_q: torch.Tensor,
189
+ dX_q: torch.Tensor,
190
+ Q_q: torch.Tensor,
191
+ N_q: torch.Tensor,
192
+ X_t: torch.Tensor,
193
+ Q_t: torch.Tensor,
194
+ N_t: torch.Tensor,
195
+ alpha_E: torch.Tensor,
196
+ alpha_desc_F: torch.Tensor,
197
+ sigma: float,
198
+ ) -> tuple[torch.Tensor, torch.Tensor]:
199
+ """Contracted energy+force inference (J^T·alpha trick, local version with label screening).
200
+
201
+ Does not materialise the full test-train kernel matrix.
202
+ Uses label-based atom screening (z1 == z2) for efficiency.
203
+
204
+ Parameters
205
+ ----------
206
+ X_q : torch.Tensor, shape (nm_q, max_atoms_q, rep), float32, CUDA
207
+ Query atom descriptors.
208
+ dX_q : torch.Tensor, shape (nm_q, max_atoms_q, rep, 3*max_atoms_q), float32, CUDA
209
+ Query Jacobians.
210
+ Q_q : torch.Tensor, shape (nm_q, max_atoms_q), int32, CUDA
211
+ Query atomic labels.
212
+ N_q : torch.Tensor, shape (nm_q,), int32, CUDA
213
+ Query active atom counts.
214
+ X_t : torch.Tensor, shape (nm_t, max_atoms_t, rep), float32, CUDA
215
+ Training atom descriptors.
216
+ Q_t : torch.Tensor, shape (nm_t, max_atoms_t), int32, CUDA
217
+ Training atomic labels.
218
+ N_t : torch.Tensor, shape (nm_t,), int32, CUDA
219
+ Training active atom counts.
220
+ alpha_E : torch.Tensor, shape (nm_t,), float32, CUDA
221
+ Energy dual coefficients.
222
+ alpha_desc_F : torch.Tensor, shape (nm_t, max_atoms_t, rep), float32, CUDA
223
+ Precomputed force weights (from ``compute_alpha_desc``).
224
+ sigma : float
225
+ Gaussian kernel length-scale.
226
+
227
+ Returns
228
+ -------
229
+ E_pred : torch.Tensor, shape (nm_q,), float32, CUDA
230
+ Predicted energies.
231
+ F_pred : torch.Tensor, shape (naq_q,), float32, CUDA
232
+ Predicted forces as flat Cartesian vector. naq_q = 3*sum(N_q).
233
+ """
234
+ ...
235
+
236
+ def precompute_train(
237
+ X_t: torch.Tensor,
238
+ Q_t: torch.Tensor,
239
+ N_t: torch.Tensor,
240
+ alpha_E: torch.Tensor,
241
+ alpha_desc: torch.Tensor,
242
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
243
+ """Precompute training-side constants for repeated inference (e.g. MD simulation).
244
+
245
+ Call once after fitting. The returned tensors are constant as long as the
246
+ training data (X_t, alpha_E, alpha_desc) does not change. Pass them to
247
+ ``kernel_gaussian_full_matvec_cached`` at every inference step.
248
+
249
+ Parameters
250
+ ----------
251
+ X_t : torch.Tensor, shape (nm_t, max_atoms_t, rep), float32, CUDA
252
+ Q_t : torch.Tensor, shape (nm_t, max_atoms_t), int32, CUDA
253
+ N_t : torch.Tensor, shape (nm_t,), int32, CUDA
254
+ alpha_E : torch.Tensor, shape (nm_t,), float32, CUDA
255
+ alpha_desc : torch.Tensor, shape (nm_t, max_atoms_t, rep), float32, CUDA
256
+
257
+ Returns
258
+ -------
259
+ norms_t : torch.Tensor, shape (nm_t * max_atoms_t,), float32, CUDA
260
+ Squared norms ||X_t[t]||².
261
+ S_adF : torch.Tensor, shape (nm_t * max_atoms_t,), float32, CUDA
262
+ Dot products X_t[t] · alpha_desc[t].
263
+ alpha_E_t : torch.Tensor, shape (nm_t * max_atoms_t,), float32, CUDA
264
+ Atom-expanded energy dual coefficients alpha_E[mol(t)].
265
+ combined_t : torch.Tensor, shape (nm_t * max_atoms_t, rep), float32, CUDA
266
+ Combined matrix alpha_desc + alpha_E_t[t] * X_t.
267
+ """
268
+ ...
269
+
270
+ def kernel_gaussian_full_matvec_cached(
271
+ X_q: torch.Tensor,
272
+ dX_q: torch.Tensor,
273
+ Q_q: torch.Tensor,
274
+ N_q: torch.Tensor,
275
+ X_t: torch.Tensor,
276
+ Q_t: torch.Tensor,
277
+ N_t: torch.Tensor,
278
+ alpha_E: torch.Tensor,
279
+ alpha_desc: torch.Tensor,
280
+ norms_t: torch.Tensor,
281
+ S_adF: torch.Tensor,
282
+ alpha_E_t: torch.Tensor,
283
+ combined_t: torch.Tensor,
284
+ sigma: float,
285
+ ) -> tuple[torch.Tensor, torch.Tensor]:
286
+ """Cached energy+force inference for repeated calls (MD simulation).
287
+
288
+ Variant of ``kernel_gaussian_full_matvec`` that accepts precomputed
289
+ training-side constants from ``precompute_train``. Eliminates per-step
290
+ cudaMalloc/cudaFree overhead and redundant kernel launches for norms_t,
291
+ S_adF, and combined_t.
292
+
293
+ Parameters
294
+ ----------
295
+ X_q : torch.Tensor, shape (nm_q, max_atoms_q, rep), float32, CUDA
296
+ dX_q : torch.Tensor, shape (nm_q, max_atoms_q, rep, 3*max_atoms_q), float32, CUDA
297
+ Q_q : torch.Tensor, shape (nm_q, max_atoms_q), int32, CUDA
298
+ N_q : torch.Tensor, shape (nm_q,), int32, CUDA
299
+ X_t : torch.Tensor, shape (nm_t, max_atoms_t, rep), float32, CUDA
300
+ Q_t : torch.Tensor, shape (nm_t, max_atoms_t), int32, CUDA
301
+ N_t : torch.Tensor, shape (nm_t,), int32, CUDA
302
+ alpha_E : torch.Tensor, shape (nm_t,), float32, CUDA
303
+ alpha_desc : torch.Tensor, shape (nm_t, max_atoms_t, rep), float32, CUDA
304
+ norms_t : torch.Tensor, shape (nm_t * max_atoms_t,), float32, CUDA
305
+ From ``precompute_train``.
306
+ S_adF : torch.Tensor, shape (nm_t * max_atoms_t,), float32, CUDA
307
+ From ``precompute_train``.
308
+ alpha_E_t : torch.Tensor, shape (nm_t * max_atoms_t,), float32, CUDA
309
+ From ``precompute_train``.
310
+ combined_t : torch.Tensor, shape (nm_t * max_atoms_t, rep), float32, CUDA
311
+ From ``precompute_train``.
312
+ sigma : float
313
+
314
+ Returns
315
+ -------
316
+ E_pred : torch.Tensor, shape (nm_q,), float32, CUDA
317
+ F_pred : torch.Tensor, shape (naq_q,), float32, CUDA
318
+ """
319
+ ...
320
+
321
+ def kernel_gaussian_full_matvec_cached_graph(
322
+ X_q: torch.Tensor,
323
+ dX_q: torch.Tensor,
324
+ Q_q: torch.Tensor,
325
+ N_q: torch.Tensor,
326
+ X_t: torch.Tensor,
327
+ Q_t: torch.Tensor,
328
+ N_t: torch.Tensor,
329
+ alpha_E: torch.Tensor,
330
+ alpha_desc: torch.Tensor,
331
+ norms_t: torch.Tensor,
332
+ S_adF: torch.Tensor,
333
+ alpha_E_t: torch.Tensor,
334
+ combined_t: torch.Tensor,
335
+ query_indices_by_group: list[torch.Tensor],
336
+ query_counts_by_group: list[int],
337
+ E_pred: torch.Tensor,
338
+ F_pred: torch.Tensor,
339
+ sigma: float,
340
+ ) -> None:
341
+ """Graph-capture-friendly cached energy+force inference.
342
+
343
+ Uses caller-provided output buffers and fixed per-element query index
344
+ tensors so the cached matvec can be captured and replayed via a CUDA graph
345
+ for repeated fixed-shape inference.
346
+ """
347
+ ...
348
+
349
+ def kernel_gaussian_full_matvec_cached_graph_with_offsets(
350
+ X_q: torch.Tensor,
351
+ dX_q: torch.Tensor,
352
+ Q_q: torch.Tensor,
353
+ N_q: torch.Tensor,
354
+ offs_q: torch.Tensor,
355
+ X_t: torch.Tensor,
356
+ Q_t: torch.Tensor,
357
+ N_t: torch.Tensor,
358
+ alpha_E: torch.Tensor,
359
+ alpha_desc: torch.Tensor,
360
+ norms_t: torch.Tensor,
361
+ S_adF: torch.Tensor,
362
+ alpha_E_t: torch.Tensor,
363
+ combined_t: torch.Tensor,
364
+ query_indices_by_group: list[torch.Tensor],
365
+ query_counts_by_group: list[int],
366
+ E_pred: torch.Tensor,
367
+ F_pred: torch.Tensor,
368
+ sigma: float,
369
+ ) -> None:
370
+ """Graph-capture-friendly cached energy+force inference with query offsets.
371
+
372
+ Uses caller-provided output buffers, fixed per-element query index tensors,
373
+ and precomputed query Cartesian offsets to avoid host synchronization during
374
+ CUDA graph capture and replay.
375
+ """
376
+ ...