kernelforge 0.3.1.dev51__cp312-cp312-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-312-darwin.so +0 -0
  15. kernelforge/fchl18_kernel.pyi +400 -0
  16. kernelforge/fchl18_repr.cpython-312-darwin.so +0 -0
  17. kernelforge/fchl18_repr.pyi +35 -0
  18. kernelforge/fchl19_repr.cpython-312-darwin.so +0 -0
  19. kernelforge/fchl19_repr.pyi +36 -0
  20. kernelforge/fchl19v2_repr.cpython-312-darwin.so +0 -0
  21. kernelforge/fchl19v2_repr.pyi +67 -0
  22. kernelforge/global_kernels.cpython-312-darwin.so +0 -0
  23. kernelforge/global_kernels.pyi +85 -0
  24. kernelforge/invdist_repr.cpython-312-darwin.so +0 -0
  25. kernelforge/invdist_repr.pyi +9 -0
  26. kernelforge/kernelcli.py +1034 -0
  27. kernelforge/kernelmath.cpython-312-darwin.so +0 -0
  28. kernelforge/kernelmath.pyi +46 -0
  29. kernelforge/kernelmd.py +255 -0
  30. kernelforge/kitchen_sinks.cpython-312-darwin.so +0 -0
  31. kernelforge/kitchen_sinks.pyi +146 -0
  32. kernelforge/local_kernels.cpython-312-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
Binary file
@@ -0,0 +1,73 @@
1
+ """KernelForge - Optimized kernels for machine learning."""
2
+
3
+ try:
4
+ from importlib.metadata import PackageNotFoundError, version
5
+
6
+ __version__ = version("kernelforge")
7
+ except PackageNotFoundError:
8
+ __version__ = "unknown"
9
+
10
+ from .ase_calculator import KernelForgeCalculator as KernelForgeCalculator
11
+ from .kitchen_sinks import (
12
+ rff_features as rff_features,
13
+ )
14
+ from .kitchen_sinks import (
15
+ rff_features_elemental as rff_features_elemental,
16
+ )
17
+ from .kitchen_sinks import (
18
+ rff_full as rff_full,
19
+ )
20
+ from .kitchen_sinks import (
21
+ rff_full_elemental as rff_full_elemental,
22
+ )
23
+ from .kitchen_sinks import (
24
+ rff_full_gramian_elemental as rff_full_gramian_elemental,
25
+ )
26
+ from .kitchen_sinks import (
27
+ rff_full_gramian_elemental_rfp as rff_full_gramian_elemental_rfp,
28
+ )
29
+ from .kitchen_sinks import (
30
+ rff_full_gramian_symm as rff_full_gramian_symm,
31
+ )
32
+ from .kitchen_sinks import (
33
+ rff_full_gramian_symm_rfp as rff_full_gramian_symm_rfp,
34
+ )
35
+ from .kitchen_sinks import (
36
+ rff_gradient as rff_gradient,
37
+ )
38
+ from .kitchen_sinks import (
39
+ rff_gradient_elemental as rff_gradient_elemental,
40
+ )
41
+ from .kitchen_sinks import (
42
+ rff_gradient_gramian_elemental as rff_gradient_gramian_elemental,
43
+ )
44
+ from .kitchen_sinks import (
45
+ rff_gradient_gramian_elemental_rfp as rff_gradient_gramian_elemental_rfp,
46
+ )
47
+ from .kitchen_sinks import (
48
+ rff_gradient_gramian_symm as rff_gradient_gramian_symm,
49
+ )
50
+ from .kitchen_sinks import (
51
+ rff_gradient_gramian_symm_rfp as rff_gradient_gramian_symm_rfp,
52
+ )
53
+ from .kitchen_sinks import (
54
+ rff_gramian_elemental as rff_gramian_elemental,
55
+ )
56
+ from .kitchen_sinks import (
57
+ rff_gramian_elemental_rfp as rff_gramian_elemental_rfp,
58
+ )
59
+ from .kitchen_sinks import (
60
+ rff_gramian_symm as rff_gramian_symm,
61
+ )
62
+ from .kitchen_sinks import (
63
+ rff_gramian_symm_rfp as rff_gramian_symm_rfp,
64
+ )
65
+ from .md import run_md as run_md
66
+ from .models import CudaFCHL18KRRModel as CudaFCHL18KRRModel
67
+ from .models import CudaGlobalRFFModel as CudaGlobalRFFModel
68
+ from .models import CudaLocalRFFModel as CudaLocalRFFModel
69
+ from .models import FCHL18KRRModel as FCHL18KRRModel
70
+ from .models import GlobalKRRModel as GlobalKRRModel
71
+ from .models import GlobalRFFModel as GlobalRFFModel
72
+ from .models import LocalKRRModel as LocalKRRModel
73
+ from .models import LocalRFFModel as LocalRFFModel
@@ -0,0 +1,10 @@
1
+ """Shared install hints for missing CUDA extension modules."""
2
+
3
+ from __future__ import annotations
4
+
5
+ CUDA_EXT_HINT = (
6
+ "Install the CUDA extensions with:\n"
7
+ " pip install 'kernelforge[cuda]' # Linux (companion wheel)\n"
8
+ " make install-linux-mkl-ilp64-cuda # local monorepo build\n"
9
+ "Requires an NVIDIA driver compatible with your torch CUDA build."
10
+ )
@@ -0,0 +1,174 @@
1
+ """ASE Calculator wrapping a fitted KernelForge model.
2
+
3
+ Usage
4
+ -----
5
+ >>> from kernelforge import KernelForgeCalculator
6
+ >>> calc = KernelForgeCalculator(model, units="kcal/mol")
7
+ >>> atoms.calc = calc
8
+ >>> energy = atoms.get_potential_energy() # eV
9
+ >>> forces = atoms.get_forces() # eV/Å, shape (n_atoms, 3)
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from typing import Any, ClassVar, Protocol, runtime_checkable
15
+
16
+ import numpy as np
17
+
18
+ # ---------------------------------------------------------------------------
19
+ # Lazy ASE import — ase is optional; only raise at instantiation time
20
+ # ---------------------------------------------------------------------------
21
+ try:
22
+ from ase.calculators.calculator import Calculator as _AseCalculator
23
+ from ase.calculators.calculator import all_changes as _all_changes
24
+
25
+ _ASE_AVAILABLE = True
26
+ except ImportError:
27
+
28
+ class _AseCalculator: # type: ignore[no-redef]
29
+ """Stub used when ASE is not installed."""
30
+
31
+ atoms: Any = None
32
+ results: ClassVar[dict[str, Any]] = {}
33
+
34
+ def __init__(self, **kwargs: object) -> None:
35
+ pass
36
+
37
+ def calculate(
38
+ self,
39
+ atoms: Any = None, # noqa: ANN401
40
+ properties: list[str] | None = None,
41
+ system_changes: list[str] | None = None,
42
+ ) -> None:
43
+ pass
44
+
45
+ _all_changes: list[str] = []
46
+ _ASE_AVAILABLE = False
47
+
48
+ # ---------------------------------------------------------------------------
49
+ # Unit conversion helpers
50
+ # ---------------------------------------------------------------------------
51
+ _KCAL_MOL_TO_EV: float | None = None
52
+
53
+
54
+ def _kcal_mol_to_eV() -> float:
55
+ """Return the kcal/mol → eV conversion factor (computed once from ase.units)."""
56
+ global _KCAL_MOL_TO_EV
57
+ if _KCAL_MOL_TO_EV is None:
58
+ import ase.units
59
+
60
+ _KCAL_MOL_TO_EV = ase.units.kcal / ase.units.mol
61
+ return _KCAL_MOL_TO_EV
62
+
63
+
64
+ def _get_factor(units: str) -> float:
65
+ """Return multiplicative factor to convert *units* → eV (energy) and eV/Å (forces)."""
66
+ if units == "eV":
67
+ return 1.0
68
+ if units == "kcal/mol":
69
+ return _kcal_mol_to_eV()
70
+ msg = f"Unknown units '{units}'. Supported values: 'kcal/mol', 'eV'."
71
+ raise ValueError(msg)
72
+
73
+
74
+ @runtime_checkable
75
+ class _PredictModel(Protocol):
76
+ """Minimal model interface required by KernelForgeCalculator."""
77
+
78
+ is_fitted_: bool
79
+
80
+ def predict(
81
+ self,
82
+ coords_list: list[Any],
83
+ z_list: list[Any],
84
+ compute_energy: bool = True,
85
+ ) -> tuple[Any, Any]: ...
86
+
87
+
88
+ # ---------------------------------------------------------------------------
89
+ # KernelForgeCalculator
90
+ # ---------------------------------------------------------------------------
91
+
92
+
93
+ class KernelForgeCalculator(_AseCalculator): # type: ignore[misc]
94
+ """ASE Calculator backed by a fitted KernelForge model.
95
+
96
+ Parameters
97
+ ----------
98
+ model:
99
+ Any fitted KernelForge model exposing ``predict(coords_list, z_list,
100
+ compute_energy=...)`` (for example ``CudaLocalKRRModel``,
101
+ ``CudaLocalRFFModel``, or other CUDA/CPU models with force support).
102
+ The model must have been trained so that force predictions are available
103
+ (not ``energy_only``).
104
+ units:
105
+ Energy (and force) units used when training the model.
106
+ ``'kcal/mol'`` (default) covers rMD17 and small_mols_mini datasets.
107
+ ``'eV'`` disables conversion.
108
+
109
+ Notes
110
+ -----
111
+ ASE always works internally in eV and eV/Å. The calculator multiplies
112
+ energies and forces by ``ase.units.kcal / ase.units.mol`` (≈ 0.04336)
113
+ when ``units='kcal/mol'`` so that all ASE MD engines see correct units.
114
+ """
115
+
116
+ implemented_properties: ClassVar[list[str]] = ["energy", "forces"]
117
+
118
+ def __init__(
119
+ self,
120
+ model: _PredictModel,
121
+ units: str = "kcal/mol",
122
+ **kwargs: object,
123
+ ) -> None:
124
+ if not _ASE_AVAILABLE:
125
+ msg = (
126
+ "ASE is required to use KernelForgeCalculator. "
127
+ "Install it with: pip install 'kernelforge[ase]' or pip install ase"
128
+ )
129
+ raise ImportError(msg)
130
+
131
+ if not getattr(model, "is_fitted_", False):
132
+ msg = "The model must be fitted before it can be wrapped in KernelForgeCalculator."
133
+ raise RuntimeError(msg)
134
+
135
+ training_mode = getattr(model, "training_mode_", None)
136
+ if training_mode == "energy_only":
137
+ msg = (
138
+ "Model was trained in 'energy_only' mode and cannot predict forces. "
139
+ "Re-train with energies and forces to use MD."
140
+ )
141
+ raise RuntimeError(msg)
142
+
143
+ _AseCalculator.__init__(self, **kwargs)
144
+ self._kf_model = model
145
+ self._kf_factor = _get_factor(units)
146
+
147
+ def calculate(
148
+ self,
149
+ atoms: Any = None, # noqa: ANN401
150
+ properties: list[str] | None = None,
151
+ system_changes: list[str] | None = None,
152
+ ) -> None:
153
+ """Compute energy and forces for *atoms* and store in ``self.results``."""
154
+ if properties is None:
155
+ properties = ["energy", "forces"]
156
+ if system_changes is None:
157
+ system_changes = list(_all_changes)
158
+
159
+ _AseCalculator.calculate(self, atoms, properties, system_changes)
160
+
161
+ if self.atoms is None:
162
+ msg = "atoms is None after Calculator.calculate(); this should not happen."
163
+ raise RuntimeError(msg)
164
+
165
+ coords = self.atoms.get_positions().astype(np.float64) # (n_atoms, 3) Å
166
+ z = self.atoms.get_atomic_numbers().astype(np.int32) # (n_atoms,)
167
+
168
+ want_energy = properties is not None and "energy" in properties
169
+ E_arr, F_flat = self._kf_model.predict([coords], [z], compute_energy=want_energy)
170
+
171
+ factor = self._kf_factor
172
+ if want_energy:
173
+ self.results["energy"] = float(E_arr[0]) * factor
174
+ self.results["forces"] = F_flat.reshape(-1, 3).astype(np.float64) * factor