mlipcpp 0.1.1__tar.gz → 0.1.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 (191) hide show
  1. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/.github/workflows/build_wasm.yml +13 -3
  2. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/.github/workflows/ci.yml +7 -2
  3. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/CMakeLists.txt +26 -2
  4. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/PKG-INFO +1 -1
  5. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/include/mlipcpp/mlipcpp.hpp +7 -0
  6. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/pyproject.toml +6 -1
  7. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/export_pytorch/fx_converter.py +2 -0
  8. mlipcpp-0.1.2/scripts/test_stress_fd.py +379 -0
  9. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/api/c/mlipcpp_api.cpp +1 -1
  10. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/api/cpp/mlipcpp_cpp.cpp +97 -1
  11. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/api/python/mlipcpp_bindings.cpp +10 -3
  12. mlipcpp-0.1.2/src/bin/graph_inference.cpp +201 -0
  13. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/runtime/graph_interpreter.cpp +75 -16
  14. mlipcpp-0.1.2/src/runtime/graph_model.cpp +1036 -0
  15. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_auto_vs_manual.cpp +6 -4
  16. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_pet.cpp +6 -6
  17. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_python_api.py +3 -3
  18. mlipcpp-0.1.2/website/bun.lock +233 -0
  19. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/package.json +2 -1
  20. mlipcpp-0.1.2/website/src/App.svelte +155 -0
  21. mlipcpp-0.1.2/website/src/components/EditOverlay.svelte +102 -0
  22. mlipcpp-0.1.2/website/src/components/EditPanel.svelte +793 -0
  23. mlipcpp-0.1.2/website/src/components/ModelLoader.svelte +397 -0
  24. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/components/OptParams.svelte +5 -2
  25. mlipcpp-0.1.2/website/src/components/PeriodicTable.svelte +112 -0
  26. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/components/StructureLoader.svelte +4 -2
  27. mlipcpp-0.1.2/website/src/components/Viewer.svelte +816 -0
  28. mlipcpp-0.1.2/website/src/components/ViewerControls.svelte +128 -0
  29. mlipcpp-0.1.2/website/src/lib/chem/xyz.ts +53 -0
  30. mlipcpp-0.1.2/website/src/lib/editor/fragments.ts +145 -0
  31. mlipcpp-0.1.2/website/src/lib/editor/ghostFlash.ts +128 -0
  32. mlipcpp-0.1.2/website/src/lib/editor/hydrogens.ts +209 -0
  33. mlipcpp-0.1.2/website/src/lib/editor/transform.svelte.ts +556 -0
  34. mlipcpp-0.1.2/website/src/lib/molview/Selection.ts +89 -0
  35. mlipcpp-0.1.2/website/src/lib/molview/Stage.ts +915 -0
  36. mlipcpp-0.1.2/website/src/lib/molview/StructureObject.ts +271 -0
  37. mlipcpp-0.1.2/website/src/lib/molview/UnitCell.ts +172 -0
  38. mlipcpp-0.1.2/website/src/lib/molview/adapter.ts +97 -0
  39. mlipcpp-0.1.2/website/src/lib/molview/data/bonds.ts +139 -0
  40. mlipcpp-0.1.2/website/src/lib/molview/data/colors.ts +19 -0
  41. mlipcpp-0.1.2/website/src/lib/molview/data/elements.ts +213 -0
  42. mlipcpp-0.1.2/website/src/lib/molview/data/jmolColors.ts +30 -0
  43. mlipcpp-0.1.2/website/src/lib/molview/data/types.ts +74 -0
  44. mlipcpp-0.1.2/website/src/lib/molview/impostorSettings.ts +13 -0
  45. mlipcpp-0.1.2/website/src/lib/molview/lighting.ts +32 -0
  46. mlipcpp-0.1.2/website/src/lib/molview/materialStyles.ts +700 -0
  47. mlipcpp-0.1.2/website/src/lib/molview/plugins/PathTracerPlugin.ts +21 -0
  48. mlipcpp-0.1.2/website/src/lib/molview/representations/BallAndStick.ts +397 -0
  49. mlipcpp-0.1.2/website/src/lib/molview/representations/ImpostorBallAndStick.ts +778 -0
  50. mlipcpp-0.1.2/website/src/lib/molview/representations/ImpostorSpacefill.ts +385 -0
  51. mlipcpp-0.1.2/website/src/lib/molview/representations/Spacefill.ts +172 -0
  52. mlipcpp-0.1.2/website/src/lib/molview/representations/Tube.ts +346 -0
  53. mlipcpp-0.1.2/website/src/lib/molview/representations/Wireframe.ts +168 -0
  54. mlipcpp-0.1.2/website/src/lib/molview/representations/types.ts +40 -0
  55. mlipcpp-0.1.2/website/src/lib/stores/simulation.svelte.ts +1101 -0
  56. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/worker/mdWorker.ts +243 -22
  57. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/worker/simulation.ts +3 -3
  58. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/styles/app.css +89 -2
  59. mlipcpp-0.1.2/website/src/vite-env.d.ts +7 -0
  60. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/vite.config.ts +1 -1
  61. mlipcpp-0.1.1/src/bin/graph_inference.cpp +0 -122
  62. mlipcpp-0.1.1/src/runtime/graph_model.cpp +0 -578
  63. mlipcpp-0.1.1/website/bun.lock +0 -766
  64. mlipcpp-0.1.1/website/src/App.svelte +0 -73
  65. mlipcpp-0.1.1/website/src/components/ModelLoader.svelte +0 -241
  66. mlipcpp-0.1.1/website/src/components/Viewer.svelte +0 -61
  67. mlipcpp-0.1.1/website/src/components/ViewerControls.svelte +0 -63
  68. mlipcpp-0.1.1/website/src/lib/chem/xyz.ts +0 -23
  69. mlipcpp-0.1.1/website/src/lib/ngl/viewer.ts +0 -220
  70. mlipcpp-0.1.1/website/src/lib/stores/simulation.svelte.ts +0 -435
  71. mlipcpp-0.1.1/website/src/vite-env.d.ts +0 -26
  72. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/.clang-format +0 -0
  73. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/.github/workflows/website.yml +0 -0
  74. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/.github/workflows/wheels.yml +0 -0
  75. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/.gitignore +0 -0
  76. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/.gitmodules +0 -0
  77. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/LICENSE +0 -0
  78. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/README.md +0 -0
  79. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/cmake/PythonBindings.cmake +0 -0
  80. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/cmake/mlipcppConfig.cmake.in +0 -0
  81. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/examples/CMakeLists.txt +0 -0
  82. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/examples/backend_benchmark.cpp +0 -0
  83. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/examples/c_api_test.c +0 -0
  84. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/examples/cpp_api_test.cpp +0 -0
  85. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/examples/fortran_api_test.f90 +0 -0
  86. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/examples/python_ase.py +0 -0
  87. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/examples/python_basic.py +0 -0
  88. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/examples/python_comparison.py +0 -0
  89. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/examples/simple_inference.cpp +0 -0
  90. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/geometries/si.xyz +0 -0
  91. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/geometries/urea.cif +0 -0
  92. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/geometries/urea.xyz +0 -0
  93. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/geometries/urea_molecule.xyz +0 -0
  94. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/geometries/water.xyz +0 -0
  95. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/gguf/LICENSE +0 -0
  96. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/gguf/README.md +0 -0
  97. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/include/mlipcpp/io.h +0 -0
  98. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/include/mlipcpp/mlipcpp.h +0 -0
  99. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/include/mlipcpp/model.h +0 -0
  100. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/include/mlipcpp/neighbor_list.h +0 -0
  101. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/include/mlipcpp/system.h +0 -0
  102. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/include/mlipcpp/timer.h +0 -0
  103. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/packages/mlip.js/LICENSE +0 -0
  104. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/packages/mlip.js/README.md +0 -0
  105. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/packages/mlip.js/examples/basic.html +0 -0
  106. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/packages/mlip.js/package-lock.json +0 -0
  107. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/packages/mlip.js/package.json +0 -0
  108. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/packages/mlip.js/scripts/build.js +0 -0
  109. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/python/mlipcpp/__init__.py +0 -0
  110. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/python/mlipcpp/ase.py +0 -0
  111. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/__init__.py +0 -0
  112. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/benchmark_backends.sh +0 -0
  113. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/benchmark_graph_inference_forces.py +0 -0
  114. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/benchmark_pet_full_torch_compile.py +0 -0
  115. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/build_wasm.sh +0 -0
  116. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/calc_energy_pytorch.py +0 -0
  117. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/convert_cif_to_extxyz.py +0 -0
  118. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/convert_models.py +0 -0
  119. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/convert_pet_mad.py +0 -0
  120. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/export_pytorch/__init__.py +0 -0
  121. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/export_pytorch/export_pet_full.py +0 -0
  122. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/export_pytorch/export_pet_gguf.py +0 -0
  123. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/export_pytorch/graph_ir.py +0 -0
  124. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/publish_ggufs.py +0 -0
  125. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/test_all_models.py +0 -0
  126. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/scripts/test_all_models.sh +0 -0
  127. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/CMakeLists.txt +0 -0
  128. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/api/fortran/mlipcpp.f90 +0 -0
  129. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/backend.cpp +0 -0
  130. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/backend.h +0 -0
  131. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/ggml_utils.cpp +0 -0
  132. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/ggml_utils.h +0 -0
  133. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/gguf_loader.cpp +0 -0
  134. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/gguf_loader.h +0 -0
  135. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/log.h +0 -0
  136. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/neighbor_list.cpp +0 -0
  137. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/system.cpp +0 -0
  138. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/core/timer.cpp +0 -0
  139. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/ggml_attention.cpp +0 -0
  140. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/ggml_attention.h +0 -0
  141. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/io/xyz.cpp +0 -0
  142. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/models/model.cpp +0 -0
  143. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/models/pet/pet.cpp +0 -0
  144. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/models/pet/pet.h +0 -0
  145. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/models/pet/pet_batch.cpp +0 -0
  146. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/models/pet/pet_batch.h +0 -0
  147. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/models/pet/pet_graph.h +0 -0
  148. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/models/pet/pet_layers.cpp +0 -0
  149. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/models/pet/pet_types.h +0 -0
  150. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/runtime/graph_interpreter.h +0 -0
  151. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/runtime/graph_ir.cpp +0 -0
  152. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/runtime/graph_ir.h +0 -0
  153. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/src/runtime/graph_model.h +0 -0
  154. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/CMakeLists.txt +0 -0
  155. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_backend_selection.cpp +0 -0
  156. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_full_export.cpp +0 -0
  157. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_ggml_layout.cpp +0 -0
  158. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_graph_interpreter.cpp +0 -0
  159. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_graph_model.cpp +0 -0
  160. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_io.cpp +0 -0
  161. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_main.cpp +0 -0
  162. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_neighbor_list.cpp +0 -0
  163. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_pet_gradients.cpp +0 -0
  164. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/tests/test_system.cpp +0 -0
  165. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/uv.lock +0 -0
  166. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/.gitignore +0 -0
  167. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/bench.html +0 -0
  168. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/index.html +0 -0
  169. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/public/favicon.svg +0 -0
  170. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/bench-main.ts +0 -0
  171. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/components/EnergyPlot.svelte +0 -0
  172. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/components/MDParams.svelte +0 -0
  173. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/components/RunControls.svelte +0 -0
  174. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/components/Segmented.svelte +0 -0
  175. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/components/Stats.svelte +0 -0
  176. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/components/VibrationsPanel.svelte +0 -0
  177. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/components/XyzEditorModal.svelte +0 -0
  178. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/chem/bonds.ts +0 -0
  179. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/chem/cell.ts +0 -0
  180. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/chem/elements.ts +0 -0
  181. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/chem/pubchem.ts +0 -0
  182. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/chem/sdf.ts +0 -0
  183. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/chem/supercell.ts +0 -0
  184. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/data/samples.ts +0 -0
  185. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/vib/jacobi.ts +0 -0
  186. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/vib/modes.ts +0 -0
  187. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/lib/vib/projector.ts +0 -0
  188. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/src/main.ts +0 -0
  189. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/svelte.config.js +0 -0
  190. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/tsconfig.json +0 -0
  191. {mlipcpp-0.1.1 → mlipcpp-0.1.2}/website/tsconfig.node.json +0 -0
@@ -85,7 +85,10 @@ jobs:
85
85
  run: npm pack
86
86
 
87
87
  - name: Upload WASM build artifacts
88
- if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
88
+ if: >-
89
+ github.event_name == 'workflow_dispatch' ||
90
+ (github.event_name == 'push' &&
91
+ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
89
92
  uses: actions/upload-artifact@v4
90
93
  with:
91
94
  name: wasm-build
@@ -93,7 +96,10 @@ jobs:
93
96
  retention-days: 30
94
97
 
95
98
  - name: Upload package artifact
96
- if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
99
+ if: >-
100
+ github.event_name == 'workflow_dispatch' ||
101
+ (github.event_name == 'push' &&
102
+ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')))
97
103
  uses: actions/upload-artifact@v4
98
104
  with:
99
105
  name: mlipjs-package
@@ -113,10 +119,14 @@ jobs:
113
119
  - name: Checkout repository
114
120
  uses: actions/checkout@v4
115
121
 
122
+ # Node 24 ships npm >= 11.5.1, which is the minimum that implements the
123
+ # OIDC-to-registry handshake for trusted publishers. Node 20/22.x ship
124
+ # npm 10.x, which can sign provenance via OIDC but still auths the
125
+ # registry PUT the old token way — that's the 404/ENEEDAUTH we hit.
116
126
  - name: Setup Node.js
117
127
  uses: actions/setup-node@v4
118
128
  with:
119
- node-version: 20
129
+ node-version: 24
120
130
  registry-url: 'https://registry.npmjs.org'
121
131
 
122
132
  - name: Download WASM build artifacts
@@ -33,13 +33,18 @@ jobs:
33
33
  restore-keys: |
34
34
  cpm-${{ runner.os }}-
35
35
 
36
+ # Bump the prefix (currently v2) to invalidate stale caches built with
37
+ # different ggml CPU baselines. Pre-v2 caches were built with
38
+ # -march=native; after we defaulted GGML_NATIVE=OFF in CMakeLists.txt
39
+ # the new objects and the old library archive can disagree on
40
+ # available CPU features at link time and SIGILL at runtime.
36
41
  - name: Cache build directory
37
42
  uses: actions/cache@v4
38
43
  with:
39
44
  path: build
40
- key: build-${{ runner.os }}-${{ env.BUILD_TYPE }}-${{ hashFiles('CMakeLists.txt', 'src/**', 'include/**') }}
45
+ key: build-v2-${{ runner.os }}-${{ env.BUILD_TYPE }}-${{ hashFiles('CMakeLists.txt', 'src/**', 'include/**') }}
41
46
  restore-keys: |
42
- build-${{ runner.os }}-${{ env.BUILD_TYPE }}-
47
+ build-v2-${{ runner.os }}-${{ env.BUILD_TYPE }}-
43
48
 
44
49
  - name: Configure CMake
45
50
  run: |
@@ -1,5 +1,5 @@
1
1
  cmake_minimum_required(VERSION 3.18)
2
- project(mlipcpp VERSION 0.1.1 LANGUAGES CXX C)
2
+ project(mlipcpp VERSION 0.1.2 LANGUAGES CXX C)
3
3
 
4
4
  set(CMAKE_CXX_STANDARD 20)
5
5
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -96,11 +96,27 @@ if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
96
96
  file(DOWNLOAD
97
97
  https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
98
98
  ${CPM_DOWNLOAD_LOCATION}
99
+ STATUS _cpm_download_status
100
+ TLS_VERIFY ON
99
101
  )
102
+ list(GET _cpm_download_status 0 _cpm_download_code)
103
+ if(NOT _cpm_download_code EQUAL 0)
104
+ message(FATAL_ERROR
105
+ "Failed to download CPM.cmake from "
106
+ "https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake "
107
+ "(status: ${_cpm_download_status}). Check your network/proxy, then "
108
+ "delete ${CPM_DOWNLOAD_LOCATION} and re-run cmake.")
109
+ endif()
100
110
  endif()
101
111
 
102
112
  include(${CPM_DOWNLOAD_LOCATION})
103
113
 
114
+ if(NOT COMMAND CPMAddPackage)
115
+ message(FATAL_ERROR
116
+ "CPM.cmake at ${CPM_DOWNLOAD_LOCATION} is invalid (CPMAddPackage not defined). "
117
+ "Delete that file and re-run cmake to redownload.")
118
+ endif()
119
+
104
120
  # ggml (forked version with gradient support)
105
121
  # Use MLIPCPP_GGML_SOURCE_DIR to point to a local ggml checkout for development
106
122
  set(MLIPCPP_GGML_SOURCE_DIR "" CACHE PATH "Path to local ggml source directory (for development)")
@@ -146,6 +162,14 @@ if(MLIPCPP_USE_BLAS)
146
162
  set(GGML_BLAS ON CACHE BOOL "" FORCE)
147
163
  endif()
148
164
 
165
+ # Default to a portable CPU baseline (no -march=native). Wheels and CI need
166
+ # this — without it ggml bakes the build host's CPU features into the binary
167
+ # and the resulting library SIGILLs on machines with a different (or older)
168
+ # CPU. Users wanting host-tuned builds can pass -DGGML_NATIVE=ON explicitly.
169
+ if(NOT DEFINED CACHE{GGML_NATIVE})
170
+ set(GGML_NATIVE OFF CACHE BOOL "Build with -march=native (non-portable)")
171
+ endif()
172
+
149
173
  # WASM-specific ggml configuration
150
174
  if(EMSCRIPTEN)
151
175
  # SINGLE_FILE=ON embeds the .wasm as base64 inside the .js, which blocks
@@ -168,7 +192,7 @@ else()
168
192
  CPMAddPackage(
169
193
  NAME ggml
170
194
  GITHUB_REPOSITORY peterspackman/ggml
171
- GIT_TAG 833b864d
195
+ GIT_TAG 9be7b7f8
172
196
  EXCLUDE_FROM_ALL YES
173
197
  )
174
198
  endif()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mlipcpp
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Fast C++ implementation of Machine Learning Interatomic Potentials
5
5
  Author-Email: Peter Spackman <peterspackman@fastmail.com>
6
6
  License: BSD 3-Clause License
@@ -73,6 +73,13 @@ struct PredictOptions {
73
73
  bool compute_stress = false; ///< Compute stress tensor
74
74
  bool use_nc_forces = false; ///< Use non-conservative forces from forward pass heads
75
75
  ///< (faster, but forces are not gradient of energy)
76
+ /**
77
+ * If true and compute_stress is true, evaluate stress via finite differences
78
+ * on the energy under symmetric Voigt strain (12 forward passes, slow but
79
+ * exact w.r.t. the model's own energy — useful as a validation oracle).
80
+ * Default false uses the autograd-based virial path.
81
+ */
82
+ bool fd_stress = false;
76
83
  };
77
84
 
78
85
  /**
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
4
4
 
5
5
  [project]
6
6
  name = "mlipcpp"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Fast C++ implementation of Machine Learning Interatomic Potentials"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -38,6 +38,11 @@ cmake.targets = ["_mlipcpp"]
38
38
  MLIPCPP_BUILD_PYTHON = "ON"
39
39
  MLIPCPP_BUILD_EXAMPLES = "OFF"
40
40
  MLIPCPP_BUILD_TESTS = "OFF"
41
+ # Build portable wheels: -march=native bakes the build host's CPU features
42
+ # (e.g. AVX-512 on some Azure VMs) into the binary, causing SIGILL on test
43
+ # or end-user machines that lack those instructions. ggml falls back to a
44
+ # conservative baseline + runtime feature detection when NATIVE is OFF.
45
+ GGML_NATIVE = "OFF"
41
46
 
42
47
  [tool.cibuildwheel]
43
48
  # One stable-ABI wheel per platform (cp312-abi3 is forward compatible with 3.12+).
@@ -144,6 +144,8 @@ ATEN_TO_GGML = {
144
144
  "aten.cos": "COS",
145
145
  "aten.sin.default": "SIN",
146
146
  "aten.sin": "SIN",
147
+ "aten.abs.default": "UNARY_ABS",
148
+ "aten.abs": "UNARY_ABS",
147
149
  "aten.clamp.default": "CLAMP",
148
150
  "aten.clamp": "CLAMP",
149
151
 
@@ -0,0 +1,379 @@
1
+ #!/usr/bin/env python3
2
+ """Validate analytical stress (virial) against finite-difference stress.
3
+
4
+ For each model GGUF, evaluate stress on a small periodic structure (Si by
5
+ default, plus optional CIFs/XYZs) and compare:
6
+
7
+ σ_voigt[k] (analytical, from compute_stress=True)
8
+ vs
9
+ (E(+δ) - E(-δ)) / (2 V₀ δ) where ε(δ) corresponds to η_k = δ
10
+
11
+ Voigt order: [xx, yy, zz, yz, xz, xy]. Strain matrix from Voigt η is:
12
+ ε = [[η₁, η₆/2, η₅/2],
13
+ [η₆/2, η₂, η₄/2],
14
+ [η₅/2, η₄/2, η₃]]
15
+
16
+ Cell rows are lattice vectors and positions/cell both transform as
17
+ new = old @ (I + ε).T
18
+
19
+ Optionally compares against the upet PyTorch calculator (--pytorch).
20
+
21
+ Usage:
22
+ .venv/bin/python scripts/test_stress_fd.py
23
+ .venv/bin/python scripts/test_stress_fd.py --models pet-mad-xs,pet-mad-s
24
+ .venv/bin/python scripts/test_stress_fd.py --delta 5e-3 --backend cpu
25
+ .venv/bin/python scripts/test_stress_fd.py --pytorch --model pet-mad-s
26
+ """
27
+
28
+ from __future__ import annotations
29
+
30
+ import argparse
31
+ import re
32
+ import subprocess
33
+ import sys
34
+ import tempfile
35
+ from dataclasses import dataclass
36
+ from pathlib import Path
37
+
38
+ import numpy as np
39
+
40
+ import mlipcpp
41
+
42
+
43
+ VOIGT_LABELS = ("xx", "yy", "zz", "yz", "xz", "xy")
44
+
45
+
46
+ def voigt_to_matrix(eta: np.ndarray) -> np.ndarray:
47
+ """ASE Voigt convention: shear stored as engineering strain (factor 2)."""
48
+ return np.array(
49
+ [
50
+ [eta[0], eta[5] / 2, eta[4] / 2],
51
+ [eta[5] / 2, eta[1], eta[3] / 2],
52
+ [eta[4] / 2, eta[3] / 2, eta[2]],
53
+ ],
54
+ dtype=np.float64,
55
+ )
56
+
57
+
58
+ @dataclass
59
+ class Structure:
60
+ name: str
61
+ positions: np.ndarray # (N, 3) float32
62
+ atomic_numbers: np.ndarray # (N,) int32
63
+ cell: np.ndarray # (3, 3) float32, rows are lattice vectors
64
+
65
+
66
+ def make_silicon(a: float = 5.43) -> Structure:
67
+ positions = np.array(
68
+ [[0.0, 0.0, 0.0],
69
+ [a * 0.25, a * 0.25, a * 0.25]],
70
+ dtype=np.float32,
71
+ )
72
+ atomic_numbers = np.array([14, 14], dtype=np.int32)
73
+ cell = np.array(
74
+ [[a * 0.5, a * 0.5, 0.0],
75
+ [0.0, a * 0.5, a * 0.5],
76
+ [a * 0.5, 0.0, a * 0.5]],
77
+ dtype=np.float32,
78
+ )
79
+ return Structure("Si (FCC primitive)", positions, atomic_numbers, cell)
80
+
81
+
82
+ def make_diamond_carbon(a: float = 3.567) -> Structure:
83
+ positions = np.array(
84
+ [[0.0, 0.0, 0.0],
85
+ [a * 0.25, a * 0.25, a * 0.25]],
86
+ dtype=np.float32,
87
+ )
88
+ atomic_numbers = np.array([6, 6], dtype=np.int32)
89
+ cell = np.array(
90
+ [[a * 0.5, a * 0.5, 0.0],
91
+ [0.0, a * 0.5, a * 0.5],
92
+ [a * 0.5, 0.0, a * 0.5]],
93
+ dtype=np.float32,
94
+ )
95
+ return Structure("Diamond C", positions, atomic_numbers, cell)
96
+
97
+
98
+ def make_fcc_aluminum(a: float = 4.05) -> Structure:
99
+ positions = np.array([[0.0, 0.0, 0.0]], dtype=np.float32)
100
+ atomic_numbers = np.array([13], dtype=np.int32)
101
+ cell = np.array(
102
+ [[a * 0.5, a * 0.5, 0.0],
103
+ [0.0, a * 0.5, a * 0.5],
104
+ [a * 0.5, 0.0, a * 0.5]],
105
+ dtype=np.float32,
106
+ )
107
+ return Structure("FCC Al", positions, atomic_numbers, cell)
108
+
109
+
110
+ def apply_strain(struct: Structure, eta: np.ndarray) -> Structure:
111
+ eps = voigt_to_matrix(eta)
112
+ F = np.eye(3) + eps # deformation gradient
113
+ new_cell = (struct.cell.astype(np.float64) @ F.T).astype(np.float32)
114
+ new_positions = (struct.positions.astype(np.float64) @ F.T).astype(np.float32)
115
+ return Structure(struct.name, new_positions, struct.atomic_numbers, new_cell)
116
+
117
+
118
+ def cell_volume(cell: np.ndarray) -> float:
119
+ return abs(float(np.linalg.det(cell.astype(np.float64))))
120
+
121
+
122
+ def predict_energy(predictor, struct: Structure) -> float:
123
+ res = predictor.predict(
124
+ struct.positions, struct.atomic_numbers,
125
+ cell=struct.cell, pbc=(True, True, True),
126
+ compute_forces=False, compute_stress=False,
127
+ )
128
+ return float(res.energy)
129
+
130
+
131
+ def predict_stress(predictor, struct: Structure) -> np.ndarray:
132
+ res = predictor.predict(
133
+ struct.positions, struct.atomic_numbers,
134
+ cell=struct.cell, pbc=(True, True, True),
135
+ compute_forces=True, compute_stress=True,
136
+ )
137
+ if not res.has_stress():
138
+ raise RuntimeError("Predictor did not return stress (has_stress=False)")
139
+ return np.array(res.stress, dtype=np.float64)
140
+
141
+
142
+ def fd_stress(predictor, struct: Structure, delta: float,
143
+ order: int = 4) -> np.ndarray:
144
+ """σ_voigt[k] = (1/V₀) ∂E/∂η_k via central-difference FD.
145
+
146
+ order=2: σ = (E(+δ) - E(-δ)) / (2Vδ)
147
+ order=4: σ = [8(E(+δ) - E(-δ)) - (E(+2δ) - E(-2δ))] / (12Vδ)
148
+
149
+ The 4th-order stencil cancels the δ² truncation term, leaving a smaller
150
+ residual when float32 noise lets us shrink δ.
151
+ """
152
+ V0 = cell_volume(struct.cell)
153
+ sigma = np.zeros(6, dtype=np.float64)
154
+ for k in range(6):
155
+ eta = np.zeros(6, dtype=np.float64)
156
+ def E_at(scale: float) -> float:
157
+ eta[k] = delta * scale
158
+ return predict_energy(predictor, apply_strain(struct, eta))
159
+ if order == 2:
160
+ sigma[k] = (E_at(+1.0) - E_at(-1.0)) / (2.0 * V0 * delta)
161
+ elif order == 4:
162
+ ep1 = E_at(+1.0); em1 = E_at(-1.0)
163
+ ep2 = E_at(+2.0); em2 = E_at(-2.0)
164
+ sigma[k] = (8.0 * (ep1 - em1) - (ep2 - em2)) / (12.0 * V0 * delta)
165
+ else:
166
+ raise ValueError(f"unsupported FD order {order}")
167
+ return sigma
168
+
169
+
170
+ def report(model_name: str, struct_name: str,
171
+ sigma_an: np.ndarray, sigma_fd: np.ndarray) -> bool:
172
+ diff = sigma_an - sigma_fd
173
+ max_abs = float(np.max(np.abs(diff)))
174
+ scale = max(1.0, float(np.max(np.abs(sigma_fd))))
175
+ rel = max_abs / scale
176
+ ok = max_abs < 5e-3 or rel < 5e-2 # loose tolerance for f32 + finite-diff error
177
+
178
+ print(f"\n Model: {model_name} Structure: {struct_name}")
179
+ print(f" {'comp':>4} {'analytical':>14} {'finite-diff':>14} {'diff':>12}")
180
+ for k, label in enumerate(VOIGT_LABELS):
181
+ marker = "" if abs(diff[k]) < 1e-3 else " *"
182
+ print(f" {label:>4} {sigma_an[k]:>14.6f} {sigma_fd[k]:>14.6f} {diff[k]:>12.3e}{marker}")
183
+ status = "PASS" if ok else "FAIL"
184
+ print(f" -> {status} (max |Δ| = {max_abs:.3e}, rel = {rel:.3e})")
185
+ return ok
186
+
187
+
188
+ SYMBOL_BY_Z = {
189
+ 1: "H", 5: "B", 6: "C", 7: "N", 8: "O", 9: "F",
190
+ 11: "Na", 12: "Mg", 13: "Al", 14: "Si", 15: "P", 16: "S", 17: "Cl",
191
+ 19: "K", 20: "Ca", 26: "Fe", 29: "Cu", 30: "Zn", 35: "Br",
192
+ }
193
+
194
+
195
+ def write_extxyz(path: Path, struct: Structure) -> None:
196
+ cell = struct.cell.flatten()
197
+ lattice = " ".join(f"{x:.10f}" for x in cell)
198
+ with path.open("w") as f:
199
+ f.write(f"{len(struct.atomic_numbers)}\n")
200
+ f.write(
201
+ f'Lattice="{lattice}" Properties=species:S:1:pos:R:3 pbc="T T T"\n'
202
+ )
203
+ for z, (x, y, zc) in zip(struct.atomic_numbers, struct.positions):
204
+ sym = SYMBOL_BY_Z.get(int(z), str(int(z)))
205
+ f.write(f"{sym} {x:.10f} {y:.10f} {zc:.10f}\n")
206
+
207
+
208
+ _STRESS_RE = re.compile(
209
+ r"xx=([-\d.eE+]+),\s*yy=([-\d.eE+]+),\s*zz=([-\d.eE+]+)"
210
+ r"[\s\S]*?yz=([-\d.eE+]+),\s*xz=([-\d.eE+]+),\s*xy=([-\d.eE+]+)"
211
+ )
212
+
213
+
214
+ def run_pytorch_reference(struct: Structure, model_name: str,
215
+ script_path: Path) -> np.ndarray | None:
216
+ """Drive scripts/calc_energy_pytorch.py via uv-run and parse stress.
217
+
218
+ The reference script declares its deps inline (PEP-723), so `uv run`
219
+ materialises an isolated env with torch+upet+ase.
220
+ """
221
+ with tempfile.TemporaryDirectory() as tmp:
222
+ xyz = Path(tmp) / "struct.xyz"
223
+ write_extxyz(xyz, struct)
224
+ cmd = [
225
+ "uv", "run", str(script_path),
226
+ str(xyz),
227
+ "--model", model_name,
228
+ "--no-forces",
229
+ ]
230
+ try:
231
+ result = subprocess.run(cmd, capture_output=True, text=True,
232
+ timeout=600)
233
+ except FileNotFoundError:
234
+ print(" (uv not found, skipping PyTorch reference)")
235
+ return None
236
+ except subprocess.TimeoutExpired:
237
+ print(" (PyTorch reference timed out)")
238
+ return None
239
+ if result.returncode != 0:
240
+ print(f" PyTorch reference failed (rc={result.returncode})")
241
+ tail = "\n".join(result.stderr.strip().splitlines()[-6:])
242
+ if tail:
243
+ print(f" stderr: {tail}")
244
+ return None
245
+ m = _STRESS_RE.search(result.stdout)
246
+ if not m:
247
+ print(" Could not parse stress from PyTorch reference output")
248
+ return None
249
+ return np.array([float(x) for x in m.groups()], dtype=np.float64)
250
+
251
+
252
+ def find_models(root: Path, requested: list[str] | None) -> list[Path]:
253
+ if requested:
254
+ out = []
255
+ for name in requested:
256
+ p = root / (name if name.endswith(".gguf") else f"{name}.gguf")
257
+ if not p.exists():
258
+ print(f" warn: {p} not found, skipping", file=sys.stderr)
259
+ continue
260
+ out.append(p)
261
+ return out
262
+ return sorted(root.glob("*.gguf"))
263
+
264
+
265
+ def main() -> int:
266
+ parser = argparse.ArgumentParser(
267
+ description="Finite-difference stress validation for mlipcpp models",
268
+ )
269
+ parser.add_argument("--models", type=str, default=None,
270
+ help="Comma-separated model names (default: all *.gguf in gguf/)")
271
+ parser.add_argument("--gguf-dir", type=str, default="gguf",
272
+ help="Directory containing model GGUFs (default: gguf)")
273
+ parser.add_argument("--structures", type=str, default="si",
274
+ help="Comma-separated structures: si, diamond, al (default: si)")
275
+ parser.add_argument("--delta", type=float, default=2e-3,
276
+ help="Strain magnitude for finite difference (default: 2e-3)")
277
+ parser.add_argument("--backend", type=str, default=None,
278
+ choices=["cpu", "metal", "cuda"],
279
+ help="Force backend (default: auto)")
280
+ parser.add_argument("--pytorch", action="store_true",
281
+ help="Also compare to upet PyTorch calculator (uv run)")
282
+ parser.add_argument("--pytorch-script", type=str,
283
+ default="scripts/calc_energy_pytorch.py",
284
+ help="Path to calc_energy_pytorch.py reference script")
285
+ parser.add_argument("--no-fd", action="store_true",
286
+ help="Skip finite-difference comparison (only --pytorch)")
287
+ args = parser.parse_args()
288
+
289
+ if args.backend:
290
+ backend = {
291
+ "cpu": mlipcpp.Backend.CPU,
292
+ "metal": mlipcpp.Backend.Metal,
293
+ "cuda": mlipcpp.Backend.CUDA,
294
+ }[args.backend]
295
+ if not mlipcpp.is_backend_available(backend):
296
+ print(f"Backend {args.backend} not available", file=sys.stderr)
297
+ return 2
298
+ mlipcpp.set_backend(backend)
299
+
300
+ mlipcpp.set_log_level(mlipcpp.LogLevel.Error)
301
+ print(f"Backend: {mlipcpp.get_backend_name()}")
302
+ print(f"Strain magnitude δ = {args.delta}")
303
+
304
+ structure_factories = {
305
+ "si": make_silicon,
306
+ "diamond": make_diamond_carbon,
307
+ "al": make_fcc_aluminum,
308
+ }
309
+ selected_structs = []
310
+ for name in args.structures.split(","):
311
+ name = name.strip().lower()
312
+ if name not in structure_factories:
313
+ print(f"Unknown structure '{name}'", file=sys.stderr)
314
+ return 2
315
+ selected_structs.append(structure_factories[name]())
316
+
317
+ requested = [m.strip() for m in args.models.split(",")] if args.models else None
318
+ model_paths = find_models(Path(args.gguf_dir), requested)
319
+ if not model_paths:
320
+ print("No models found", file=sys.stderr)
321
+ return 1
322
+
323
+ n_pass = 0
324
+ n_fail = 0
325
+ n_skip = 0
326
+
327
+ for mpath in model_paths:
328
+ model_name = mpath.stem
329
+ print(f"\n{'='*70}\nModel: {model_name}\n{'='*70}")
330
+ try:
331
+ predictor = mlipcpp.Predictor(str(mpath))
332
+ except Exception as e:
333
+ print(f" load failed: {e}")
334
+ n_skip += 1
335
+ continue
336
+
337
+ for struct in selected_structs:
338
+ try:
339
+ sigma_an = predict_stress(predictor, struct)
340
+ except Exception as e:
341
+ print(f" Skip {struct.name}: {e}")
342
+ n_skip += 1
343
+ continue
344
+
345
+ ok_fd = True
346
+ if not args.no_fd:
347
+ sigma_fd = fd_stress(predictor, struct, args.delta)
348
+ ok_fd = report(model_name, struct.name, sigma_an, sigma_fd)
349
+
350
+ ok_torch = True
351
+ if args.pytorch:
352
+ sigma_torch = run_pytorch_reference(
353
+ struct, model_name, Path(args.pytorch_script))
354
+ if sigma_torch is None:
355
+ n_skip += 1
356
+ else:
357
+ diff = sigma_an - sigma_torch
358
+ max_abs = float(np.max(np.abs(diff)))
359
+ scale = max(1.0, float(np.max(np.abs(sigma_torch))))
360
+ rel = max_abs / scale
361
+ ok_torch = max_abs < 5e-3 or rel < 5e-2
362
+ print(f"\n Model: {model_name} Structure: {struct.name} PyTorch reference")
363
+ print(f" {'comp':>4} {'mlipcpp':>14} {'pytorch':>14} {'diff':>12}")
364
+ for k, label in enumerate(VOIGT_LABELS):
365
+ marker = "" if abs(diff[k]) < 1e-3 else " *"
366
+ print(f" {label:>4} {sigma_an[k]:>14.6f} {sigma_torch[k]:>14.6f} {diff[k]:>12.3e}{marker}")
367
+ status = "PASS" if ok_torch else "FAIL"
368
+ print(f" -> {status} vs PyTorch (max |Δ| = {max_abs:.3e}, rel = {rel:.3e})")
369
+
370
+ ok = ok_fd and ok_torch
371
+ n_pass += int(ok)
372
+ n_fail += int(not ok)
373
+
374
+ print(f"\n{'='*70}\nSummary: {n_pass} pass, {n_fail} fail, {n_skip} skip")
375
+ return 0 if n_fail == 0 else 1
376
+
377
+
378
+ if __name__ == "__main__":
379
+ sys.exit(main())
@@ -136,7 +136,7 @@ to_compute_precision(mlipcpp_precision_t precision) {
136
136
  // Version Information
137
137
  // ============================================================================
138
138
 
139
- const char *mlipcpp_version(void) { return "0.1.1"; }
139
+ const char *mlipcpp_version(void) { return "0.1.2"; }
140
140
 
141
141
  // ============================================================================
142
142
  // Backend and Logging Control
@@ -15,7 +15,7 @@
15
15
 
16
16
  namespace mlipcpp {
17
17
 
18
- const char *version() { return "0.1.1"; }
18
+ const char *version() { return "0.1.2"; }
19
19
 
20
20
  // Global backend provider - shared across all models
21
21
  static std::shared_ptr<BackendProvider> g_backend_provider;
@@ -163,6 +163,96 @@ struct Predictor::Impl {
163
163
  return result;
164
164
  }
165
165
 
166
+ /**
167
+ * Symmetric Voigt strain → cell @ F.T, positions @ F.T (rows are lattice
168
+ * vectors). Used by the FD stress path.
169
+ */
170
+ static AtomicSystem strain(const AtomicSystem &src, const float eta[6]) {
171
+ AtomicSystem out = src;
172
+ // Strain matrix from Voigt (engineering shear → factor of 1/2 off-diag)
173
+ double e[3][3] = {
174
+ {1.0 + eta[0], 0.5 * eta[5], 0.5 * eta[4]},
175
+ {0.5 * eta[5], 1.0 + eta[1], 0.5 * eta[3]},
176
+ {0.5 * eta[4], 0.5 * eta[3], 1.0 + eta[2]},
177
+ };
178
+ // Transform cell rows: each lattice vector a_i' = e * a_i
179
+ if (auto *cell_ptr = src.cell(); cell_ptr) {
180
+ Cell new_cell = *cell_ptr;
181
+ for (int i = 0; i < 3; ++i) {
182
+ double a[3] = {cell_ptr->matrix[i][0], cell_ptr->matrix[i][1],
183
+ cell_ptr->matrix[i][2]};
184
+ for (int alpha = 0; alpha < 3; ++alpha) {
185
+ new_cell.matrix[i][alpha] = static_cast<float>(
186
+ e[alpha][0] * a[0] + e[alpha][1] * a[1] + e[alpha][2] * a[2]);
187
+ }
188
+ }
189
+ // Recompute inverse via the public Cell ctor
190
+ Cell rebuilt(new_cell.matrix, new_cell.periodic[0],
191
+ new_cell.periodic[1], new_cell.periodic[2]);
192
+ out.set_cell(rebuilt);
193
+ }
194
+ // Transform positions: r' = e * r
195
+ auto &pos = out.positions_mut();
196
+ for (int i = 0; i < src.num_atoms(); ++i) {
197
+ double r[3] = {pos[3 * i + 0], pos[3 * i + 1], pos[3 * i + 2]};
198
+ for (int alpha = 0; alpha < 3; ++alpha) {
199
+ pos[3 * i + alpha] = static_cast<float>(
200
+ e[alpha][0] * r[0] + e[alpha][1] * r[1] + e[alpha][2] * r[2]);
201
+ }
202
+ }
203
+ return out;
204
+ }
205
+
206
+ /**
207
+ * Stress via 4th-order central difference in symmetric Voigt strain.
208
+ * 12 forward passes; bypasses autograd entirely.
209
+ *
210
+ * σ_voigt[k] = [8(E(+δ) - E(-δ)) - (E(+2δ) - E(-2δ))] / (12 V δ)
211
+ *
212
+ * Voigt[k] convention: (xx, yy, zz, yz, xz, xy). Off-diagonals use
213
+ * symmetric strain ε_αβ = ε_βα = η_k/2 (engineering shear) so the same
214
+ * formula applies to all six components.
215
+ */
216
+ std::vector<float> compute_fd_stress(const AtomicSystem &system,
217
+ float delta = 5e-3f) {
218
+ const auto *cell = system.cell();
219
+ if (!cell) {
220
+ return {};
221
+ }
222
+ const auto &m = cell->matrix;
223
+ double vol = static_cast<double>(m[0][0]) *
224
+ (static_cast<double>(m[1][1]) * m[2][2] -
225
+ static_cast<double>(m[1][2]) * m[2][1]) -
226
+ static_cast<double>(m[0][1]) *
227
+ (static_cast<double>(m[1][0]) * m[2][2] -
228
+ static_cast<double>(m[1][2]) * m[2][0]) +
229
+ static_cast<double>(m[0][2]) *
230
+ (static_cast<double>(m[1][0]) * m[2][1] -
231
+ static_cast<double>(m[1][1]) * m[2][0]);
232
+ vol = std::abs(vol);
233
+ if (vol < 1e-10) {
234
+ return {};
235
+ }
236
+
237
+ auto E_at = [&](int k, double scale) {
238
+ float eta[6] = {0, 0, 0, 0, 0, 0};
239
+ eta[k] = static_cast<float>(delta * scale);
240
+ auto strained = strain(system, eta);
241
+ return static_cast<double>(model->predict(strained, /*forces=*/false).energy);
242
+ };
243
+
244
+ std::vector<float> stress(6, 0.0f);
245
+ for (int k = 0; k < 6; ++k) {
246
+ double ep1 = E_at(k, +1.0);
247
+ double em1 = E_at(k, -1.0);
248
+ double ep2 = E_at(k, +2.0);
249
+ double em2 = E_at(k, -2.0);
250
+ stress[k] = static_cast<float>(
251
+ (8.0 * (ep1 - em1) - (ep2 - em2)) / (12.0 * vol * delta));
252
+ }
253
+ return stress;
254
+ }
255
+
166
256
  Result predict_impl(const AtomicSystem &system, const PredictOptions &options) {
167
257
  // Use predict_batch for NC forces support
168
258
  auto *pet_model = dynamic_cast<pet::PETModel *>(model.get());
@@ -185,6 +275,9 @@ struct Predictor::Impl {
185
275
  if (options.compute_stress && internal_result.has_stress) {
186
276
  result.stress = std::move(internal_result.stress);
187
277
  }
278
+ if (options.compute_stress && options.fd_stress) {
279
+ result.stress = compute_fd_stress(system);
280
+ }
188
281
  return result;
189
282
  } else {
190
283
  // Fallback for non-PET models
@@ -195,6 +288,9 @@ struct Predictor::Impl {
195
288
  if (!options.compute_stress) {
196
289
  result.stress.clear();
197
290
  }
291
+ if (options.compute_stress && options.fd_stress) {
292
+ result.stress = compute_fd_stress(system);
293
+ }
198
294
  return result;
199
295
  }
200
296
  }