mlipcpp 0.1.2__tar.gz → 0.1.3__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 (187) hide show
  1. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/.github/workflows/website.yml +3 -3
  2. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/.github/workflows/wheels.yml +1 -1
  3. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/CMakeLists.txt +39 -8
  4. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/PKG-INFO +1 -1
  5. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/include/mlipcpp/mlipcpp.hpp +54 -0
  6. mlipcpp-0.1.3/packages/mlip.js/examples/activations.html +393 -0
  7. mlipcpp-0.1.3/packages/mlip.js/examples/activations_smoke.mjs +84 -0
  8. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/packages/mlip.js/package-lock.json +2 -2
  9. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/packages/mlip.js/package.json +1 -1
  10. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/pyproject.toml +7 -1
  11. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/convert_models.py +2 -1
  12. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/export_pytorch/export_pet_full.py +81 -40
  13. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/export_pytorch/export_pet_gguf.py +41 -5
  14. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/CMakeLists.txt +38 -9
  15. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/api/c/mlipcpp_api.cpp +11 -3
  16. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/api/cpp/mlipcpp_cpp.cpp +130 -1
  17. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/api/fortran/mlipcpp.f90 +0 -4
  18. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/ggml_utils.cpp +13 -0
  19. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/ggml_utils.h +13 -0
  20. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/log.h +1 -0
  21. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/io/xyz.cpp +22 -21
  22. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/models/pet/pet.cpp +7 -3
  23. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/models/pet/pet_batch.cpp +5 -1
  24. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/models/pet/pet_layers.cpp +2 -2
  25. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/runtime/graph_interpreter.cpp +37 -2
  26. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/runtime/graph_interpreter.h +15 -0
  27. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/runtime/graph_ir.cpp +79 -17
  28. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/runtime/graph_model.cpp +216 -72
  29. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/runtime/graph_model.h +25 -2
  30. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_auto_vs_manual.cpp +15 -10
  31. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_graph_interpreter.cpp +107 -0
  32. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_python_api.py +4 -4
  33. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/uv.lock +1 -1
  34. mlipcpp-0.1.3/website/src/components/EditOverlay.svelte +158 -0
  35. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/EditPanel.svelte +74 -47
  36. mlipcpp-0.1.3/website/src/components/EditorHelp.svelte +197 -0
  37. mlipcpp-0.1.3/website/src/components/PeriodicTable.svelte +194 -0
  38. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/StructureLoader.svelte +14 -1
  39. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/Viewer.svelte +431 -70
  40. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/ViewerControls.svelte +4 -40
  41. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/chem/elements.ts +19 -1
  42. mlipcpp-0.1.3/website/src/lib/data/samples.ts +244 -0
  43. mlipcpp-0.1.3/website/src/lib/editor/editorMachine.svelte.ts +163 -0
  44. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/editor/hydrogens.ts +22 -0
  45. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/Stage.ts +11 -5
  46. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/data/elements.ts +19 -2
  47. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/data/jmolColors.ts +4 -0
  48. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/stores/simulation.svelte.ts +39 -17
  49. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/worker/mdWorker.ts +7 -18
  50. mlipcpp-0.1.2/website/src/components/EditOverlay.svelte +0 -102
  51. mlipcpp-0.1.2/website/src/components/PeriodicTable.svelte +0 -112
  52. mlipcpp-0.1.2/website/src/lib/data/samples.ts +0 -93
  53. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/.clang-format +0 -0
  54. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/.github/workflows/build_wasm.yml +0 -0
  55. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/.github/workflows/ci.yml +0 -0
  56. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/.gitignore +0 -0
  57. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/.gitmodules +0 -0
  58. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/LICENSE +0 -0
  59. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/README.md +0 -0
  60. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/cmake/PythonBindings.cmake +0 -0
  61. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/cmake/mlipcppConfig.cmake.in +0 -0
  62. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/examples/CMakeLists.txt +0 -0
  63. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/examples/backend_benchmark.cpp +0 -0
  64. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/examples/c_api_test.c +0 -0
  65. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/examples/cpp_api_test.cpp +0 -0
  66. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/examples/fortran_api_test.f90 +0 -0
  67. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/examples/python_ase.py +0 -0
  68. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/examples/python_basic.py +0 -0
  69. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/examples/python_comparison.py +0 -0
  70. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/examples/simple_inference.cpp +0 -0
  71. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/geometries/si.xyz +0 -0
  72. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/geometries/urea.cif +0 -0
  73. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/geometries/urea.xyz +0 -0
  74. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/geometries/urea_molecule.xyz +0 -0
  75. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/geometries/water.xyz +0 -0
  76. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/gguf/LICENSE +0 -0
  77. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/gguf/README.md +0 -0
  78. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/include/mlipcpp/io.h +0 -0
  79. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/include/mlipcpp/mlipcpp.h +0 -0
  80. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/include/mlipcpp/model.h +0 -0
  81. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/include/mlipcpp/neighbor_list.h +0 -0
  82. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/include/mlipcpp/system.h +0 -0
  83. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/include/mlipcpp/timer.h +0 -0
  84. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/packages/mlip.js/LICENSE +0 -0
  85. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/packages/mlip.js/README.md +0 -0
  86. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/packages/mlip.js/examples/basic.html +0 -0
  87. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/packages/mlip.js/scripts/build.js +0 -0
  88. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/python/mlipcpp/__init__.py +0 -0
  89. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/python/mlipcpp/ase.py +0 -0
  90. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/__init__.py +0 -0
  91. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/benchmark_backends.sh +0 -0
  92. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/benchmark_graph_inference_forces.py +0 -0
  93. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/benchmark_pet_full_torch_compile.py +0 -0
  94. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/build_wasm.sh +0 -0
  95. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/calc_energy_pytorch.py +0 -0
  96. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/convert_cif_to_extxyz.py +0 -0
  97. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/convert_pet_mad.py +0 -0
  98. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/export_pytorch/__init__.py +0 -0
  99. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/export_pytorch/fx_converter.py +0 -0
  100. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/export_pytorch/graph_ir.py +0 -0
  101. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/publish_ggufs.py +0 -0
  102. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/test_all_models.py +0 -0
  103. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/test_all_models.sh +0 -0
  104. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/scripts/test_stress_fd.py +0 -0
  105. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/api/python/mlipcpp_bindings.cpp +0 -0
  106. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/bin/graph_inference.cpp +0 -0
  107. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/backend.cpp +0 -0
  108. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/backend.h +0 -0
  109. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/gguf_loader.cpp +0 -0
  110. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/gguf_loader.h +0 -0
  111. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/neighbor_list.cpp +0 -0
  112. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/system.cpp +0 -0
  113. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/core/timer.cpp +0 -0
  114. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/ggml_attention.cpp +0 -0
  115. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/ggml_attention.h +0 -0
  116. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/models/model.cpp +0 -0
  117. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/models/pet/pet.h +0 -0
  118. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/models/pet/pet_batch.h +0 -0
  119. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/models/pet/pet_graph.h +0 -0
  120. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/models/pet/pet_types.h +0 -0
  121. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/src/runtime/graph_ir.h +0 -0
  122. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/CMakeLists.txt +0 -0
  123. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_backend_selection.cpp +0 -0
  124. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_full_export.cpp +0 -0
  125. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_ggml_layout.cpp +0 -0
  126. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_graph_model.cpp +0 -0
  127. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_io.cpp +0 -0
  128. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_main.cpp +0 -0
  129. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_neighbor_list.cpp +0 -0
  130. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_pet.cpp +0 -0
  131. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_pet_gradients.cpp +0 -0
  132. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/tests/test_system.cpp +0 -0
  133. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/.gitignore +0 -0
  134. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/bench.html +0 -0
  135. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/bun.lock +0 -0
  136. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/index.html +0 -0
  137. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/package.json +0 -0
  138. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/public/favicon.svg +0 -0
  139. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/App.svelte +0 -0
  140. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/bench-main.ts +0 -0
  141. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/EnergyPlot.svelte +0 -0
  142. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/MDParams.svelte +0 -0
  143. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/ModelLoader.svelte +0 -0
  144. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/OptParams.svelte +0 -0
  145. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/RunControls.svelte +0 -0
  146. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/Segmented.svelte +0 -0
  147. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/Stats.svelte +0 -0
  148. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/VibrationsPanel.svelte +0 -0
  149. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/components/XyzEditorModal.svelte +0 -0
  150. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/chem/bonds.ts +0 -0
  151. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/chem/cell.ts +0 -0
  152. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/chem/pubchem.ts +0 -0
  153. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/chem/sdf.ts +0 -0
  154. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/chem/supercell.ts +0 -0
  155. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/chem/xyz.ts +0 -0
  156. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/editor/fragments.ts +0 -0
  157. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/editor/ghostFlash.ts +0 -0
  158. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/editor/transform.svelte.ts +0 -0
  159. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/Selection.ts +0 -0
  160. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/StructureObject.ts +0 -0
  161. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/UnitCell.ts +0 -0
  162. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/adapter.ts +0 -0
  163. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/data/bonds.ts +0 -0
  164. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/data/colors.ts +0 -0
  165. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/data/types.ts +0 -0
  166. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/impostorSettings.ts +0 -0
  167. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/lighting.ts +0 -0
  168. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/materialStyles.ts +0 -0
  169. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/plugins/PathTracerPlugin.ts +0 -0
  170. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/representations/BallAndStick.ts +0 -0
  171. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/representations/ImpostorBallAndStick.ts +0 -0
  172. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/representations/ImpostorSpacefill.ts +0 -0
  173. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/representations/Spacefill.ts +0 -0
  174. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/representations/Tube.ts +0 -0
  175. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/representations/Wireframe.ts +0 -0
  176. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/molview/representations/types.ts +0 -0
  177. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/vib/jacobi.ts +0 -0
  178. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/vib/modes.ts +0 -0
  179. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/vib/projector.ts +0 -0
  180. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/lib/worker/simulation.ts +0 -0
  181. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/main.ts +0 -0
  182. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/styles/app.css +0 -0
  183. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/src/vite-env.d.ts +0 -0
  184. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/svelte.config.js +0 -0
  185. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/tsconfig.json +0 -0
  186. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/tsconfig.node.json +0 -0
  187. {mlipcpp-0.1.2 → mlipcpp-0.1.3}/website/vite.config.ts +0 -0
@@ -53,13 +53,13 @@ jobs:
53
53
  run: npm install
54
54
 
55
55
  # Cache the bundled GGUF across runs so we don't re-download from HF on
56
- # every build. Keyed on the URL + filename so a model bump in
57
- # package.json invalidates the cache automatically.
56
+ # every build. Keyed on package.json (the fetch URL) and the model
57
+ # converter, so a re-export published to HF invalidates the cache.
58
58
  - name: Cache bundled GGUF
59
59
  uses: actions/cache@v4
60
60
  with:
61
61
  path: website/public/pet-mad-xs.gguf
62
- key: gguf-pet-mad-xs-${{ hashFiles('website/package.json') }}
62
+ key: gguf-pet-mad-xs-${{ hashFiles('website/package.json', 'scripts/convert_models.py') }}
63
63
 
64
64
  - name: Build WASM (both variants)
65
65
  working-directory: packages/mlip.js
@@ -30,7 +30,7 @@ jobs:
30
30
  include:
31
31
  - os: ubuntu-latest
32
32
  arch: x86_64
33
- - os: macos-14
33
+ - os: macos-15
34
34
  arch: arm64
35
35
  steps:
36
36
  - uses: actions/checkout@v4
@@ -1,5 +1,5 @@
1
1
  cmake_minimum_required(VERSION 3.18)
2
- project(mlipcpp VERSION 0.1.2 LANGUAGES CXX C)
2
+ project(mlipcpp VERSION 0.1.3 LANGUAGES CXX C)
3
3
 
4
4
  set(CMAKE_CXX_STANDARD 20)
5
5
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -27,6 +27,7 @@ option(MLIPCPP_BUILD_TESTS "Build tests" OFF)
27
27
  option(MLIPCPP_BUILD_FORTRAN "Build Fortran bindings" OFF)
28
28
  option(MLIPCPP_BUILD_PYTHON "Build Python bindings" OFF)
29
29
  option(MLIPCPP_INSTALL "Generate install target" OFF)
30
+ option(MLIPCPP_BUILD_SHARED "Build libmlipcpp (and the Fortran bindings) as shared libraries; ggml/fmt are always linked in statically" OFF)
30
31
  option(MLIPCPP_USE_CUDA "Enable CUDA backend via ggml" OFF)
31
32
  option(MLIPCPP_USE_HIP "Enable HIP/ROCm backend via ggml (AMD)" OFF)
32
33
  option(MLIPCPP_USE_METAL "Enable Metal backend via ggml" OFF)
@@ -79,6 +80,24 @@ if(MLIPCPP_BUILD_PYTHON)
79
80
  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
80
81
  endif()
81
82
 
83
+ # =============================================================================
84
+ # Compiler-specific settings (apply to mlipcpp *and* ggml below)
85
+ # =============================================================================
86
+ # Intel icx/icpx default to -fp-model=fast, which implies finite-math-only.
87
+ # ggml's softmax / flash attention and our attention masks rely on -INFINITY
88
+ # comparisons that fast-math is allowed to fold away (producing NaNs), so
89
+ # keep IEEE semantics for every C/C++ target in this directory tree.
90
+ foreach(_lang C CXX)
91
+ if(CMAKE_${_lang}_COMPILER_ID STREQUAL "IntelLLVM")
92
+ if(CMAKE_${_lang}_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
93
+ add_compile_options("$<$<COMPILE_LANGUAGE:${_lang}>:/fp:precise>")
94
+ else()
95
+ add_compile_options("$<$<COMPILE_LANGUAGE:${_lang}>:-fp-model=precise>")
96
+ endif()
97
+ endif()
98
+ endforeach()
99
+ unset(_lang)
100
+
82
101
  # =============================================================================
83
102
  # Dependencies (via CPM)
84
103
  # =============================================================================
@@ -121,9 +140,19 @@ endif()
121
140
  # Use MLIPCPP_GGML_SOURCE_DIR to point to a local ggml checkout for development
122
141
  set(MLIPCPP_GGML_SOURCE_DIR "" CACHE PATH "Path to local ggml source directory (for development)")
123
142
 
124
- set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
125
- set(GGML_BUILD_TESTS OFF CACHE BOOL "" FORCE)
126
- set(GGML_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
143
+ # Dependencies (ggml, fmt, ...) are always built as static libraries and
144
+ # linked into mlipcpp; whether mlipcpp itself is shared is controlled by
145
+ # MLIPCPP_BUILD_SHARED. These are normal (directory-scoped) variables rather
146
+ # than FORCEd cache entries so they never override a parent project's
147
+ # BUILD_SHARED_LIBS when mlipcpp is consumed via add_subdirectory /
148
+ # FetchContent. The dependencies' option() calls honour them (CMP0077).
149
+ set(BUILD_SHARED_LIBS OFF)
150
+ set(GGML_BUILD_TESTS OFF)
151
+ set(GGML_BUILD_EXAMPLES OFF)
152
+ if(MLIPCPP_BUILD_SHARED)
153
+ # The static dependencies end up inside a shared library.
154
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
155
+ endif()
127
156
 
128
157
  # Configure ggml backend options based on mlipcpp options
129
158
  if(MLIPCPP_USE_CUDA)
@@ -192,7 +221,7 @@ else()
192
221
  CPMAddPackage(
193
222
  NAME ggml
194
223
  GITHUB_REPOSITORY peterspackman/ggml
195
- GIT_TAG 9be7b7f8
224
+ GIT_TAG 7b2db3c7
196
225
  EXCLUDE_FROM_ALL YES
197
226
  )
198
227
  endif()
@@ -204,7 +233,7 @@ elseif(NOT EMSCRIPTEN)
204
233
  CPMAddPackage(
205
234
  NAME fmt
206
235
  GITHUB_REPOSITORY fmtlib/fmt
207
- GIT_TAG 11.0.2
236
+ GIT_TAG 11.1.4
208
237
  OPTIONS
209
238
  "FMT_INSTALL OFF"
210
239
  EXCLUDE_FROM_ALL YES
@@ -224,6 +253,9 @@ CPMAddPackage(
224
253
  # =============================================================================
225
254
  # Library
226
255
  # =============================================================================
256
+ # GNUInstallDirs must be included before src/ so CMAKE_INSTALL_INCLUDEDIR is
257
+ # defined when the INSTALL_INTERFACE include paths are recorded.
258
+ include(GNUInstallDirs)
227
259
  add_subdirectory(src)
228
260
 
229
261
  # Enable CTest before descending into examples/, so add_test() calls there
@@ -296,7 +328,6 @@ endif()
296
328
  # Installation
297
329
  # =============================================================================
298
330
  if(MLIPCPP_INSTALL)
299
- include(GNUInstallDirs)
300
331
  include(CMakePackageConfigHelpers)
301
332
 
302
333
  # Install headers
@@ -311,7 +342,7 @@ if(MLIPCPP_INSTALL)
311
342
  list(APPEND MLIPCPP_EXPORT_TARGETS mlipcpp_fortran)
312
343
 
313
344
  # Install Fortran module files
314
- install(DIRECTORY ${CMAKE_BINARY_DIR}/fortran_modules/
345
+ install(DIRECTORY ${PROJECT_BINARY_DIR}/fortran_modules/
315
346
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mlipcpp/fortran
316
347
  FILES_MATCHING PATTERN "*.mod"
317
348
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mlipcpp
3
- Version: 0.1.2
3
+ Version: 0.1.3
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
@@ -9,6 +9,8 @@
9
9
  #define MLIPCPP_HPP
10
10
 
11
11
  #include <array>
12
+ #include <cstddef>
13
+ #include <cstdint>
12
14
  #include <memory>
13
15
  #include <optional>
14
16
  #include <span>
@@ -65,6 +67,38 @@ struct ModelOptions {
65
67
  float cutoff_override = 0.0f; ///< 0 = use model default
66
68
  };
67
69
 
70
+ /**
71
+ * @brief A single intermediate tensor captured during inference.
72
+ *
73
+ * Returned by Predictor::predict_with_activations(). Data is held as raw
74
+ * bytes; the caller interprets them according to `dtype` and `shape`.
75
+ *
76
+ * Node id conventions (mirroring the GIR graph):
77
+ * - >= 0 : matches the GIR node id
78
+ * - -1000, -1001, ... : synthetic ids for model inputs (one per input)
79
+ * - 9999 : the final model output
80
+ *
81
+ * Supported dtypes (others are emitted with empty data):
82
+ * "f32", "f16" (converted to f32 in `data`), "i32", "i8" (bool/byte)
83
+ */
84
+ struct NodeActivation {
85
+ int node_id = 0;
86
+ std::string name; ///< human-readable node name
87
+ std::string dtype; ///< element type (after any f16->f32 conversion)
88
+ std::vector<int64_t> shape; ///< up to 4 entries
89
+ std::vector<uint8_t> data; ///< raw bytes; size == n_elements * elt_size
90
+ };
91
+
92
+ /**
93
+ * @brief Result of Predictor::predict_with_activations.
94
+ *
95
+ * Carries the usual energy/forces/stress alongside per-node activations.
96
+ */
97
+ struct ActivationResult {
98
+ Result prediction;
99
+ std::vector<NodeActivation> activations;
100
+ };
101
+
68
102
  /**
69
103
  * @brief Options for prediction
70
104
  */
@@ -191,6 +225,26 @@ public:
191
225
  const int32_t *atomic_numbers, const float *cell,
192
226
  const bool *pbc, const PredictOptions &options);
193
227
 
228
+ /**
229
+ * @brief Predict energy and capture every intermediate tensor.
230
+ *
231
+ * Runs the energy graph and collects each node's output (plus inputs and
232
+ * the final output) for inspection. Intended for debugging, parity
233
+ * checks, and live-trace visualisation; not optimised for throughput.
234
+ *
235
+ * Only supported for graph-based models (architecture "pet-graph").
236
+ * Throws std::runtime_error for legacy model paths or non-CPU backends
237
+ * that haven't been validated for readback.
238
+ *
239
+ * Forces are not captured in this v1 — the visualisation contract is
240
+ * energy-only (see ACTIVATION_CAPTURE.md, open question 1).
241
+ */
242
+ ActivationResult predict_with_activations(int32_t n_atoms,
243
+ const float *positions,
244
+ const int32_t *atomic_numbers,
245
+ const float *cell = nullptr,
246
+ const bool *pbc = nullptr);
247
+
194
248
  private:
195
249
  struct Impl;
196
250
  std::unique_ptr<Impl> impl_;
@@ -0,0 +1,393 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>mlip.js — activation inspector</title>
7
+ <style>
8
+ :root {
9
+ --fg: #1a1a1a;
10
+ --muted: #666;
11
+ --bg: #fafafa;
12
+ --panel: #fff;
13
+ --border: #e5e5e5;
14
+ --accent: #0066cc;
15
+ --good: #0a8d3a;
16
+ --bad: #c0392b;
17
+ }
18
+ * { box-sizing: border-box; }
19
+ body {
20
+ margin: 0;
21
+ font: 14px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
22
+ color: var(--fg);
23
+ background: var(--bg);
24
+ }
25
+ header {
26
+ padding: 12px 20px;
27
+ background: var(--panel);
28
+ border-bottom: 1px solid var(--border);
29
+ }
30
+ h1 { font-size: 16px; margin: 0 0 4px 0; }
31
+ .sub { color: var(--muted); font-size: 12px; }
32
+ main {
33
+ display: grid;
34
+ grid-template-columns: 320px 1fr;
35
+ gap: 12px;
36
+ padding: 12px 20px;
37
+ height: calc(100vh - 56px);
38
+ }
39
+ .panel {
40
+ background: var(--panel);
41
+ border: 1px solid var(--border);
42
+ border-radius: 4px;
43
+ padding: 12px;
44
+ overflow: auto;
45
+ }
46
+ label { display: block; font-weight: 500; margin: 8px 0 4px; }
47
+ input[type=file], select, button, textarea {
48
+ font: inherit;
49
+ padding: 6px 8px;
50
+ border: 1px solid var(--border);
51
+ border-radius: 3px;
52
+ background: white;
53
+ color: var(--fg);
54
+ }
55
+ button {
56
+ background: var(--accent);
57
+ color: white;
58
+ border: none;
59
+ cursor: pointer;
60
+ padding: 8px 14px;
61
+ font-weight: 500;
62
+ }
63
+ button:disabled { background: #ccc; cursor: not-allowed; }
64
+ textarea { width: 100%; height: 90px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12px; }
65
+ .status { color: var(--muted); margin-top: 8px; font-size: 12px; }
66
+ .status.err { color: var(--bad); }
67
+ .status.ok { color: var(--good); }
68
+
69
+ #right { display: grid; grid-template-rows: auto 1fr auto; gap: 8px; padding: 0; }
70
+ #summary { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
71
+ #summary span.k { color: var(--muted); margin-right: 4px; }
72
+ #summary span.v { font-family: ui-monospace, 'SF Mono', Menlo, monospace; margin-right: 14px; }
73
+
74
+ #tableWrap { overflow: auto; }
75
+ table { width: 100%; border-collapse: collapse; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12px; }
76
+ thead th {
77
+ position: sticky; top: 0;
78
+ background: #f0f0f0;
79
+ text-align: left;
80
+ padding: 6px 10px;
81
+ border-bottom: 1px solid var(--border);
82
+ cursor: pointer;
83
+ user-select: none;
84
+ }
85
+ thead th:hover { background: #e6e6e6; }
86
+ thead th.sort-asc::after { content: ' ▲'; color: var(--accent); }
87
+ thead th.sort-desc::after { content: ' ▼'; color: var(--accent); }
88
+ tbody tr { cursor: pointer; }
89
+ tbody tr:hover { background: #f4f8ff; }
90
+ tbody tr.selected { background: #dceaff; }
91
+ tbody td { padding: 4px 10px; border-bottom: 1px solid #f0f0f0; }
92
+ td.num { text-align: right; }
93
+ td.name { color: var(--accent); }
94
+ td.dtype.f32 { color: #555; }
95
+ td.dtype.i32 { color: #b06; }
96
+ td.dtype.i8 { color: #960; }
97
+
98
+ #preview {
99
+ border-top: 1px solid var(--border);
100
+ padding: 10px 12px;
101
+ font-family: ui-monospace, 'SF Mono', Menlo, monospace;
102
+ font-size: 12px;
103
+ max-height: 200px;
104
+ overflow: auto;
105
+ white-space: pre-wrap;
106
+ background: #fafbfc;
107
+ }
108
+ #preview h3 { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 13px; margin: 0 0 6px; color: var(--muted); font-weight: 500; }
109
+ </style>
110
+ </head>
111
+ <body>
112
+ <header>
113
+ <h1>mlip.js · activation inspector</h1>
114
+ <div class="sub">Run a graph model on a system and browse every intermediate tensor.</div>
115
+ </header>
116
+
117
+ <main>
118
+ <aside class="panel">
119
+ <label>Backend</label>
120
+ <select id="backendSel">
121
+ <option value="cpu">CPU</option>
122
+ <option value="webgpu">WebGPU</option>
123
+ <option value="auto">auto</option>
124
+ </select>
125
+
126
+ <label>1. Load GGUF model</label>
127
+ <input type="file" id="modelFile" accept=".gguf">
128
+
129
+ <label>2. Geometry</label>
130
+ <select id="presetSel">
131
+ <option value="water">Water (H₂O)</option>
132
+ <option value="methane">Methane (CH₄)</option>
133
+ <option value="custom">Custom XYZ…</option>
134
+ </select>
135
+ <textarea id="xyzInput" placeholder="Paste XYZ here (only used when 'Custom XYZ…' is selected)"></textarea>
136
+
137
+ <label>3. Run</label>
138
+ <button id="runBtn" disabled>Capture activations</button>
139
+
140
+ <div id="status" class="status">Loading mlip.js…</div>
141
+ </aside>
142
+
143
+ <section id="right" class="panel">
144
+ <div id="summary"></div>
145
+ <div id="tableWrap">
146
+ <table id="actTable">
147
+ <thead>
148
+ <tr>
149
+ <th data-key="node_id">id</th>
150
+ <th data-key="name">name</th>
151
+ <th data-key="dtype">dtype</th>
152
+ <th data-key="shape_str">shape</th>
153
+ <th data-key="n_elements" class="num">n</th>
154
+ <th data-key="min" class="num">min</th>
155
+ <th data-key="max" class="num">max</th>
156
+ <th data-key="mean" class="num">mean</th>
157
+ </tr>
158
+ </thead>
159
+ <tbody></tbody>
160
+ </table>
161
+ </div>
162
+ <div id="preview"><h3>Click a row to preview values</h3></div>
163
+ </section>
164
+ </main>
165
+
166
+ <script type="module">
167
+ import createMlip from '../dist/index.browser.js';
168
+
169
+ const els = {
170
+ status: document.getElementById('status'),
171
+ backendSel: document.getElementById('backendSel'),
172
+ modelFile: document.getElementById('modelFile'),
173
+ presetSel: document.getElementById('presetSel'),
174
+ xyzInput: document.getElementById('xyzInput'),
175
+ runBtn: document.getElementById('runBtn'),
176
+ summary: document.getElementById('summary'),
177
+ tbody: document.querySelector('#actTable tbody'),
178
+ ths: document.querySelectorAll('#actTable th'),
179
+ preview: document.getElementById('preview'),
180
+ };
181
+
182
+ // Pre-canned geometries (Å). Format matches mlip.js AtomicSystem.create().
183
+ const PRESETS = {
184
+ water: {
185
+ positions: new Float64Array([
186
+ 0.0, 0.000, 0.117,
187
+ 0.0, 0.757, -0.469,
188
+ 0.0, -0.757, -0.469,
189
+ ]),
190
+ Z: new Int32Array([8, 1, 1]),
191
+ },
192
+ methane: {
193
+ positions: new Float64Array([
194
+ 0.000, 0.000, 0.000,
195
+ 0.629, 0.629, 0.629,
196
+ -0.629, -0.629, 0.629,
197
+ -0.629, 0.629, -0.629,
198
+ 0.629, -0.629, -0.629,
199
+ ]),
200
+ Z: new Int32Array([6, 1, 1, 1, 1]),
201
+ },
202
+ };
203
+
204
+ function setStatus(msg, kind) {
205
+ els.status.textContent = msg;
206
+ els.status.className = 'status ' + (kind ?? '');
207
+ }
208
+
209
+ // Minimal XYZ parser: skip header lines, then `<element> x y z` per line.
210
+ const PERIODIC = ['', 'H','He','Li','Be','B','C','N','O','F','Ne','Na','Mg','Al','Si','P','S','Cl','Ar','K','Ca'];
211
+ const ELEM_TO_Z = Object.fromEntries(PERIODIC.map((s, i) => [s.toLowerCase(), i]).filter(([s]) => s));
212
+ function parseXyz(text) {
213
+ const lines = text.trim().split(/\r?\n/);
214
+ const n = parseInt(lines[0], 10);
215
+ if (!Number.isFinite(n)) throw new Error('XYZ: first line must be the atom count.');
216
+ const positions = new Float64Array(n * 3);
217
+ const Z = new Int32Array(n);
218
+ for (let i = 0; i < n; i++) {
219
+ const parts = lines[2 + i].trim().split(/\s+/);
220
+ const z = ELEM_TO_Z[parts[0].toLowerCase()];
221
+ if (!z) throw new Error(`XYZ: unknown element '${parts[0]}'`);
222
+ Z[i] = z;
223
+ positions[i*3] = parseFloat(parts[1]);
224
+ positions[i*3+1] = parseFloat(parts[2]);
225
+ positions[i*3+2] = parseFloat(parts[3]);
226
+ }
227
+ return { positions, Z };
228
+ }
229
+
230
+ function getGeometry() {
231
+ const sel = els.presetSel.value;
232
+ if (sel === 'custom') return parseXyz(els.xyzInput.value);
233
+ return PRESETS[sel];
234
+ }
235
+
236
+ // --- main state ---
237
+ let Module = null;
238
+ let model = null;
239
+ let rows = []; // [{node_id, name, dtype, shape, shape_str, data, n_elements, min, max, mean}]
240
+ let sortKey = 'node_id';
241
+ let sortDir = 1; // 1 asc, -1 desc
242
+
243
+ function statsOf(arr) {
244
+ if (!arr || arr.length === 0) return { min: NaN, max: NaN, mean: NaN };
245
+ let mn = Infinity, mx = -Infinity, sum = 0;
246
+ for (let i = 0; i < arr.length; i++) {
247
+ const v = arr[i];
248
+ if (v < mn) mn = v;
249
+ if (v > mx) mx = v;
250
+ sum += v;
251
+ }
252
+ return { min: mn, max: mx, mean: sum / arr.length };
253
+ }
254
+
255
+ const fmt = v => Number.isFinite(v) ? v.toExponential(2) : '—';
256
+
257
+ function renderTable() {
258
+ const sorted = rows.slice().sort((a, b) => {
259
+ const x = a[sortKey], y = b[sortKey];
260
+ if (x === y) return 0;
261
+ if (x === undefined || x === null || Number.isNaN(x)) return 1;
262
+ if (y === undefined || y === null || Number.isNaN(y)) return -1;
263
+ return (x < y ? -1 : 1) * sortDir;
264
+ });
265
+ // Build the rows in one string for speed (a few hundred rows max).
266
+ const html = sorted.map(r => `
267
+ <tr data-id="${r.node_id}">
268
+ <td class="num">${r.node_id}</td>
269
+ <td class="name">${r.name}</td>
270
+ <td class="dtype ${r.dtype}">${r.dtype}</td>
271
+ <td>${r.shape_str}</td>
272
+ <td class="num">${r.n_elements}</td>
273
+ <td class="num">${fmt(r.min)}</td>
274
+ <td class="num">${fmt(r.max)}</td>
275
+ <td class="num">${fmt(r.mean)}</td>
276
+ </tr>`).join('');
277
+ els.tbody.innerHTML = html;
278
+ els.ths.forEach(th => {
279
+ th.classList.remove('sort-asc', 'sort-desc');
280
+ if (th.dataset.key === sortKey) {
281
+ th.classList.add(sortDir > 0 ? 'sort-asc' : 'sort-desc');
282
+ }
283
+ });
284
+ }
285
+
286
+ els.ths.forEach(th => {
287
+ th.addEventListener('click', () => {
288
+ const k = th.dataset.key;
289
+ if (sortKey === k) sortDir = -sortDir;
290
+ else { sortKey = k; sortDir = 1; }
291
+ renderTable();
292
+ });
293
+ });
294
+
295
+ els.tbody.addEventListener('click', e => {
296
+ const tr = e.target.closest('tr');
297
+ if (!tr) return;
298
+ const id = parseInt(tr.dataset.id, 10);
299
+ const r = rows.find(x => x.node_id === id);
300
+ if (!r) return;
301
+ els.tbody.querySelectorAll('tr.selected').forEach(t => t.classList.remove('selected'));
302
+ tr.classList.add('selected');
303
+ const n = Math.min(r.data.length, 64);
304
+ const head = Array.from(r.data.slice(0, n))
305
+ .map(v => typeof v === 'number' ? v.toFixed(4) : String(v))
306
+ .join(', ');
307
+ els.preview.innerHTML =
308
+ `<h3>id ${r.node_id} · ${r.name} · [${r.shape_str}] · ${r.dtype} · ${r.n_elements} elts</h3>` +
309
+ `[${head}${r.data.length > n ? `, … (+${r.data.length - n} more)` : ''}]`;
310
+ });
311
+
312
+ // --- init ---
313
+ // Module is (re)created when the user picks a model, with the selected
314
+ // backend. This lets you switch CPU<->WebGPU without reloading the page.
315
+ async function ensureModule() {
316
+ const backend = els.backendSel.value;
317
+ if (Module && Module.__backend === backend) return Module;
318
+ Module = await createMlip({ backend });
319
+ Module.__backend = backend;
320
+ return Module;
321
+ }
322
+
323
+ setStatus('Pick a backend and load a model.', 'ok');
324
+
325
+ els.modelFile.addEventListener('change', async e => {
326
+ const file = e.target.files[0];
327
+ if (!file) return;
328
+ setStatus(`Loading ${file.name}…`);
329
+ els.runBtn.disabled = true;
330
+ try {
331
+ const mod = await ensureModule();
332
+ const v = await mod.getVersion();
333
+ const buf = await file.arrayBuffer();
334
+ // await everywhere so this works against both the CPU build
335
+ // (sync) and the GPU build (ASYNCIFY → all calls return Promises).
336
+ model = await mod.Model.loadFromBuffer(buf);
337
+ const [type, cutoff] = await Promise.all([model.modelType(), model.cutoff()]);
338
+ setStatus(`mlip.js v${v} · ${els.backendSel.value} · ${type} · cutoff ${cutoff.toFixed(2)} Å`, 'ok');
339
+ els.runBtn.disabled = false;
340
+ } catch (err) {
341
+ setStatus('Failed to load model: ' + err.message, 'err');
342
+ console.error(err);
343
+ }
344
+ });
345
+
346
+ els.runBtn.addEventListener('click', async () => {
347
+ if (!model) return;
348
+ els.runBtn.disabled = true;
349
+ setStatus('Running…');
350
+ try {
351
+ const { positions, Z } = getGeometry();
352
+ const mod = await ensureModule();
353
+ const sys = await mod.AtomicSystem.create(positions, Z, null, false);
354
+ const t0 = performance.now();
355
+ const result = await model.predictWithActivations(sys);
356
+ const elapsed = performance.now() - t0;
357
+
358
+ rows = [];
359
+ let totalBytes = 0;
360
+ for (const [id, a] of result.activations) {
361
+ totalBytes += a.data ? a.data.byteLength : 0;
362
+ const stats = a.dtype === 'f32' ? statsOf(a.data) : { min: NaN, max: NaN, mean: NaN };
363
+ rows.push({
364
+ node_id: id,
365
+ name: a.name,
366
+ dtype: a.dtype,
367
+ shape: a.shape,
368
+ shape_str: a.shape.join('×'),
369
+ data: a.data ?? new Float32Array(),
370
+ n_elements: a.data ? a.data.length : 0,
371
+ ...stats,
372
+ });
373
+ }
374
+
375
+ els.summary.innerHTML =
376
+ `<span class="k">energy</span><span class="v">${result.energy.toFixed(6)} eV</span>` +
377
+ `<span class="k">atoms</span><span class="v">${Z.length}</span>` +
378
+ `<span class="k">tensors</span><span class="v">${rows.length}</span>` +
379
+ `<span class="k">payload</span><span class="v">${(totalBytes / 1024).toFixed(1)} KiB</span>` +
380
+ `<span class="k">time</span><span class="v">${elapsed.toFixed(1)} ms</span>`;
381
+ renderTable();
382
+ els.preview.innerHTML = '<h3>Click a row to preview values</h3>';
383
+ setStatus(`Captured ${rows.length} tensors in ${elapsed.toFixed(1)} ms.`, 'ok');
384
+ } catch (err) {
385
+ setStatus('Run failed: ' + err.message, 'err');
386
+ console.error(err);
387
+ } finally {
388
+ els.runBtn.disabled = false;
389
+ }
390
+ });
391
+ </script>
392
+ </body>
393
+ </html>