Contributing
This guide explains how to set up the tasks of the project, add a system to the catalog with its gallery example, and send the work as a pull request. Contributions are welcome.
Tasks
This section lists the commands of the development tasks. The project runs them with
nox, and the file noxfile.py at the root of the project defines each session.
PDM names the common ones as scripts.
Documentation
pdm docs serveorpdm docs: serve the documentation.pdm docs build: build the documentation.
Formatting
pdm formatting allorpdm formatting: format the code and the docstrings.pdm formatting code: format only the code.pdm formatting docstrings: format only the docstrings.
Checks
pdm checks allorpdm checks: run all checks.pdm checks quality: check only the quality of the code, with ruff and the import contracts.pdm checks types: check only the type annotations, with mypy.pdm checks dependencies: check only the dependencies for vulnerabilities and for unused or missing ones.pdm checks security: run only the security checks, with bandit.pdm checks docs: check only the coverage and the format of the docstrings, with interrogate and pydoclint.pdm checks conventions: check only the conventions of the sources, the tests, and the documentation, withopenspec/scripts/check_conventions.py.
Tests
pdm tests: run the whole suite with coverage, including the slow tests, the docstring examples, the README, and the user guide.nox -s tests -- <expression>: run only the tests whose names match the expression.nox -s quick_tests: run a small subset of the fast tests in a few minutes, as CI does on every push.
The tests of a module src/skcomplex/<package>/_<module>.py live in tests/<package>/test_<module>.py, and every test
file mirrors a module this way. pdm checks conventions checks it.
Changelog
pdm changelog: build the changelog.
Release
Before a release, name the runtime dependencies without a release in the last 24 months. Replace each one, or record an
exception in the Project Profile of openspec/constitution.md. The script below prints each such dependency with the
date of its last release.
python - <<'EOF'
import json, re, tomllib, urllib.request
from datetime import UTC, datetime, timedelta
limit = datetime.now(UTC) - timedelta(days=730)
for requirement in tomllib.load(open('pyproject.toml', 'rb'))['project']['dependencies']:
name = re.match(r'[\w.-]+', requirement).group()
with urllib.request.urlopen(f'https://pypi.org/pypi/{name}/json') as response:
releases = json.load(response)['releases'].values()
last = max(datetime.fromisoformat(file['upload_time_iso_8601']) for files in releases for file in files)
if last < limit:
print(name, last.date())
EOF
pdm release: release a new version of the package. It writes the changelog, merges a release branch intomain, and pushes the tag that starts the release pipeline.
Development
This section gives the order of work on a change.
git checkout -b new-branch-namecreates a branch for the change.pdm formattingformats the code and the docstrings.pdm checksruns all checks.pdm testsruns the tests.pdm docs serveshows the documentation, when the change touches it or the dependencies of the project.
Where a component goes
This section decides where a new component belongs. One ordered test, the placement rule, decides where any component
goes, and openspec/scripts/check_conventions.py checks it mechanically. The page Extend the
library
of the user guide gives an example of each step.
- A structural base, such as a
Baseclass,Element,Interaction,System, a space, or a neighbourhood, goes to the core. - A law kind, an operator generated from one function, such as
laplacianorrelax, and numerics the engine handles by type, through a compile pass, a kernel, a solver, a backend lowering, or an analysis, go to the core. They are named by their mathematics and must be cross-domain in principle. The engine keys only on the seven law kinds and never names a class ofskcomplex.systems. - Every other component is a recipe, written with core components, and a law of one field is first written as a
recipe of the seven law kinds and the core operators. Its users place it. Several fields:
skcomplex.systems.general.<concept>. One field with several systems:systems/<field>/common/<family>. One system: that system's module. A field with its own term names it, andgeneraluses neutral names. - A recipe that needs something the core cannot express reveals a missing core primitive, which enters by step 2. Numerics that serve one field alone, such as the Lindblad equation or rewriting, come as a solver or a compiler built on the public engine bases, in the package of that field, and its elements name it.
- The core never imports
skcomplex.systems.
Analyses follow the rule by their users too. An analysis that measures what systems of several fields share goes to
skcomplex.core.analysis, and an analysis of one field goes to systems/<field>/common/<family>.
Module layout
This section gives the order of a Python file. Every file holds the docstring, the licence header, the imports, the
constants block, the type aliases, the other module statements, and then the definitions. The constitution in
openspec/constitution.md states the rules, and openspec/scripts/check_conventions.py checks them. The checks cover the constants
block and the values derived from it, the symbolic functions written as BuiltinFunction subclasses, the class that
owns each helper, the action word that begins the name of every method, such as get or check, and the three kinds
of module functions that stay functions.
Adding a system to the catalog
This section adds a ready-made system to the catalog. A system of the catalog is a subclass of BaseSystem whose name
ends in System. Its __init__ takes the parameters of the model and stores each under its own name, and its hook
_prepare sets system_ to the System of its components. Its body sets these class variables:
field, the field path of a field and a subfield, such as'engineering/processes',topics, the words thatall_systemsfilters by,references, the works the model comes from, each an author and a year,untilanddt, the tuned run settings thatsimulatereads when a call leaves them out.
from typing import Annotated
from sage.all__sagemath_symbolics import oo
from sage.sets.real_set import RealSet
from skcomplex.core.components.elements import Element
from skcomplex.core.components.interactions import Interaction
from skcomplex.core.components.laws import RateLaw
from skcomplex.core.systems import BaseSystem, System
class TankElement(Element):
def __init__(self, label, *, level: Annotated[float, RealSet.closed_open(0, oo)] = 1.0):
super().__init__(label)
self.level = level
class DrainingTankSystem(BaseSystem):
"""A tank that drains at a rate proportional to its level."""
field = 'engineering/processes'
topics = ('ode', 'decay')
references = ('Torricelli 1643',)
until = 5.0
dt = 0.1
def __init__(self, level=2.0, *, k=0.5, label='system', solver='auto', backend='auto'):
super().__init__(label, solver=solver, backend=backend)
self.level = level
self.k = k
def _prepare(self, context=None):
super()._prepare(context)
k = self.k
drain = Interaction('drain', roles={'target': 'tank'}, laws=lambda s: [RateLaw(s.target.level, -k * s.target.level)])
self.system_ = System(self.label, elements=[TankElement('tank', level=self.level)], interactions=[drain])
DrainingTankSystem().get_params()
get_params returns k=0.5, the label, and level=2.0, so set_params, clone, and the experiments of the library
change them by name. all_systems lists a class when its module lives in the package skcomplex.systems and its body
sets field. It reads the sources without importing them, so field, topics, and references must be literal
values. It raises a RegistryError for a class of the package whose name lacks the suffix System or whose field is
computed at run time.
A new system adds these files:
- the module of the class in its subfield package, such as
src/skcomplex/systems/engineering/processes/_tanks.py, - an import of the class in the
__init__.pyof the subfield, with its name in__all__, - the tests of the class in the mirrored path, such as
tests/systems/engineering/processes/test_tanks.py, - an entry in the inventory
docs/overview/inventory.toml, - a gallery example, as the next section describes.
The module holds one system and the components that only it uses. A component that several systems of one field share
goes to the common package of the field, and a component that several fields share goes to
skcomplex.systems.general, as the placement rule says.
tests/systems/test_catalog.py runs every listed class through one generic check. It builds the class with its
default parameters, simulates it for ten frames while a RerunObserver saves the run, requires a logged frame for
every simulated frame, and clones the system. Run pytest tests/systems/test_catalog.py -k DrainingTankSystem to run
the check on the new class.
The inventory entry sits in the table of its field path, and its name is the class name without System in snake
case, so DrainingTankSystem is draining_tank.
[engineering.processes]
draining_tank = { title = "Draining tank", sources = ["Torricelli 1643"], primitives = ["rates"], system = { components = ["element"], bindings = ["members"] }, priority = "example", status = "implemented" }
The title names the system in the gallery, the sources cite the works, and the primitives name the capabilities
of the core it exercises from the table primitives of the inventory. The priority is 'core' when the system
exercises a set of primitives that no earlier entry exercises, and 'example' otherwise. The status is
'implemented' once the class exists. An implemented entry does not write its time, space, laws, or domains, since the
check of the inventory reads them from get_tags() of the class. The documentation build runs that check and fails on
an entry that disagrees with the catalog.
The guide page Share a system follows these steps for one model, with every field of the inventory entry explained.
System gallery
This section explains the gallery of the documentation. Every system of the catalog has one example there. The example runs the system, streams it to Rerun, and adds an analysis figure computed from its own run. A screenshot of its Rerun view becomes the thumbnail of the example.
Where the examples live
- The examples are scripts in the format of
mkdocs-galleryunderdocs/examples/<field>/<subfield>/plot_<system>.py, one per system, named after the inventory name of the system. - The gallery tooling is the package
gallery_toolsindocs. It needs the dependency groupgallery, which holds Pillow and Playwright:pdm install -dG docs -dG gallery. nox -s galleryruns the examples, captures their screenshots, and builds the documentation with them. It takes--backend native, the default, or--backend web,--jobsfor parallel captures, and--sampleto run only three fast systems per field, which is whatnox -s docsand CI build.
How the examples are captured
The tooling runs with docs on the path, as PYTHONPATH=docs python -m gallery_tools <command>.
scaffoldwrites a scaffold for every system without an example, with the title of its inventory entry.coveragereports the systems without an example and the examples without a system, and--strictfails on either.run <system> ...runs the named examples, or all selected ones, and captures their screenshots into the cache. The default selection is the sample of three fast systems per field, and--allselects every example.
The run of every example, the whole script with its analysis, must stay within the budget: at most 300 frames on the timeline of the recording, a recording of at most 20 MB, and at most 60 s. An example over budget fails.
The capture opens the recording with its blueprint in the Rerun viewer at the last frame, crops to the views, and
checks the image for blank views, notifications, and its size. The first view of the blueprint, the primary view,
becomes the thumbnail. Screenshots are cached under docs/generated/gallery/_cache, keyed by the source of the example,
the source of the system, the Rerun version, and the capture settings. Each entry holds thumbnail.png and a
metadata.json with the frames, the size of the recording, and the run time. The cache is not committed, and the
documentation build captures only the stale screenshots.
Adding an example for a new system
This section writes the example of a new system, from the scaffold to the captured screenshot.
- Add the class and its inventory entry, then run
PYTHONPATH=docs python -m gallery_tools scaffoldto write the scaffold. It imports the class from its subfield, setsSYSTEMto the inventory name, and runs the class withsimulateand aRerunObserver. - Read the docstring of the class, its parameters from
get_params(), and its tuned run settings fromget_run_settings(). - Write the docstring of the example: a title, and a caption of the behaviour the system is known for, which the thumbnail must show. Delete the sentence that marks the example as a scaffold.
- Choose the parameters,
until,dt, theintervalof the observer, and arandom_statefor a stochastic system, so that the run stays within the budget.simulateuses the tuned solver of the class unless the call names another. - Choose the primary view. Use
blueprint='default', withprimary='<origin>'to put the most telling view first. A customrrb.Blueprintis fine when no default view shows the behaviour, with a comment on why. A custom time series view must show the whole run, or the view follows the latest frames and cuts the curve off.
import rerun.blueprint as rrb
# The view shows the whole run, not the default window that follows the latest frame.
whole_run = rrb.TimeAxis(
view_range=rrb.TimeRange(start=rrb.TimeRangeBoundary.infinite(), end=rrb.TimeRangeBoundary.infinite()),
)
view = rrb.TimeSeriesView(origin='/<element>/<state>', name='<name>', axis_x=whole_run)
view
- Add one analysis figure computed from the trajectory that
simulatereturns, with labelled axes, a title, and a sentence in the comment above it on the agreement to expect, such as a law, a conserved quantity, or a theoretical curve. Prefer the functions ofskcomplex.core.analysis. - Capture it with
PYTHONPATH=docs python -m gallery_tools run <system>, and open itsthumbnail.pngin the cache. - Run
ruff checkandblack --checkon the example.
The example docs/examples/biology/ecology/plot_lotka_volterra.py shows the finished form.
Reviewing the screenshots
This section explains how a screenshot is accepted. Every screenshot is reviewed against its caption: at the size of
the gallery grid, the thumbnail must show the behaviour the caption states. A screenshot that does not is fixed in the
example, by its run, its primary view, or its caption, never by editing the image. Each review is one row of the list
of its field, with the system, what the thumbnail shows, what the analysis checks, and the budget of the run. The lists
of the first gallery are in openspec/changes/archive/2026-10-21-add-model-gallery/reviews/<field>.md.
Commit message convention
This section gives the format of a commit message. Commit messages follow conventions based on the Angular style.
Structure
<type>(<scope>): <subject>
<body>
<footer>
Example
feat(directive): A new feature of code
A description of the new feature.
It contains **important** information.
Issue #10: https://github.com/namespace/project/issues/10
Related to PR namespace/other-project#15: https://github.com/namespace/other-project/pull/15
Guidelines
- The scope and the body are optional.
- The subject and the body must be valid Markdown.
- The body ends with trailers, such as references to issues and pull requests, or co-authors.
- The subject starts with an uppercase letter where that makes sense.
- The subject has no full stop at the end and no punctuation.
- The type is one of these:
feat: a new feature.fix: a bug fix.docs: a change of the documentation.style: a change of the style or the format of the code.refactor: a change that is neither a feature nor a bug fix.tests: tests added or corrected.chore: maintenance of the code.
Pull request guidelines
This section explains how to send the work. Link every related issue in the message of the pull request. Fixup commits keep the history readable during review.
git commit --fixup=SHA
Once all the changes are approved, squash the commits.
git rebase -i --autosquash main
Then force the push.
git push -f