Skip to content

C3 Stage contract ​

IDGroupTypeBackendsFigureProgram
C3ContractsCCPU (gfortran, nvfortran, ifx; R8P and R4P); GPU (A30)noselah_test_stepper, selah_test_stepper_options, selah_test_stepper_ranks, selah_test_kernels, selah_test_xfail_*

Case and scope ​

A solver programs against the stage contract. This case checks every clause, and the options around it, as a solver would use them:

  1. Between begin_stage(k) and end_stage(k) the stage state holds stage k: q when stage_state_is_q(k), else stage_state().
  2. The stepper never writes a ghost cell.
  3. The caller may write the ghost cells of the stage state.
  4. rhs_register() is distinct from the stage state, and null outside the window, as stage_state() is.
  5. After finish_step the registers are scratch.

Setup ​

Clause or optionHow it is checkedProgram
no ghost cell written (2)every register and q start with a sentinel in their ghost layers; the layers the caller never fills keep it bit for bit through whole steps, every scheme and formselah_test_stepper
a kernel writes its box onlyevery kernel, both layouts, masked and unmasked, on a component range: every cell outside the box (ghosts, pool slots past the active blocks, other components, inactive cells) bitwise untouchedselah_test_kernels (348 checks)
residual register distinct (4)associated(rhs_register(), stage_state) false at every stageselah_test_stepper
no register outside a window (4)rhs_register() and stage_state() not associated after begin_step and after every end_stage, every scheme and formselah_test_stepper
state_aliases_q, stage_state_is_q (1)true exactly for the aliasing forms, and for the zero rows of A with stages_on_q; stage_state() null on such a stageselah_test_stepper
stages_on_qthe solution bitwise that of the plain Butcher form, every schemeselah_test_stepper
registers=NaN-filled caller registers give the solution of the own registers bitwise, in the Butcher, two-register, 2N and Ketcheson forms: no form reads a register before writing itselah_test_stepper_options
maskssolid blocks of q bitwise untouched through whole steps in four forms; mask_comp absent = the last componentselah_test_stepper_options, selah_test_kernels
the mask policy (masked_q)the solid cells of every stage state are qn bitwise, every Runge–Kutta scheme in the Butcher form (with and without stages_on_q, registers filled with NaN) and every other form; every stage state and the solution bitwise those of a caller that copies qn into the solid cells itself; the stage-state kernel with masked_q, both layouts, both mask components, 0 and 3 registers: inactive box cells =q, active cells the stage state, every other cell untouchedselah_test_stepper_options, selah_test_kernels
stage_time, finish_step(dq=)ck; for a splitting the other partition's fractions before flow k; dq=(qn+1−qn)/Δt to round-offselah_test_stepper_options
ADAM's foresttwo steppers (realms) driven stage by stage together: begin_stage(k) on every realm, the seam fill of every stage state from the neighbours', the residuals, end_stage(k) on every realm; per-stage seams give the single-block solution bitwise; lagged seams (#113: the ghosts of q kept through the step, copied into the stage state in the Butcher form) the lagged scheme's definition to 1000 ε; ∑k stage_weight(k) Fk telescopes every block's mass change; end-of-step reflux (on q after finish_step) and per-stage reflux (on rhs_register() before end_stage) conserve the mass to round-off; the caller's registers written or NaN-filled between steps (ADAM's D_flux diagnostic) leave the solution bitwiseselah_test_forest
time-dependent residualsthrough the stepper, every scheme and form: u′=qtq−1 exact to round-off for q≤p (Runge–Kutta stage times and weights; for a splitting, with either partition time-dependent); the observed order p on a nonlinear non-autonomous problem (the Riccati equation; a forced oscillator for the splittings)selah_test_nonautonomous
fields of rank 1 to 4seven shapes, every scheme and form: bitwise the rank-5 run; ghost cells of q and of every register untouched; both views null outside every window, rhs_register_view associated inside it, stage_state_view exactly when the stage is not on q; the stage coefficients; masks of q's rank with their own components (solid cells untouched, fluid cells bitwise the unmasked run)selah_test_stepper_ranks
stage coefficientsstage k of every form is stage k of the Butcher tableau, measured: with the residual 1 at every stage the stage state is qn+Δtstage_time(k); with the residual the indicator of stage j the step adds Δtstage_weight(j) (64 ε), every scheme and formselah_test_stepper
error stopsdq for a non-Butcher form; registers numbered from 0; rk4 in a two-register form: each program must stop with its messageselah_test_xfail_dq_form, _registers, _form

Program ​

bash
./exe/selah_test_stepper ; ./exe/selah_test_stepper_options ; ./exe/selah_test_stepper_ranks ; ./exe/selah_test_kernels
bash scripts/run_tests.sh       # runs the xfail programs and passes them when they exit with an error

Results ​

All checks pass on every compiler, in both precisions, and on the GPU: 314 in selah_test_stepper, 49 in selah_test_stepper_options, 848 in selah_test_stepper_ranks (694 in R4P), 348 in selah_test_kernels. The three expected failures stop with their messages. The A30 jobs of 2026-11-17 (C5) ran 248 checks of selah_test_stepper, before the stage window and the stage coefficients were added. Job 1368457 ran all of them on the A30.

Findings ​

  • No form reads a register before writing it: the stepper accepts uninitialised registers. Before the documentation audit of 2026-11-17 the 2N form's first stage computed 0⋅ΔQ, and a NaN in a caller's register poisoned the step. The 2N stage with A=0 now writes ΔQ=ΔtR without reading it.
  • initialize(registers=) now refuses registers whose slots are not numbered from 1 or whose bounds are not the field's. Such registers used to be indexed one slot off without a message.
  • Before 2026-11-18, rhs_register() outside a stage window returned, in the Butcher form, the stage-state register (slot k_active + 1 with no stage active), against clause 4, without a message. Both pointers are now null there.
  • Before 2026-11-18, stage_time was checked against the tableau it returns, in the Butcher form only: a stage of another form evaluated at another abscissa would have passed. The stage coefficients are now measured in every form. A swap of two abscissae (stages 5 and 6) fails the check in 8 scheme-form pairs, ssp-104 ket among them. A swap of two weights fails it in every pair where the two weights differ. Where they are equal (ssp-22, ssp-33, ssp-104: SSP(10,4)'s ten weights are all 1/10) the swap changes nothing a caller can observe.

GPL-3.0-or-later, BSD-2-Clause, BSD-3-Clause or MIT, at your choice