-
Notifications
You must be signed in to change notification settings - Fork 10
Implement a C API for metatomic #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Luthaf
wants to merge
39
commits into
main
Choose a base branch
from
metatomic-core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
4d63a1a
Add an empty metatomic-core python package, re-exporting metatomic-torch
Luthaf 5a02190
Use pathlib for all path manipulations
Luthaf 5c12ebd
Switch main test runner from tox to cargo
Luthaf e1a4eff
Scaffold a new metatomic-core package
Luthaf 64e4bf5
Draft the C API for metatomic-core
Luthaf 18f8329
Implement PairListOptions json serialization
sofiia-chorna ec29dbc
Implement JSON serialization for `Quantity`
GardevoirX 45b7e30
Validate quantities names
Luthaf 0db2e09
Implement JSON serialization for ModelMetadata
alessandroforina 6a4c6e9
Add error handling based on metatensor
RMeli 659e305
Implement mta_string_t in the C API
johannes-spies 366b8f2
Port unit parsing from metatomic-torch
Luthaf 5c17a2f
document mta_model_t and related functions in C API
sofiia-chorna 9847ff8
Add ModelCapabilities to the JSON structs
Luthaf 6c2e8d0
Implement plugin registration and loading, model loading
frostedoyster 1661238
Add a C model registration test
frostedoyster 84465a5
Implement System in metatomic-core
Luthaf 1f5731b
Implement `mta_format_metadata`
GardevoirX ba9b610
Add unit conversion and error handling to C++
RMeli 5d3fc90
Add C++ documentation
Luthaf 94fc0dc
Expose mta_model_t function in rust's Model struct
alessandroforina 033df91
Cleanup CMake code calling cargo
Luthaf 53310d9
C++ API to format model metadata (#266)
RMeli 3d67ff1
Add C++ API for loading plugins
RMeli 579985b
Re-enable Windows Rust tests
Luthaf c013c54
Add a C API for systems
Luthaf 0b7e594
Separate C++ and C API tests
Luthaf 8deaa29
Better fix to "no module named __pip__" in tests
Luthaf c7ff8af
Bump MSRV to 1.88
Luthaf df1b2a6
Update to edition 2024
Luthaf 75246e1
Implement serialization for Systems
Luthaf faf6935
Remove double indirection (Box + Arc) in mta_system_t
Luthaf 54df008
C++ metadata classes with JSON serialization/deserialization (#277)
RMeli 95611b8
Implement System in the C++ API
frostedoyster 8cd42d6
Group all code accessing values in a new `kernels` module
Luthaf 6f7c2da
Add cuda kernels for system validation
Luthaf 55fa61c
Add custom metal kernels for system validation
Luthaf a87395e
Cache reference values on device
Luthaf 92913de
Remove cargo caching in CI, it interacts badly with our setup
Luthaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: Python tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| # Check all PR | ||
|
|
||
| concurrency: | ||
| group: python-tests-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
|
||
| jobs: | ||
| python-tests: | ||
| runs-on: ${{ matrix.os }} | ||
| name: ${{ matrix.os }} / Python ${{ matrix.python-version }} / Torch ${{ matrix.torch-version }} | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - os: ubuntu-24.04 | ||
| python-version: "3.10" | ||
| torch-version: "2.3" | ||
| numpy-version-pin: "<2.0" | ||
| # Do not run docs-tests with python 3.10 since torch-sim-atomistic | ||
| # is not available for this version of python | ||
| tox-envs: lint,torch-tests | ||
| - os: ubuntu-24.04 | ||
| python-version: "3.10" | ||
| torch-version: "2.13" | ||
| # See above | ||
| tox-envs: lint,torch-tests | ||
| - os: ubuntu-24.04 | ||
| # TorchScript is no longer supported in Python 3.14 | ||
| # so we keep a test with 3.13 to make sure this doesn't break | ||
| python-version: "3.13" | ||
| torch-version: "2.13" | ||
| tox-envs: lint,torch-tests,docs-tests | ||
| - os: ubuntu-24.04 | ||
| python-version: "3.14" | ||
| torch-version: "2.13" | ||
| tox-envs: lint,torch-tests,docs-tests | ||
| - os: macos-15 | ||
| python-version: "3.14" | ||
| torch-version: "2.13" | ||
| tox-envs: lint,torch-tests,docs-tests | ||
| - os: windows-2022 | ||
|
RMeli marked this conversation as resolved.
|
||
| python-version: "3.14" | ||
| torch-version: "2.13" | ||
| tox-envs: lint,torch-tests,docs-tests | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: setup Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: setup rust | ||
| uses: dtolnay/rust-toolchain@master | ||
| with: | ||
| toolchain: stable | ||
|
|
||
| - name: Setup sccache | ||
| if: ${{ !env.ACT }} | ||
| uses: mozilla-actions/sccache-action@v0.0.10 | ||
| with: | ||
| version: "v0.10.0" | ||
|
RMeli marked this conversation as resolved.
|
||
|
|
||
| - name: setup MSVC command prompt | ||
| uses: ilammy/msvc-dev-cmd@v1 | ||
|
|
||
| - name: Setup sccache environnement variables | ||
| if: ${{ !env.ACT }} | ||
| run: | | ||
| echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV | ||
| echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV | ||
| echo "CMAKE_C_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV | ||
| echo "CMAKE_CXX_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV | ||
|
|
||
| - name: install tests dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install tox coverage | ||
|
|
||
| - name: run tests | ||
| run: tox -e ${{ matrix.tox-envs }} | ||
| env: | ||
| PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu | ||
| METATOMIC_TESTS_TORCH_VERSION: ${{ matrix.torch-version }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| name: Rust tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| # Check all PR | ||
|
|
||
| concurrency: | ||
| group: rust-tests-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
|
||
| jobs: | ||
| rust-tests: | ||
| name: ${{ matrix.os }} / Rust ${{ matrix.rust-version }}${{ matrix.extra-name }} | ||
| runs-on: ${{ matrix.os }} | ||
| container: ${{ matrix.container }} | ||
| defaults: | ||
| run: | ||
| shell: "bash" | ||
| env: | ||
| CMAKE_CXX_COMPILER: ${{ matrix.cxx }} | ||
| CMAKE_C_COMPILER: ${{ matrix.cc }} | ||
| CMAKE_GENERATOR: ${{ matrix.cmake-generator }} | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| # test our MSRV | ||
| - os: ubuntu-24.04 | ||
| rust-version: 1.88 | ||
| rust-target: x86_64-unknown-linux-gnu | ||
| cxx: g++ | ||
| cc: gcc | ||
| cargo: cargo | ||
| cmake-generator: Unix Makefiles | ||
|
|
||
| # check the build on a stock Ubuntu 22.04, which uses cmake 3.22, and | ||
| # using cargo/rustc from APT | ||
| - os: ubuntu-24.04 | ||
| rust-version: from APT | ||
| container: ubuntu:22.04 | ||
| rust-target: x86_64-unknown-linux-gnu | ||
| extra-name: ", cmake 3.22" | ||
| cxx: g++ | ||
| cc: gcc | ||
| cargo: cargo-1.89 | ||
| cmake-generator: Unix Makefiles | ||
|
|
||
| - os: macos-15 | ||
|
RMeli marked this conversation as resolved.
|
||
| rust-version: stable | ||
| rust-target: aarch64-apple-darwin | ||
| cxx: clang++ | ||
| cc: clang | ||
| cargo: cargo | ||
| cmake-generator: Unix Makefiles | ||
|
|
||
| - os: windows-2022 | ||
| rust-version: stable | ||
| rust-target: x86_64-pc-windows-msvc | ||
| extra-name: " / MSVC" | ||
| cxx: cl.exe | ||
| cc: cl.exe | ||
| cargo: cargo | ||
| cmake-generator: Visual Studio 17 2022 | ||
|
|
||
| - os: windows-2022 | ||
| rust-version: stable | ||
| rust-target: x86_64-pc-windows-gnu | ||
| extra-name: " / MinGW" | ||
| cxx: g++.exe | ||
| cc: gcc.exe | ||
| cargo: cargo | ||
| cmake-generator: MinGW Makefiles | ||
| steps: | ||
| - name: install dependencies in container | ||
| if: matrix.container == 'ubuntu:22.04' | ||
| run: | | ||
| apt update | ||
| apt install -y software-properties-common | ||
| apt install -y cmake make gcc g++ git curl python3-venv cargo-1.89 | ||
|
|
||
| # for some reason, cargo-1.89 from APT tries to find `rustdoc` and | ||
| # not `rustdoc-1.89`, so we force it to use the correct one | ||
| echo "RUSTDOC=rustdoc-1.89" >> "$GITHUB_ENV" | ||
|
|
||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Configure git safe directory | ||
| if: matrix.container == 'ubuntu:22.04' | ||
| run: git config --global --add safe.directory /__w/metatomic/metatomic | ||
|
|
||
| - name: setup rust | ||
| uses: dtolnay/rust-toolchain@master | ||
| if: matrix.container == null | ||
| with: | ||
| toolchain: ${{ matrix.rust-version }} | ||
| target: ${{ matrix.rust-target }} | ||
|
|
||
| - name: setup Python | ||
| uses: actions/setup-python@v6 | ||
| if: matrix.container == null | ||
| with: | ||
| python-version: "3.14" | ||
|
|
||
| - name: install valgrind | ||
| if: matrix.do-valgrind | ||
| run: | | ||
| sudo apt-get install -y valgrind | ||
|
|
||
| - name: Setup sccache | ||
| if: ${{ !env.ACT }} | ||
| uses: mozilla-actions/sccache-action@v0.0.10 | ||
| with: | ||
| version: "v0.15.0" | ||
|
|
||
| - name: Setup sccache environnement variables | ||
| if: ${{ !env.ACT }} | ||
| run: | | ||
| echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV | ||
| echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV | ||
| echo "CMAKE_C_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV | ||
| echo "CMAKE_CXX_COMPILER_LAUNCHER=sccache" >> $GITHUB_ENV | ||
|
|
||
| - name: run tests | ||
| env: | ||
| RUST_BACKTRACE: full | ||
| run: | | ||
| ${{ matrix.cargo }} test --package metatomic-core --target ${{ matrix.rust-target }} | ||
|
|
||
| - name: check that the header was already up to date | ||
| run: | | ||
| git diff --exit-code | ||
|
|
||
| # check that the C API declarations are correctly documented and used | ||
| prevent-bitrot: | ||
| runs-on: ubuntu-24.04 | ||
| name: check C API declarations | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: setup Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.14" | ||
|
|
||
| - name: install python dependencies | ||
| run: | | ||
| pip install pycparser | ||
|
|
||
| - name: check that C API functions are all documented | ||
| run: | | ||
| python scripts/check-c-api-docs.py | ||
|
|
||
| # make sure no debug print stays in the code | ||
| check-debug-prints: | ||
| runs-on: ubuntu-24.04 | ||
| name: check leftover debug print | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: install ripgrep | ||
| run: | | ||
| wget https://github.com/BurntSushi/ripgrep/releases/download/13.0.0/ripgrep-13.0.0-x86_64-unknown-linux-musl.tar.gz | ||
| tar xf ripgrep-13.0.0-x86_64-unknown-linux-musl.tar.gz | ||
| echo "$(pwd)/ripgrep-13.0.0-x86_64-unknown-linux-musl" >> $GITHUB_PATH | ||
|
|
||
| - name: check for leftover dbg! | ||
| run: | | ||
| # use ripgrep (rg) to check for instances of `dbg!` in rust files. | ||
| # rg will return 1 if it fails to find a match, so we invert it again | ||
| # with the `!` builtin to get the error/success in CI | ||
|
|
||
| ! rg "dbg!" --type=rust --quiet | ||
|
|
||
| - name: check for leftover \#include <iostream> | ||
| run: | | ||
| ! rg "<iostream>" --iglob "\!metatomic-core/tests/cpp/external/catch/catch.hpp" --quiet | ||
|
|
||
| - name: check for leftover std::cout | ||
| run: | | ||
| ! rg "cout" --iglob "\!metatomic-core/tests/cpp/external/catch/catch.hpp" --quiet | ||
|
|
||
| - name: check for leftover std::cerr | ||
| run: | | ||
| ! rg "cerr" --iglob "\!metatomic-core/tests/cpp/external/catch/catch.hpp" --quiet | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.