Building from source¶
Note
End users should not need this page. The published PyPI wheels are expected to cover the vast majority of use cases — see Basic installation. Build from source if you are contributing to NEML2 itself, debugging a build flavor the wheels don’t ship, or experimenting with a custom LibTorch.
Quick start¶
git clone -b main https://github.com/applied-material-modeling/neml2.git
cd neml2
pip install -e ".[dev]" -v
This drives scikit-build-core to build the bundled C++ runtime and lays down an editable Python install plus everything the dev workflow needs (pytest, pre-commit, sphinx, …).
CMake presets¶
For pure C++ development (the wheel build is invoked separately by
pip), CMakePresets.json defines two presets, each serving a
different purpose:
dev— the day-to-day build presetDebug build of
libneml2_aoti(the compiled-model runtime). The pybind extension modules are not included (NEML2_WHEEL=OFF); usepip install -e ".[dev]"to rebuild those. This is the preset for iterating on C++ sources:cmake --preset dev -S . cmake --build --preset dev
cc— a configure-only preset for toolingConfigures with
CMAKE_EXPORT_COMPILE_COMMANDS=ONandNEML2_WHEEL=ONso the resultingcompile_commands.jsoncovers both the C++ runtime sources and the pybind extension.cppfiles. Acompile_commands.jsonsymlink is created in the repo root for clangd / clang-tidy / other static-analysis tools to pick up. This preset is configure-only; there is no corresponding build step.cmake --preset cc -S .
One-off CMake variable overrides¶
The presets cover the vast majority of cases. For a single-shot
override (for example, switching the build type or pointing at a
custom LibTorch), append -D<NAME>=<VALUE> to the configure line in
the usual way:
cmake --preset dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -S .
Custom LibTorch¶
If you want to build NEML2 against a libtorch other than the one shipped
by the active Python environment’s torch package, set torch_ROOT
before configuring:
cmake --preset dev -Dtorch_ROOT=/path/to/libtorch -S .
Equivalent environment variables and the active Python’s torch
site-packages are also consulted; see the bundled Findtorch.cmake
module for the full discovery procedure.
Running the test suite¶
See Testing in the contributing guide.