Workflow¶
How the project is built, tested and changed.
Setting up a clone¶
You need a Rust toolchain through rustup, and
uv. The exact Rust version is pinned in
rust-toolchain.toml, and rustup installs it on first use.
scripts/setup-git.sh
uv sync
The first command sets the commit identity and activates the commit hook
(decision D12). The second creates .venv, installs the development tools and
builds the extension module.
Coverage needs one more tool:
cargo install cargo-llvm-cov --locked
Everyday commands¶
Purpose |
Command |
|---|---|
The tests of both languages, without instrumentation |
|
The tests with a word in their name |
|
Rust tests |
|
Python tests |
|
Format |
|
Lint |
|
Coverage, with the 95 % floor |
|
The examples of the documentation |
|
Documentation |
|
Hygiene, lints and all tests |
|
Everything CI runs |
|
Benchmarks, against the last baseline |
|
Timings of new benchmark cases, added to the baseline |
|
uv run rebuilds the extension module when Rust sources have changed.
How coverage is measured¶
scripts/coverage.sh builds the workspace with coverage instrumentation, runs
the Rust tests, then runs the Python tests against the instrumented extension
module. The Rust figure therefore includes lines that only Python tests reach,
which is how the binding crate is covered. Each language must reach 95 % on
its own (decision D6).
The examples of the documentation (test_docs.py) are not among the tests
that are measured: under the counters they took nearly half the time of
all tests of Python. scripts/examples.sh runs them with the package that
users get (decision D80.1). So a line of the core must not be reached by a
page alone: it needs a test of its own.
Instrumented artifacts are kept in target/coverage, apart from normal
builds.
Instrumented code counts every region it runs through, in counters that
all threads of a process share. Threads that run the same code fight over
them: on four cores the instrumented tests took 24 times as long as the
plain ones. So under instrumentation every computation uses one thread
(RAYON_NUM_THREADS=1), and the tests of both languages are spread over
processes in place of threads (decision D31.2).
Which check when¶
Run the smallest check that can find the mistake you may just have made. The whole suite is not the way to find out whether a change works: the tests of the code that changed are.
Check |
Takes |
When |
|---|---|---|
|
seconds |
While writing code, as often as you like: the tests of what you are changing. This is the everyday check |
|
1 to 3 minutes |
When a package is finished: once for each package of a pull request. Not after every change, and not before every push |
|
8 minutes |
Once for a pull request, before it is marked as ready. Again after merging |
A push to a draft needs no check. It is a copy of work in progress, and the commit hook has looked at its messages already.
Choose the word by what you touched: the name of the test module
(polar, bounded, helmholtz), of the method, or of the Python test
file. A change to a file that many methods share (expr.rs, grid.rs,
fft.rs, the planner) is the exception: there the fast check is the
right one, because anything may break.
The fast check runs every test of both languages and the lints, and enforces the coverage floor on Python. It leaves out what is slow: the instrumented build that measures coverage of Rust, and the documentation.
A test costs its time in every check, and three times as much under the
counters of the coverage. So a test asks for the smallest problem that
shows what it asserts, and it runs the planner only where it asserts
what the planner chooses: on a shape the planner solves on mesh after
mesh. A test on a shape that names its method takes its plan from
shaped_tests::framed, which has the grid and the times of the
planner’s plan without the planning.
The times are for four cores. The fast check takes the longer time after
Rust sources changed, because both builds are made again.
CI runs the full check, but not on a draft of a pull request: a draft is
work in progress. It runs when the pull request is marked as ready, and
on every push after that. It runs as two jobs side by side: the lints
and the tests with their coverage in one, the examples of the
documentation and the documentation in the other. Each builds the package for itself, the first with the counters
of the coverage and the second as users get it. A third job, “Lint,
test, coverage, docs”, passes when both have passed: it is the check to
look at, and the one that a rule for main asks for.
After the full check or CI found something, fix it, run the stage that
failed (scripts/lint.sh, scripts/coverage.sh, scripts/examples.sh or
scripts/docs.sh),
and push. CI confirms the rest.
Milestones, branches and pull requests¶
A milestone is one branch and one pull request. It delivers one package
of the backlog, several of them, or a part of a large one.
The owner decided that a pull request may be large, and may bundle small
and medium packages (decision D31.3): each pull request costs a full
check, a run of CI, a review and a merge, and each merge makes the others
merge main again.
Claim the package and a milestone number, as described under Several sessions at once. The branch is named
m<N>-<slug>, for examplem1-first-solve. The name must not contain “claude” (decision D12).Commit in small steps. Each commit message says what changed and why.
Test what you change while you work, run
scripts/check.sh --fastwhen a package is finished, andscripts/check.shonce, before the pull request is marked as ready: see Which check when.When the pull request is ready and its checks in CI are green, the session that opened it merges it, with a merge commit. It does not wait for the owner (decision D32.5).
Never push to
main.
A milestone is done when:
its tests pass, and coverage is at or above 95 % in both languages;
numerical results are verified against exact or manufactured solutions, with the convergence order asserted;
the documentation describes what was built, with each kind of page in its place (decision D68.2): a topic page explains it, the reference lists it, on the page of what is solved on its domain and where it has them among the methods of a plan and the diagnostics, and an example in the gallery shows it. A task that became possible gets a recipe. See The pages for users;
every other page that names its subject still holds. A milestone that widens what a kind of equation or of domain takes makes sentences elsewhere wrong: search the topics, the reference and the method pages for the domains and methods concerned, and for “only”, “yet”, “so far” and “cannot” (decision D37.1);
its record in milestones says what was built, what was decided and what was left for later;
the backlog no longer holds the package, and holds what the milestone left for later as packages or as ideas;
the known limits and the pages of what is solved where describe the project as it now is, and the roadmap too, where a campaign changed.
The pages for users¶
The website keeps four kinds of pages apart, as the documentation of Django does (decision D68.1). A page is of one kind, and a milestone puts each thing it has to say on the page of the kind it is.
Kind |
Folder |
What a page is |
|---|---|---|
Tutorial |
|
Takes a newcomer by the hand, part after part |
Topic |
|
Explains one concept, with short examples |
How-to |
|
A recipe for one task: steps and one complete example |
Reference |
|
Complete and dry: the API, what is solved where, the plan, the diagnostics, and the known limits |
Gallery |
|
One example on a page, with its picture |
Methods |
|
How a method works, how accurate it is, what it costs |
Three rules keep it so:
One kind, and a size. A page of the tutorial, the topics, the recipes or the gallery has at most 250 lines, which a test checks. A subject that outgrows its page gets a page of its own, and a line on the index page of its folder and on the start page.
One place. What is solved where, and what does not work, stands in the reference and nowhere else in full. Other pages link there.
A picture. What a milestone adds for users is shown by an example in the gallery: a page of its own in the form of the others, named on
docs/gallery/index.mdunder its theme.
The examples of every page run in the tests (test_docs.py), and a
block of text right below an example must be what the example prints.
The record of a milestone¶
Each milestone writes one file, docs/dev/milestones/m<N>-<slug>.md, named
like its branch. It holds:
which packages it delivered, and what was built;
the decisions taken, numbered
D<N>.1,D<N>.2and so on, each with who took it (owner or developer) and why;what was found out, and what was left for later.
Code and pages refer to a decision by that number: “decision D31.2”. The numbers of one milestone cannot collide with those of another, which is why they carry the milestone’s number (decision D30.3).
Milestones 1 to 29 are recorded in history.md, and decisions D1 to D79 in decisions.md. Both files are closed: nothing is appended to them. A new dependency still gets its row in the table at the end of decisions.md.
Several sessions at once¶
Several sessions can work on the project at the same time, each on a package of its own. They share nothing but the repository on GitHub, so that is where they coordinate.
Claiming a package¶
The list of open pull requests says who is working on what. A session claims its package before it does anything else:
Fetch, and read the open pull requests. A package that one of them names is taken. So is every package in the same lane, unless the backlog says that the two touch different files. A session that bundles packages takes them from one lane, and names all of them.
Take the next milestone number: one more than the highest among the branches
m<N>-…on the remote, the files indocs/dev/milestonesand the open pull requests.Start the branch
m<N>-<slug>fromorigin/main. Its first commit creates the milestone’s record with a title and the package. Push it, and open the pull request at once, as a draft, with the titleMilestone <N> (<packages>): <what>. This is the one push that needs no check before it: it holds one page.Read the open pull requests once more. If another one claims the same package, or the same number, the pull request that GitHub numbered lower keeps it. The other session closes its pull request and starts again at step 1: with the next number, or with another package.
GitHub numbers pull requests in the order in which they arrive, and each session looks after it has opened its own. So of two sessions that claim the same thing at the same moment, exactly one yields.
A session that is given no package asks the owner. It does not pick one.
To add a package to a pull request that is in work, read the open pull requests as in step 1, and then add it to the title.
While working¶
The pull request stays a draft while the work goes on. Pushes to a draft cost nothing: CI does not check them.
Stay in the lane. A change that the package needs in another lane is kept small, and the pull request names it.
A package that needs another one which is still in work waits, or starts from that branch and names it as the base of its pull request.
Work that is given up: say why in the description of the pull request, and close it. The branch stays.
Files that everybody changes¶
Most collisions are not in the code of a method. They are in the few files that every milestone touches. For each there is a rule that keeps two milestones apart:
File |
Rule |
|---|---|
The record of what was built and decided |
A file per milestone, see above. |
|
Change the lines of your own package only. Do not reorder or reflow what is around them |
|
Only when a campaign begins, ends or changes |
|
Add the timings of new cases with |
|
A function per group of cases. Do not touch the groups of others |
The list of cases in |
They are sorted. Insert in order, not at the end |
|
Add, do not rearrange. Tidying a shared file is a package of its own (P1) |
|
After a collision, take the file of |
Counts in prose and in tests (“32 cases”) |
Do not write them. Where one is needed, compute it |
Before a pull request is merged¶
Merge
origin/maininto the branch. Do not rebase, and do not force-push: the pull request keeps its history.Run
scripts/check.sh, the full check, on the result, and push.Mark the pull request as ready, and write its description: what was built, how it was verified, what the owner should look at. CI checks it from now on.
Watch the checks of CI until they are done: this is always part of the work. When every check is green, merge the pull request, with a merge commit. The owner has said that this needs no further word (decision D32.5). A check that fails is fixed, and never merged around.
Pull requests are merged one at a time. After each merge, the next one
merges main again and waits for its checks. A session merges its own
pull request only.
Settings for the owner¶
Two settings of the repository make the rules above hold by themselves.
Only the owner can make them, under Settings, Branches, as a rule for
main:
Require a pull request before merging.
Require status checks to pass, and require branches to be up to date: the checks “Lint, test, coverage, docs” and “No forbidden names”.
To start a session on a package, name it: “take package A10”. The session reads the backlog and does the rest.
Commit rules¶
No commit may mention Claude or Anthropic: not in the message, a trailer, the
author or the committer. The commit-msg hook rejects such commits locally,
and CI rejects them on the pull request. Both call
scripts/commit-hygiene.sh.
Changes that are about speed¶
Measure before and after, with the suite of benchmarks. A change that claims to be faster says by how much, for which cases. When a milestone changes timings on purpose, it records a new baseline:
cargo bench -p pdemagic --bench suite -- --save benches/baseline.json
A new method gets a case in scripts/benchmark-cases.py, and its timing
is added to the baseline with --add, which leaves the timings of all
other cases as they are.
Adding a dependency¶
General numerical kernels (FFT, linear algebra) come from established, high-performance libraries. PDE-specific code is written here (decision D4).
The project is closed, with all rights reserved (decision D39.1). Every build takes permissively licensed dependencies only (decision D5): a library under a copyleft license could not be passed on with it, also not as an optional backend.
Add a row to the dependency table in decisions.md.
Continuous integration¶
.github/workflows/ci.yml runs the same steps as scripts/check.sh, on Linux.
A release¶
A version is published as binary packages on PyPI, one for each platform,
with no package of the source (decision D41.1). The workflow
.github/workflows/release.yml builds them, installs each into a fresh
environment, runs the Python tests against it, and publishes them. It
builds and tests on every pull request that changes the workflow or the
metadata of the package, and it publishes when a tag v<version> is
pushed.
To cut a version:
In a milestone of its own, set
versionin theCargo.tomlat the root, runcargo update -w, and write the section of the version on the page of changes. A version that changes the interface gets a new middle number, and its section says under “Changed” what to write instead (decision D41.4). The terms of use are the fileLICENSE: it names the versions it holds for, and only the owner changes it (decision D41.2).Run
uv run python scripts/third-party-licenses.py. It writesTHIRD-PARTY-LICENSES.txt, the licenses of every library that is built into the package.scripts/lint.shfails when the file is not current.Merge the milestone, and wait until the documentation website shows the new state: the page of the package on PyPI takes the figures of the README from there (decision D41.5).
With the owner’s word for this version, the merge commit on
mainis tagged asv<version>. A session in the cloud cannot push a tag: the owner creates it, under Releases, Draft a new release, with the targetmain. The workflow refuses a tag that does not match the version of the packages.The publication waits for the owner’s approval in the environment
pypi, if the owner has set a reviewer there. A version on PyPI can be withdrawn but never replaced: what is wrong in 0.1.0 is repaired in 0.1.1.
Two settings belong to a release, and only the owner can make them:
On PyPI, a trusted publisher for the project
pdemagic: ownermaroba, repositorypdemagic, workflowrelease.yml, environmentpypi. No password and no token is stored anywhere. If the upload is refused withinvalid-publisher, this entry does not match: it is found in the settings of the project on PyPI, under Publishing. The packages need not be built again: “Re-run failed jobs” repeats the upload alone.In the repository, under Settings, Environments, the environment
pypi. With the owner as its required reviewer, nothing is published without one more approval. Without a reviewer the tag alone publishes: the first version went out that way, a minute after the upload was started again.
The package holds the core as a compiled library, and the Python frontend as it is written: Python files that anyone who installs it can read.
The documentation website¶
.github/workflows/docs.yml builds the documentation and publishes it with
GitHub Pages every time main changes (decision D43). The address is
https://maroba.github.io/pdemagic/.
The figures of the website are not files in the repository. A page that
calls .plot( or .animate( has its Python examples run when the
documentation is built, and what they draw is shown below them, once for the
light and once for the dark version of the site (decision D51). The
extension that does this is docs/_ext/examples.py. To add a figure, call
plot in an example. The build therefore needs the package, and fails if an
example fails.
The extension runs the pages before Sphinx reads them, each in a process of its own and as many at once as there are cores. A page solves each of its problems once: in the run for the second theme, a solve with the same problem, plan and data is answered from memory. So a page must not depend on another page, which the tests ask of it already.
How the website is laid out, and why, is decision D68.1. It replaces the layout of decision D61. The kinds of pages and their rules are under The pages for users:
Where |
What |
|---|---|
|
The start page, by subject: under each, the links to the pages of every kind. |
|
The tutorial, in parts. |
|
One concept on a page. |
|
One recipe on a page. |
|
The reference: the Python API from the docstrings, what is solved where, the methods of a plan, the diagnostics. |
|
One example on a page. |
|
One page per method, behind an overview. |
|
What changed, version by version. |
|
These pages, behind |
|
The addresses of the first website, each forwarding to its successor. |
Each page of the tutorial, the topics, the recipes and the gallery
stands on its own: its examples run from top to bottom without another
page. python/tests/test_docs.py runs them, and picks up a new page by
itself.
A page of the gallery starts with its title, one sentence, and the
example. On gallery/index.md a block :::{gallery} with the names of
pages becomes a grid of tiles, each with the first picture of its page,
its title and that sentence.
The figures of the README are files, in docs/_static/readme, because
GitHub shows a README as it is in the repository. After a change that
should show in them, draw them again:
uv run python scripts/readme-figures.py
Publishing needs one setting that only the owner can make, once: in the repository settings under Pages, set the source to GitHub Actions. It is made: the site is published after every merge. Without it the build job passes and the publish job fails.
The workflow can also be started by hand from the Actions tab.