============ Contributing ============ This page is the single source for the contribution workflow of GPRidge: how to set up a checkout, build and test, write a commit and a news fragment, add a command-line flag or a configuration key, change the documentation, and what the continuous integration (CI) checks. The published documentation shows the same page under Development at `https://gpridge.rgoswami.me/development/contributing.html `_, next to the guides on the documentation build, versions and releases, correctness checks and performance. By taking part in this project you agree to follow the `code of conduct `_. The `development quick reference `_ lists build commands, source paths and compatibility checks. Set up a checkout ----------------- Open pull requests against ``develop``, the integration branch. The ``main`` branch holds released source. .. code:: bash git clone https://github.com/TheochemUI/gpridge.git cd gpridge Dependencies come from `pixi `_ (version 0.81.0 or newer; the manifest solves for linux-64 only). Three tools are not in the default environment: - A C++20 compiler. The default environment has meson, CMake and ninja but no compiler. The ``python`` environment brings GCC 14. - Rust 1.88 or newer with ``cargo`` on the ``PATH``. The ``anneal`` and ``rgmin`` Rust subprojects are enabled by default (``use_anneal`` and ``use_rgmin`` in ``meson_options.txt``), and both declare ``rust-version = "1.88"``. Only the ``scalapack`` environment installs Rust; elsewhere install it yourself. - ``cbindgen`` 0.29.4, which generates the C headers of those subprojects. ``scripts/install_cbindgen_pixi.sh`` installs it into the active pixi environment with ``cargo install``. The ``install-cbindgen`` pixi task of the ``python`` and ``scalapack`` environments runs the script, and ``pixi run -e python build`` runs that task first. For a meson build in the default environment, run ``bash scripts/install_cbindgen_pixi.sh`` once from inside ``pixi shell``. The Prerequisites section of ``docs/orgmode/getting-started/installation.org`` lists the full requirements of the library and the Python package. Pixi environments ----------------- Each environment adds one concern to the default one. Run a task with ``pixi run -e NAME TASK`` and open a shell with ``pixi shell -e NAME``. .. table:: +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | Environment | Purpose | +=======================+=========================================================================================================================+ | ``default`` | C++ build and tests with meson: library dependencies, meson, CMake, ninja, gtest, Catch2, gcovr. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``python`` | Python bindings (nanobind, meson-python), pytest, GCC 14, Nim. Tasks ``build``, ``test``, ``test-coverage``, ``bench``. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``docs`` | Documentation: Emacs, Doxygen, doxyrest, Sphinx, lychee, towncrier, Cog. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``analysis`` | Python 3.11 with ASE, h5py and matplotlib, for plotting and analysing run output. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``scalapack`` | MPI and ScaLAPACK builds, Rust and libclang, GCC 14, the HPC benchmark and profiling tasks. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``cutlass`` | CUDA compiler and CUTLASS headers, for the optional CUTLASS GEMM path. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``scalapack-cutlass`` | ``scalapack`` and ``cutlass`` together. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``gpu-scalapack`` | ``scalapack`` with the CUDA 12.8 toolkit and the cu128 PyTorch wheels. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``bench`` | asv benchmark tasks on top of ``scalapack``. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``symbolic`` | SymPy derivations (tasks ``derive-*``). | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``proofs`` | Coq and Lean proofs under ``proofs/``. | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``petmad-assets`` | Fetches the PET-MAD model and configuration (tasks ``prepare-petmad-*``). | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ | ``jcim`` | Builds the figures of the JCIM manuscript (``paper/jcim/build.sh``). | +-----------------------+-------------------------------------------------------------------------------------------------------------------------+ Run ``pixi task list -e NAME`` for the tasks of an environment. Build and test -------------- C++ library and drivers ~~~~~~~~~~~~~~~~~~~~~~~ .. code:: bash pixi shell meson setup builddir -Dwith_tests=true meson compile -C builddir meson test -C builddir ``-Dwith_tests=true`` builds the test targets and the ``gprd`` and ``gprn`` drivers they need. The build type defaults to release. The default build compiles the Rust subprojects, so install ``cbindgen`` first (see above). Meson groups the tests into suites. ``meson test -C builddir --list`` prints every test with its suite, and ``--suite NAME`` selects one. .. table:: +---------------------+--------------------------------------------------------------------------+ | Suite | Content | +=====================+==========================================================================+ | ``gpridge`` | The default suite: unit and integration tests of the library. | +---------------------+--------------------------------------------------------------------------+ | ``gpridge:quantum`` | The quantum-path tests. | +---------------------+--------------------------------------------------------------------------+ | ``gpridge:gp`` | Five checks of pair-local directional curvature and GP iteration limits. | +---------------------+--------------------------------------------------------------------------+ | ``gpridge:docs`` | The documentation examples and their lint, see below. | +---------------------+--------------------------------------------------------------------------+ | ``gpridge:install`` | Checks of an installed library. | +---------------------+--------------------------------------------------------------------------+ | ``rgpot``, ``ira`` | Tests of the vendored subprojects. | +---------------------+--------------------------------------------------------------------------+ Run a single test by name, for example ``meson test -C builddir test_kernel_properties --print-errorlogs``. Python bindings ~~~~~~~~~~~~~~~ .. code:: bash pixi run -e python build pixi run -e python test ``build`` runs ``pip install --no-build-isolation -e .`` and depends on ``install-cbindgen``. ``test`` runs ``pytest python/tests/ tests/integration/``. ``test-coverage`` runs the same tests with ``pytest-cov`` and fails below 100 percent line coverage of ``python/gpridge``. Optional features ~~~~~~~~~~~~~~~~~ Optional dependencies are meson options, listed in ``meson_options.txt``: for example ``-Duse_capnp=true`` for Cap'n Proto configuration files, ``-Duse_hdf5=false`` to drop HDF5, and ``-Dlinalg_backend=scalapack`` for the distributed backend. The CUTLASS path has its own pixi tasks, ``test-cutlass-gemm`` and ``test-cutlass-rff``, in the ``cutlass`` environment. Commit messages --------------- Commit subjects follow `Conventional Commits `_: ``type(scope): summary``, with the scope optional, in the imperative mood and without a trailing period. The types in the history are ``fix``, ``docs``, ``test``, ``chore``, ``feat``, ``style``, ``perf``, ``build`` and ``tools``. Examples from the history: :: fix(env): declare the locked Linux virtual packages perf(gp): use pair tiles for open-boundary directional curvature docs(contributing): bring CONTRIBUTING.org in line with the markdown Keep one logical change per commit. Close an issue with ``Fixes #NUMBER`` in the pull request description. News fragments -------------- The release notes in ``CHANGELOG.md`` are assembled by `towncrier `_ from files in ``docs/newsfragments/``. A change that a user or developer would notice adds one fragment. The file name is ``TOPIC.TYPE.md``, with a leading ``+`` when no issue number applies, as in ``+irc-vibrational-minimum.changed.md``; with an issue number, the name is ``NUMBER.TYPE.md``. ``TYPE`` is one of the directories declared in ``towncrier.toml``: .. table:: +----------------+------------------------------+ | Type | Section in the release notes | +================+==============================+ | ``security`` | Security | +----------------+------------------------------+ | ``removed`` | Removed | +----------------+------------------------------+ | ``deprecated`` | Deprecated | +----------------+------------------------------+ | ``added`` | Added | +----------------+------------------------------+ | ``dev`` | Developer | +----------------+------------------------------+ | ``changed`` | Changed | +----------------+------------------------------+ | ``fixed`` | Fixed | +----------------+------------------------------+ The file holds a short paragraph in plain Markdown. Preview the notes without writing any file: .. code:: bash pixi run -e docs towncrier build --draft Towncrier drops a file whose name does not end in ``.TYPE.md`` for a declared type, without a warning. The pre-commit hook ``newsfragments`` runs ``scripts/check_newsfragments.py``, which rejects such files and fragments outside ``docs/newsfragments/``. Formatting and pre-commit ------------------------- Run the hooks before opening a pull request. The configuration is ``.pre-commit-config.yaml``: .. code:: bash uvx prek -a uvx prek install The first command checks every file. The second installs the git hook. The standard ``pre-commit run --all-files`` reads the same configuration. The hooks are: - Trailing whitespace and end-of-file fixes, a YAML check and a check for large files. - ``clang-format`` v16.0.6 with the style in ``.clang-format``, on C and C++ files outside ``subprojects/`` and ``thirdparty/``. - ``ruff`` v0.9.7 with its default rules, and ``ruff-format``, on Python files. - ``meson format -i`` on ``meson.build`` files outside ``subprojects/``. - ``scripts/check_newsfragments.py``, described above. CI also runs ``tools/check_copyright.py``. Every file that is not vendored carries the notice ``Copyright (c) gpridge developers``, and the check fails on any other copyright line. Conventions for the code: - C++20. Public declarations carry a Doxygen comment (``///`` or ``/** */``) that starts with ``@brief``, because the C++ API reference is generated from these comments. - A new option is a command-line flag backed by a field of the Cap'n Proto schema, as described below, and not a new environment variable. - Python follows the ruff defaults. Add a command-line flag ----------------------- ``gprn`` and ``gprd`` are separate drivers with separate parsers. A ``gprn`` flag ~~~~~~~~~~~~~~~ All of the steps are in ``main_neb.cpp``: 1. Add a member with its default to the ``CliArgs`` struct. 2. Add a row to the ``kFlagDocs`` table: ``{"Group", "--flag ", "Meaning. Default X."}``. ``gprn --help`` prints this table, and the CLI reference page is generated from it. State the default in the text; the generator checks it against the ``CliArgs`` initializer. 3. Register the flag in ``parseCli``: ``boolOpt``, ``intOpt``, ``longOpt``, ``doubleOpt``, ``strOpt`` or ``cstrOpt`` for a plain value, or ``parser.add(Option("--flag").argName("ARG").handler(...))`` when the value needs parsing. 4. Copy the value into the configuration object where ``main_neb.cpp`` builds ``GPNEBConfig``, for example ``config.rff_features = cli.rff_features;``. 5. Add a ``add("name", ...)`` line to ``cliArgLines``. It feeds ``gprn --dump-cli-args`` and the parameters logged to MLflow. The CLI tests in ``tests/gpr/GprnCliTest.cpp`` use the dump. 6. If the option also has a TOML key, copy it from the configuration message in ``applyConfigFileToCliArgs``, see the next section. Then regenerate the reference and run the check: .. code:: bash python scripts/gen_cli_reference.py --write python scripts/gen_cli_reference.py --check The generator reads ``kFlagDocs``, the registrations and the ``CliArgs`` initializers. It fails when a flag has no row, when a row has no flag, or when a default in the text differs from the initializer. Hand-written text for a flag goes in ``docs/cli_overrides.toml``, never in the generated pages. A ``gprd`` flag ~~~~~~~~~~~~~~~ Register the flag with ``parser.add(Option("--flag")...)`` in ``main.cpp``, with ``.argName(...)``, a ``.help(...)`` text that says more than the flag name, and a ``.handler(...)`` that writes a member of the ``CliArgs`` struct of ``main.cpp``. Options shared by both drivers, such as ``--potential``, live in ``gpr/cli/PotentialOptions.h``. Run the same generator and check. Add a TOML configuration key ---------------------------- ``gprn --config run.toml`` reads TOML and also accepts a binary Cap'n Proto message. Both end in the schema ``schema/params.capnp``, and the code that reads them is built only with ``-Duse_capnp=true``. A new key touches these files: 1. ``schema/params.capnp``: add a field to the sub-struct that owns it. Give it the next free ordinal of that struct and a default that reproduces the behaviour without the field. Never renumber, retype or remove a field. Raise ``currentSchemaVersion`` by one. Name the matching flag in the field's comment. 2. ``schema/params.capnp.ordinals``: record the field. Run ``python scripts/check_capnp_evolution.py --write schema/params.capnp schema/params.capnp.ordinals`` and review the added line. The meson test ``test_capnp_evolution_params`` compares the two files. 3. ``managers/io/TomlConfigLoader.cpp``: add the key to the allowed-key list of its table (``rejectUnknownKeys``, which makes an unknown key an error) and read it with ``setIfPresent(table, "key", setter)``. 4. ``managers/io/CapnProtoNebLoader.cpp``: copy the field into ``GPNEBConfig``. 5. ``main_neb.cpp``: copy the value in ``applyConfigFileToCliArgs``. The file fills the ``CliArgs`` baseline and the parser overwrites only the fields whose flags are on the command line, so a flag wins over the file. Then regenerate the reference page and run the check: .. code:: bash python scripts/gen_config_reference.py python scripts/gen_config_reference.py --check The generator takes the key list from the ``setIfPresent`` calls, resolves each field in the schema and the flag it mirrors, and takes the default and the meaning from the CLI reference. A key without a flag needs an entry in the ``NO_FLAG`` table of the script. The design page ``docs/orgmode/development/design/params_capnp.org`` explains the schema. Documentation ------------- The sources are org files under ``docs/orgmode/``. The page ``docs/orgmode/development/docs.org`` describes the build in full. The steps for a new or changed page: 1. Pick the page type, one of tutorial, how-to, explanation or reference, and put the file in ``tutorials/``, ``howto/``, ``explanation/`` or ``reference/``. Theory and design pages that are not user guides live in ``explanation/theory/`` and ``development/design/``. 2. Start the file with ``#+TITLE:`` and ``#+OPTIONS: toc:nil todo:nil num:nil author:nil``. Write math in ``\( \)`` and link other pages with ``[[file:../howto/gpneb.org][text]]``. 3. Add the page to the toctree in ``docs/orgmode/index.org``. 4. Mark every code block. A ``python``, ``bash``, ``sh``, ``c``, ``cpp`` or ``fortran`` block runs in CI against the build. Use ``#+begin_src bash :eval no :why REASON`` for a block that must not run, and put output in a ``#+begin_example`` block. Put ``#+DOC_OUTPUT:`` directly before that block to have the runner check it against the output of the block, and write a value that varies between machines as ````, ```` or another placeholder. The docstring of ``scripts/run_doc_examples.py`` lists the header arguments and the placeholders. 5. Run the example runner, the lint and the export: .. code:: bash python3 scripts/run_doc_examples.py --lint docs/orgmode/howto/PAGE.org pixi run -e python python scripts/run_doc_examples.py docs/orgmode/howto/PAGE.org -v --build-dir builddir pixi run -e docs mkrst After a change to a flag, a key or a Fortran symbol, regenerate the reference instead of editing it by hand: ``scripts/gen_cli_reference.py``, ``scripts/gen_config_reference.py`` or ``scripts/gen_fortran_reference.py``. ``pixi run -e docs check-docs-reference`` runs the reference checks and verifies that every flag in a documented ``gprn`` or ``gprd`` command exists. Files that exist both as org and markdown, such as this one, have the org file as the source. Regenerate the markdown with ``scripts/org_to_md.sh CONTRIBUTING.org`` and never edit it by hand. What CI checks -------------- The workflows are in ``.github/workflows/``. Each runs on pushes and pull requests unless the table says otherwise. .. table:: +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Workflow | Checks | +===========================+==========================================================================================================================================================================================================================================================================================================================================================+ | ``c-cpp.yml`` | Release build and ``meson test`` with and without Cap'n Proto; a debug build with coverage that fails below 66.5 percent line coverage; the Python build and ``test-coverage``. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``pre-commit.yml`` | The pre-commit hooks, ``tools/check_copyright.py``, and an audit of files larger than 1 MB. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``docbuilder.yml`` | The reference pages against the sources, the flags of every documented ``gprn`` and ``gprd`` command, the documentation code blocks (lint, then every block run against a build), the Sphinx HTML build with warnings as errors, a lychee link check, and deployment of the site from ``main`` when the repository variable ``DOCS_DEPLOY`` is ``true``. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``version-sot.yml`` | That every copy of the version matches ``meson.build`` and that the news fragments render. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``correctness.yml`` | The kernel and parser tests under AddressSanitizer and UndefinedBehaviorSanitizer, and a short fuzzing run of the TOML and binary parsers. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``wheels.yml`` | The source distribution and the wheels, an install of each in a clean environment, and the PyPI upload for stable tags. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``native-registries.yml`` | The pkg-config and CMake package, the Fortran fpm package, the Rust ``gpridge-sys`` crate, the R and Julia packages, and the conda recipe. Nothing is uploaded. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``formal.yml`` | The Lean and Rocq developments, and that no proof is admitted or left unfinished. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``lammps-oracle.yml`` | The LAMMPS pair style through ``gprn`` and ``gprd``. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``ci_benchmark.yml`` | Pull requests into ``main``: asv benchmarks of the head against ``main``, reported by ``ci_bench_commenter.yml``. | +---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ To reproduce a CI failure, run the command that the failing step prints from the repository root, in the pixi environment the workflow selects. Benchmarks and performance changes ---------------------------------- A change that is meant to make code faster needs a measurement before and after. The pixi task ``pixi run -e python bench`` runs ``scripts/bench_compare.nim``. It builds the base branch (``main`` by default) and the current ``HEAD`` in separate worktrees, runs the asv benchmarks of ``benchmarks/`` on both, and compares them with ``asv-spyglass``. Pass another base branch after ``nim r scripts/bench_compare.nim``. Add a benchmark as a class in ``benchmarks/`` that follows the asv conventions. The page ``docs/orgmode/development/developer/performance.org`` lists the hot paths and the coding patterns that matter in them. Submit the change ----------------- Push the branch to your fork and `open a pull request `_. A maintainer reviews it and may ask for changes. Before opening it: - The hooks pass (``uvx prek -a``). - ``meson test -C builddir`` passes, and ``pixi run -e python test`` passes when the change touches the Python package. - A news fragment is present when the change is user-visible. - Generated reference pages are regenerated, and every new documentation page is in the toctree.