The software
Open-source Rust libraries built from first principles, with every result checked by an automated test.
Why tensors
“I admire the elegance of your method of computation; it must be nice to ride through these fields upon the horse of true mathematics while the like of us have to make our way laboriously on foot.”
The laws of physics do not depend on the coordinates used to describe them, so the mathematics that expresses them shouldn't either. Tensors have exactly this property: a tensor equation that holds in one coordinate system holds in all of them. For most problems this is a convenience. For Einstein's equations it is a necessity, because the geometry itself changes as the simulation runs, and no single fixed coordinate system can describe it.
Our library tensor-core implements tensors of general rank together with the operations of differential geometry: the metric and its inverse, raising and lowering indices, contraction, Christoffel symbols, covariant derivatives, and the Riemann, Ricci and Einstein tensors. It is tested against exact solutions such as the Schwarzschild black hole.
Derivatives
Every simulation is built on derivatives, and two different tools are used, each where it belongs.
Automatic differentiation for formulas
When a quantity is given by an exact formula, we use automatic differentiation. Any expression is broken into basic operations whose derivatives are known exactly, and the chain rule combines them. There is no approximation error, only floating-point rounding. The project began with our own automatic adjoint differentiation (AAD) library, which recorded expressions at run time. It now uses Enzyme, which differentiates compiled code inside the LLVM compiler: ordinary Rust functions on plain 64-bit numbers become differentiable at full compiled speed, with no run-time bookkeeping. The original AAD library remains available but is no longer developed.
Finite differences for grid fields
In a simulation, fields are known only at grid points, not as formulas, so spatial derivatives must be approximated from neighbouring values. We use 2nd- and 4th-order central stencils and check their accuracy with automated convergence tests: halving the grid spacing must reduce the error by the predicted factor.
Numerical methods
- Grid: uniform 3D grid, with a 3-cell boundary zone on every face.
- Spatial derivatives: 2nd- or 4th-order finite differences; Christoffel-symbol derivatives either by differencing or analytically via the chain rule.
- Time stepping: 4th-order Runge–Kutta (method of lines), with matter recomputed at every sub-step.
- Dissipation: 6th-order Kreiss–Oliger dissipation, which damps grid-scale noise without affecting the smooth solution.
- Surface integrals: 4th-order interpolation from the grid onto spheres, Gauss–Legendre quadrature, and projection onto spherical harmonics.
- Outer boundary: Sommerfeld radiative condition, so that outgoing waves leave the grid instead of reflecting (see latest findings).
- Formulation: ADM today, as a reference; Z4c with 1+log lapse and Gamma-driver shift for production.
- Initial data: the conformal method, solving the constraint equations as nonlinear elliptic equations.
Architecture
Three layers, each depending only on the one below:
simulation — physics of the experiment: pump protocols, the scan runner, output, checkpointssolver — numerics: grids, finite differences, evolution equations, boundaries, initial data, diagnosticstensor-core — mathematics: tensors, metric, curvature, automatic differentiation| Module | Responsibility |
|---|---|
tensor-core | Tensor algebra, metric, Christoffel symbols, Riemann/Ricci/Einstein tensors, Enzyme derivatives. Kept as the reference implementation. |
solver::grid | Grid storage, stencils, dissipation, Runge–Kutta stepping. |
solver::boundary | Sommerfeld radiative outer boundary for any field on the grid. |
solver::sphere | Interpolation onto spheres, sphere quadrature, spherical harmonics and mode projection. |
solver::flux | Energy and angular momentum carried by electromagnetic and gravitational waves through spheres. |
solver::poisson | Conjugate-gradient Poisson solver for starting data. |
solver::linear | Flat-space Maxwell and linearized gravity for the Phase B baseline. |
solver::z4c | Z4c/BSSN evolution with matter sources and evolving gauge, with upwind stencils for the shift terms; ADM remains as reference. |
solver::maxwell | Maxwell's equations on the curved slice, producing the matter source terms. |
solver::initial_data | Constraint-satisfying Einstein–Maxwell starting data. |
solver::diagnostics | Constraint norms, Ψ4 and its modes, gravitational angular momentum, fluxes, frame dragging, energy budget. |
simulation | Pump protocols (done: one-way wave packets, rotating ring of emitters); later the configuration-driven amplitude scans, output and restart. |
Engineering rules
- Rust and plain 64-bit arithmetic throughout.
- No memory allocation per grid point in hot loops: flat arrays and per-thread scratch buffers, parallelised over all cores with Rayon.
- Every fast path has a slow twin. The readable tensor implementation is kept as a test oracle, and the fast version must agree with it to 10−12.
- Test first. A feature is done when its acceptance test passes, including the measured convergence order.
- Store deviations from flat space where possible, to keep precision at small amplitudes.
- MIT licensed and developed in the open.
Milestones
| ID | Milestone | Done when |
|---|---|---|
| M1 | Grid and operators | Stencils, dissipation, Sommerfeld boundaries, interpolation onto spheres; tests G1–G5 pass. Done |
| M2 | Linear Maxwell and linearized gravity | L1, L4, L5 pass; the gauge condition drift converges to zero. Done |
| M3 | Linear diagnostics | Fluxes through spheres and angular momentum; consistent starting data for electromagnetically sourced gravity; L2, L3, D1, D2 pass. Done |
| M4 | Phase B science runs | Linear results for every protocol, with convergence evidence. |
| M5 | Z4c/BSSN with matter and evolving gauge | Upwind stencils for the shift terms; Z1–Z5 pass; agrees with the ADM reference on short runs. |
| M6 | Maxwell coupled to gravity | E1–E3 pass. |
| M7 | Constraint-satisfying initial data | I1–I3 pass. |
| M8 | Nonlinear diagnostics | D3–D6 pass. |
| M9 | Pump protocols, runner, scans | R1–R3 pass; a full scan point runs from a configuration file. |
| M10 | Phase C and D science runs | X1–X3 pass; nonlinear excess reported with error bars. |
Acceptance tests
Convergence tests use at least three resolutions and must show the design order to within ±0.3.
| ID | Test | Acceptance criterion |
|---|---|---|
| Grid and operators | ||
| G1 | Derivatives of smooth fields | Order 2 or 4 as designed |
| G2 | Mixed second derivatives | Order 2 or 4 as designed |
| G3 | Dissipation on a grid-scale mode | Damped by the predicted factor; smooth modes unaffected |
| G4 | Outgoing spherical pulse through the outer boundary | Reflection below 1% at the coarsest resolution, falling with resolution |
| G5 | Interpolation onto a sphere | Integrals of spherical harmonics exact to interpolation order |
| Linear physics | ||
| L1 | Maxwell plane wave | Matches the exact solution at design order |
| L2 | Oscillating electric dipole | Radiated power matches Larmor's formula within 2% |
| L3 | Rotating mass quadrupole | Radiated energy and angular momentum match the quadrupole formula within 2% |
| L4 | Superposition | Sum of two runs equals the combined run to round-off |
| L5 | Gauge condition | Drift converges to zero for conserved sources |
| Nonlinear evolution | ||
| Z1 | Flat space with tiny random noise | No exponential growth over 1000 crossing times |
| Z2 | Standard linear-wave test problem | Design-order convergence against the exact solution |
| Z3 | Standard gauge-wave test problem | Stable and convergent over 100 crossing times |
| Z4 | Small-amplitude Teukolsky wave | Ψ4 matches the analytic solution |
| Z5 | Fast vs. reference evaluation | Agree to 10−12 |
| Electromagnetism on curved space | ||
| E1 | Electromagnetic wave on a flat slice | Equals the linear code to round-off |
| E2 | Divergence constraints | Converge to zero |
| E3 | Energy, momentum and stress of the field | Match the closed-form expressions |
| Initial data | ||
| I1 | Constraint residual | Converges at design order |
| I2 | Weak-field limit | Matches the Newtonian potential to second order |
| I3 | Spinning test data | Measured angular momentum equals the input |
| Diagnostics | ||
| D1 | Energy balance (linear) | Injected = stored + radiated, to truncation error |
| D2 | Angular-momentum balance (linear) | Same balance for angular momentum |
| D3 | Radiation extraction | Teukolsky-wave modes correct; independent of extraction radius |
| D4 | Mass of a black hole | Schwarzschild data recovers its mass |
| D5 | Angular momentum | Spinning data recovers its angular momentum |
| D6 | Nonlinear energy budget | Balance closes to truncation error |
| Runner | ||
| R1 | Configuration round trip | Parse, write and re-parse give the same configuration |
| R2 | Checkpoint and restart | Restarted run bitwise identical to an uninterrupted one |
| R3 | Short end-to-end run | No invalid numbers, bounded constraints, readable output |
| Cross-validation (science-critical) | ||
| X1 | Small-amplitude limit | Full code reproduces the linear code, residual proportional to ε |
| X2 | Domain independence | Storage unchanged when the box is enlarged 1.5× (guards against the mirror trap) |
| X3 | Second-order consistency | Fitted quadratic coefficient matches second-order theory |
Compute budget
One 2nd-order time step currently costs about 1.8 µs per grid point; the 4th-order path with evolving gauge and dissipation about 7 µs. Z4c with Maxwell is expected to cost two to four times that. A run of 128³ points for 104 steps is therefore of order 10–40 hours on a single workstation, and linear runs are about ten times cheaper. If radiation must be measured far from the sources, nested grids (mesh refinement) will be needed; that decision waits for the Phase B measurements.
Source code
All code is MIT licensed and developed in the open.