Development
Guide for contributing to Thor.
Setup
Prerequisites
- All installation requirements
- uv for Python dependencies
Clone and Build
git clone https://github.com/cbyrohl/thor.git
cd thor
./scripts/init-submodules.sh base
# Install dev dependencies
uv sync --group=ci-tests --group=docs
# Debug build
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER=acpp
cmake --build build
Memory Usage
Compilation can require large amounts of memory. If you run out of memory during the build, reduce the number of concurrent builders by adding -j1 to the build command:
Adding configuration settings
Configuration has three stages: decode input, validate requested values, and
prepare runtime state. Runtime code owns ordinary C++ values and does not read
YAML. Native startup creates an immutable Validated<RunConfig> containing
startup, dataset, live-service and selected-driver requests. Python dictionaries
enter through ConfigValue; YAML files enter through ConfigYaml.
Choose the config group by the component that consumes the setting:
| Settings | Value header |
|---|---|
| Resonant line, phase, isotopes, interactor and density fallback | src/mcrt/LineConfig.h |
Field mappings (populate) and temperature floor |
src/FieldPreparationConfig.h |
| Output paths, overwrite/restart policy, photon streams and field lists | src/mcrt/OutputConfig.h |
| Observers, peel merging and peeling behavior | src/mcrt/PeelingConfig.h |
| Photon limits, propagation, acceleration, survival, termination and transport shortcuts | src/mcrt/TransportConfig.h |
| Allocation budgets | src/mcrt/MemoryConfig.h |
| Requested time budgets and initial timing probe | src/mcrt/TimingConfig.h |
| Debugging controls | src/mcrt/DebugConfig.h |
| Transport random seed and rank policy | src/mcrt/RandomConfig.h |
| Source mode, seed inheritance, point/plane geometry and shared/dataset source settings | src/mcrt/EmissionConfig.h |
| Native BPASS continuum inputs | src/mcrt/BPASSContinuumConfig.h |
| Analytic spectrum shapes and recipes | src/mcrt/SpectrumConfig.h |
| Trace storage shared with ray tracing | src/TraceConfig.h |
| Ionizing transport, iteration, convergence and thermal settings | src/ionizing/TransportConfig.h, src/ionizing/IterationConfig.h |
| Dataset loading and shared metadata | src/DatasetConfig.h |
| Desktop display, live server and rendering | src/display/core/DisplayConfig.h |
| Complete native run assembly | src/config/RunConfig.h |
These groups are plain structs. McrtConfig assembles the MCRT settings;
it does not contain devices, loaded datasets, measured durations, or allocations.
TransportConfig::propagation holds shared PropagationConfig values, including
HubbleConfig in its hubble member. Their YAML keys stay flat under the driver.
A new option normally belongs in an existing group. Introduce another group
only when it represents a coherent responsibility, rather than one function call.
Pass a relevant group or individual values to internal helpers.
Organize config files by subsystem. Related types can share a header and its
matching .cpp, as the source configs do in EmissionConfig. Keep schema and
decoder declarations beside the value types, using forward declarations for
config infrastructure. Include the schema implementation headers only where
the bindings are defined or used. A new config type does not need its own files.
To add a timing setting:
- Add its member and default in
TimingConfig.h. - Declare its input name, description, and scalar constraints in
describeTimingConfig()inTimingConfig.cpp:
fields.option("kernel_execution_target_time", &TimingConfig::kernel_target_seconds,
"Target kernel duration in seconds")
.finiteNonnegative();
- Use
.activeWhen(&TimingConfig::initial_probe, "requires initial_kerneltime_probe: true")for conditional fields.Fieldsreads unconditional boolean selectors first, independently of declaration order. Inactive inputs are ignored with a warning; their value constraints do not apply. - Consume the member and test meaningful YAML and direct C++ validation cases.
The same declaration supplies defaults, discovery, input ownership, and scalar
checks. Relationships between fields or groups belong in ordinary
validate*ConfigValues functions beside their component's declarations.
For example, memory validation receives MemoryConfig and PeelingConfig.
These functions accept plain values and a ValidationContext for diagnostic
paths; they do not parse input or initialize devices.
Scalar shortcuts can be chained: .finite(), .finiteNonnegative(),
.finitePositive(), .positive() (integers), .atLeast(lower), .atMost(upper),
.inRange(lower, upper), and .nonEmpty(). Bounds are inclusive and reject NaN;
add .finite() when infinity must also be rejected. Integer bounds compare
exactly across signed and unsigned types. Use floating bounds for floating
fields, for example .finite().inRange(0.0, 1.0). .nonEmpty() accepts strings
and containers; it does not reject whitespace. .check(predicate, message)
adds a component-specific rule. All stacked checks respect .activeWhen().
Existing component validators can call the same predicates from
config/ConfigChecks.h while retaining their diagnostic messages. Unit
conversion, representability after conversion, and relationships between
settings still belong in the component validator.
For enum inputs, config/ConfigChoices.h provides EnumChoices<Enum> and
choice(name, member, description, choices). One spelling table supplies
parsing, diagnostics, the advertised default, and contains(value) checks for
C++ drafts. Multiple spellings may map to one value; the first is canonical.
Custom bindings can use choices.read(input, optionalValue) when absence must
remain distinct from an explicit default, as for legacy line-phase overrides.
Older groups retain defaulted, optional, required, and activeWhen
bindings in their .cpp files. Their explicit schemas still read selectors
before dependent fields. Prefer the TimingConfig declaration pattern for new
settings; richer existing schemas can migrate when their input contracts are
covered.
The public typed MCRT initialization boundary accepts Validated<McrtConfig>:
mcrt::McrtConfig requested;
requested.timing.kernel_target_seconds = 2.5;
auto checked = config::ConfigValidator::validate(requested);
// Report checked.diagnostics, then initialize only on success.
if (checked.ok()) simulation.initialize(startup, datasetSetup, *checked.value);
The factory checks every assembled group and their relationships before creating
an immutable snapshot. Editing the draft cannot change it. YAML assembly uses
the same factory and adds input paths and source locations to its diagnostics.
Inside the driver, private plain config values suffice. The snapshot certifies
requested values, not compatibility with a particular dataset or device;
initialization checks those capabilities and prepares derived state.
For example, resolveRuntimeLimit receives the scheduler value explicitly and
computes a deadline separately from TimingConfig.
C++ groups need not add YAML sections. In the input assembly in McrtConfig.cpp,
flatten(member, schema) keeps a group's keys at the current YAML level;
section(name, member, schema) places them inside a named mapping. Register a
new group once there; discovery and input ownership use that same declaration.
The memory decoder receives the already decoded peeling selection. The private
assembly state tracks successful prerequisites, so a failed prerequisite prevents
its dependent decoder from running.
Schemas check that supplied inputs were decoded, explicitly ignored, or rejected.
Custom bindings must use readValue, ignore(reason), or error(message);
inspecting a node alone does not count. Named sections reject unknown keys and
audit their descendants. This checks input handling, not subsequent C++ member
access. Native assembly warns about unconsumed inputs after the selected owners
have run. Runtime APIs accept retained structs, so caller input can be released
before initialization. Test fixtures may decode YAML through the shared schemas;
production YAML dependencies are checked by the ThorConfigOwnership test.
Focused verification requires no simulation or device initialization:
./build.sh --debug --no-clean --target thor_config_tests
./cmake-build-debug-generic/tests/thor_config_tests
ThorConfigCli checks command-line discovery and validation; driver tests check
typed initialization. Physics regressions use release builds.
Vector components
Vec3<T> and Vec2<T> own fixed-size std::array storage. In C++, use
v.x(), v.y() and (for Vec3) v.z() to read or modify named components,
or v[i] for a runtime component index. These accessors return references
to the same elements. Indexing is unchecked: valid indices are 0–2 for
Vec3 and 0–1 for Vec2. v.data() exposes the contiguous component
array; it does not allocate memory.
Code migrating from the separate-member representation must replace
.x, .y and .z with accessor calls. Use explicit component reads
instead of decomposing a vector with a structured binding. Arithmetic,
formatting and YAML coordinate order remain the same. Python bindings
retain the writable v.x, v.y and v.z properties.
MPI reflection registers the references returned by the component accessors. Vectors remain standard-layout and trivially copyable for SYCL captures and transfers.
Project Structure
thor/
├── src/
│ ├── datasets/ # Dataset implementations
│ ├── drivers/ # Simulation drivers
│ ├── interactors/ # Define photon interactions
│ ├── outputprocessors/ # Output handling
│ ├── photongenerators/ # MC package spawning
│ ├── rngs/ # Random number generators
│ └── main.cpp # Entry point
├── tests/ # Unit tests (Catch2)
├── regression_tests/ # End-to-end simulation tests
├── scripts/ # Utility scripts (PractRand testing, etc.)
└── extern/ # (submodule) dependencies
Key Components
- Datasets (
src/datasets/): Computational meshes and geometry - Drivers (
src/drivers/): Simulation algorithms (MCRT, ray tracing)
Code Style
C++20 with SYCL, formatted via ./.clang-format.
sp(VAR),dp(VAR),fp(VAR): cast to single, double, or compile-timeFP.ip(VAR): cast to the compile-timeIP(32- or 64-bit signed integer).- Mark device-callable functions with
SYCL_EXTERNAL.
Testing
The project includes both unit and regression tests. For a detailed explanation of the testing frameworks and how to run tests, please see the Testing documentation.
Desktop downloads
A v* tag starts CDash Continuous in the THOR source repository. After the
checks pass, the desktop release workflow builds the Linux headless and GUI
AppImages and the Apple Silicon DMG from the tested commit. It uploads all
three files and SHA256SUMS to a draft in the
THOR downloads repository,
then publishes the draft. If an upload fails, rerun the workflow to finish the
same draft.
For publishing, install a GitHub App with Contents write access to
thor-rt/downloads. In the THOR source repository's desktop-release
environment, set the THOR_DOWNLOADS_APP_CLIENT_ID variable and
THOR_DOWNLOADS_APP_PRIVATE_KEY secret.
To verify the credentials, open Actions, select Release THOR desktop
downloads, and click Run workflow on main. This operation checks
that the app can obtain a token scoped to thor-rt/downloads.
The AppImage and macOS workflows also support manual builds. Use their Actions artifacts to try a build before cutting a release tag.
Documentation media assets
Where a media file lives depends on whether it should version with the repository:
- Videos and animations (
*.webm,*.mp4, animated*.webp) are never committed. They are hosted on the rolling GitHub release at thor-rt/docs-assets and referenced from markdown as full URLs. - Raster figures (
*.png) also go to the docs-assets release by default, especially large or presentation-style renders. Commit a PNG todocs/assets/images/only when it should track a code revision (benchmarks, validation plots, cookbook figures regenerated from committed scripts) or when it is small and stable. Committing one requiresgit add -fsince.gitignoreblocks*.png. The friction is deliberate: a committed PNG should be a conscious decision. - Vector figures (
*.svg) are committed normally; they are small and diff as text.
Figure style (scripts/thorplot.py)
Plots that go into the docs should use the shared house style so every figure
looks consistent. scripts/thorplot.py provides the THOR look — a minimal,
slide-style aesthetic (light by default; dark=True for dark pages). It offers two colour strategies: a fixed per-code
map (code_color) for neutral comparisons, and a "hero" treatment
(hero_colors, bold accent for one series + muted peers) for THOR-centric
figures. Plus small helpers:
import thorplot as tp
with tp.style(): # or tp.style(dark=True)
fig, ax = plt.subplots(figsize=tp.FIGSIZE_WIDE)
ax.plot(x, y, color=tp.code_color("thor"))
tp.strip_axes(ax); tp.legend_top(ax)
tp.save_doc_figure(fig, "my_plot") # -> docs/assets/images/my_plot.svg
save_doc_figure writes SVG by default — vector-crisp at any zoom, smaller
than PNG for line plots, and (unlike *.png) not blocked by .gitignore,
so it commits without -f and diffs as text. Pass fmt="png" for raster-heavy
figures (volume renders, dense scatter) where SVG would balloon.
Use tp.save_doc_figure() for all documentation exports, including figures
rendered in companion repositories. Pass output_dir=... to save elsewhere
and dpi=... to set raster resolution. The helper keeps exports transparent
even when called outside tp.style(). Direct fig.savefig() calls inside
the style also default to transparency. Use transparent=False for opaque
standalone exports.
Generate both a light and a dark version and reference them with mkdocs-material's light/dark suffixes so the figure follows the page theme:
scripts/plot_benchmark.py is a worked example (it renders the Neufeld
benchmark figure both ways).
The docs page stretches every image to the content-column width, so figures
authored at different widths display their fonts at different sizes. The
full-width reference is tp.DOC_FULL_WIDTH (12.2 in). Author full-column
figures at that width; for anything narrower, embed at the proportional
column width so fonts render at the intended size (save_doc_figure prints
the attribute to use):
For 2D coordinate maps (imshow panels), the house look is minimal: no
ticks, axis labels, or frames — a scale bar replaces the axes, and colorbars
are frameless with markless ticks. The helpers are in thorplot too:
with tp.style(dark=dark):
fig, axes = plt.subplots(1, 2, constrained_layout=True)
for ax, m, title in zip(axes, maps, titles):
im = ax.imshow(m, extent=extent, norm=norm, cmap="plasma")
tp.imshow_panel(ax, title) # strip ticks/labels/frame
tp.scalebar(axes[0], 10.0, "10 pMpc") # one bar; panels share the scale
tp.colorbar_minimal(fig, im, axes, label=r"$\langle L \rangle$ [pMpc]")
tp.suptitle_left(fig, "...", dark=dark)
Figure-generating scripts that only need data committed to this repo live in
scripts/plot_*.py. Scripts that need external snapshots or long runs live
in the companion thor_setups repo (setups/<topic>/python/, importing
thorplot from a side-by-side thor checkout). In that case record the
provenance next to the embed in the page source:
Uploading
Stage the file anywhere on disk, then run:
The script bootstraps the docs-assets release on first use, uploads with --clobber (re-uploads overwrite), and prints the canonical URLs to paste into markdown.
URL pattern
Naming rules
- Filenames are unique on the release. Don't re-upload to the same name unless you intend to replace the live content for every page that references it; bump a version suffix (
banner_v2.webp) when in doubt. - Orphaned assets stay until cleaned up explicitly:
gh release delete-asset docs-assets --repo thor-rt/docs-assets <filename>.
Sanity checks
# What's currently on the release
gh release view docs-assets --repo thor-rt/docs-assets --json assets -q '.assets[].name'
# What URLs the docs reference
grep -rhoE 'releases/download/docs-assets/[A-Za-z0-9._-]+' docs/ | sort -u
If something is in the second list but not the first, it's a broken image on the deployed site. If only in the first, it's an orphan.
AI Authorship Attribution
This project uses AI-assisted development (Claude Code) extensively. AI-generated code is tagged for transparency:
- Functions:
[AI-Claude]tag at the end of the\briefDoxygen line - Tests:
[AI]tag in Catch2 test tags, e.g.,[mytag][AI] - Shell scripts:
[AI-Claude]at end of first description comment line - Python modules:
[AI-Claude]at end of first docstring line
Tags are removed after in-depth human review and approval.
Contributing
Contribute by submitting pull requests from your fork and the new feature branch.
Report issues at GitHub Issues.