Which Instrument for Which Symptom¶
FlexMESA provides a layered set of diagnostics for localizing differences against upstream MESA 26.4.1, isolating non-determinism, and comparing standalone microphysics or oscillation outputs at the IEEE-754 binary64 level. Choosing the right instrument first saves full-trajectory reruns and prevents chasing downstream symptoms that originate earlier in a step or stage.
Diagnostic runs versus strict acceptance
Commands that accept --allow-unsupported-controls run past unported upstream &star_job or &controls keys for triage, whereas acceptance checks require strict control validation without ignored controls (flexmesa harness run). MESA reference overlays also run against a private scratch copy of $MESA_DIR (MESA_SKIP_OPTIONAL=t unless noted otherwise) so the pristine upstream tree stays untouched.
1. The Divergence Localization Ladder¶
When a test-suite case differs from MESA 26.4.1 or drifts between configurations, narrow the discrepancy from coarse trajectory behavior down to the first differing solver record, kernel call, or floating-point bit:
flowchart TD
S["1. Trajectory check (flexmesa harness run / flexmesa trace)"] --> Q1{"First difference at model 1 or later?"}
Q1 -- "Model 10+" --> B["2. Automated window search (flexmesa trace bisect)"]
Q1 -- "Model 1..3" --> C["3. Solver step dump (flexmesa trace --compare)"]
B --> C
C --> Q2{"First differing record tag"}
Q2 -- "STATE / DM / AUX" --> R["4a. Routine replay or pre-solver state tap (flexmesa-replay, oracles)"]
Q2 -- "EQU / CALL dt / CORR / TRY" --> X["4b. Opt-in XTRA scalars and Jacobian blocks (run_stepdumps.py --xtra star)"]
Q2 -- "Domain-specific (RSP, RLOF, GYRE, omega)" --> D["4c. Targeted domain wrapper (-Wl,--wrap, LD_PRELOAD, XTRA binary-rlo)"]
Work down this ladder from coarse trajectory to single routine:
- Confirm the trajectory and stage: determine whether the symptom is an unsupported control, a stage or step-count mismatch, an inlist interval artifact, or a numerical trajectory shift.
- Pinpoint the first differing model: avoid manually stepping through thousands of lines of
LOGS/history.datawhenflexmesa trace bisectcan binary-search monotonic stages using cached MESA step-dump bundles (mesa_stepdumps,mesa_stepdump_windows). - Inspect the first differing record inside that model:
flexmesa trace --comparechecks zone-level solver inputs (STATE,DM,AUX,EQU) before Newton iteration records (CALL,CORR,NEWTON,FOLD,TRY,RESID) and reports IEEE-754 hex bit patterns plus ULP distances. - Isolate the responsible routine or kernel: once the differing variable, zone, or auxiliary field is known, drop down to record/replay (
flexmesa-replay), Jacobian block dumps (--xtra starpaired withFLEXMESA_STEPDUMP_XTRA_JAC_ZONES), linker-wrapped capture hooks (pulse_export_tap,astero_track_tap,lina_dgeev_oracle), or standalone Fortran module oracles (benchmarks/fortran_mesa/*_oracles/).
2. Symptom-to-Instrument Decision Table¶
| Observed symptom | First instrument to run | Primary entry point | What it sees | What it misses or caveat |
|---|---|---|---|---|
| History column drifts, stops early, or misses termination | Harness / incremental trace | flexmesa harness run --cases <suite>/<case> --early-stop-on-divergence (star only) or flexmesa trace <suite> <case> --out <dir> |
Manifest track tolerances, step counts, stage counts, termination code, ignored controls, and per-step LOGS/history.data or binary_history.data |
--early-stop-on-divergence checks single-stage star cases only; cannot pinpoint which solver record, zone, or kernel caused the first shift inside a step |
First history column differs at model N (all printed columns, bit-exact) |
No integrated bit-exact trace history comparator yet (#969) |
Run flexmesa trace <suite> <case> --out <dir> and compare emitted LOGS/ externally against cached MESA runs/ |
history_compare interpolates manifest tolerance columns on a coordinate grid and omits non-manifest columns |
Full un-interpolated comparator (python -m flexmesa.testing.full_history_compare from PR #968 once merged; flexmesa diff runs CLI wrapper planned under #969, no diff runs CLI command exists yet) |
Step count, dt limiter, or retry reason differs from MESA |
No matched step-decision tap on both sides yet (#961) |
FLEXMESA_STEP_TRACE + FLEXMESA_STEP_TRACE_FILE (plus FLEXMESA_DISABLE_RUNTIME_CACHE=1 for cache isolation) |
Per-attempt retry events, argmax residual summaries, timestep collapses, omega_mix warnings, and binary outer/implicit retries inside FlexMESA |
FlexMESA-only decimal (6e) JSONL with no paired MESA dt-limiter / retry-reason comparator yet (#961); must set FLEXMESA_STEP_TRACE_FILE under trace subprocesses |
Relax result or saved .mod model differs (star_job relax / pre-evolve) |
No committed .mod bitwise comparator or relax phase taps yet (#962) |
Compare initial STATE records via flexmesa trace --compare <dump> once evolution starts, or inspect saved .mod files directly |
STATE captures zone arrays at the first solver call of each dumped model |
Cannot localize differences inside relax_* phases or between saved .mod cells before solver entry (#962) |
RSP last-bit residual or nonlinear oscillation evolution differs |
No RSP step dump yet (#963, #837) |
benchmarks/fortran_mesa/lina_dgeev_oracle/ (initial LINA eigenproblem only) |
lina_dgeev_oracle/ isolates initial dgeev matrix inputs and eigenvectors for LINA |
Current stepdump_patch.py and trace --compare hook star_solver only, which is bypassed when RSP_flag is set; nonlinear rsp_step dumps are tracked in #963 / #837 |
| Monotonic stage diverges ten or more models into evolution | Automated step-dump bisection | flexmesa trace bisect <suite>/<case> --work-dir <dir> |
First model m below first_diverging_step + 1 where zone inputs or solver records leave bit identity, reusing mesa_stepdumps and mesa_stepdump_windows |
Exempt exit codes (0 found, 4 no diff, 1 failed, 3 MESA needed, 5 restart unsupported); later stages (--stage > 1) apply to star cases only |
| First difference is at model 1..3, after an in-stage restart, or in a known window | Solver step-dump comparison (local or GitHub Actions case-run.yml) |
flexmesa trace <suite> <case> --out <dir> --compare <dump>.stepdump [--stage S --occurrence K] or gh workflow run case-run.yml -f mode=compare ... |
Bit-level STATE, DM, AUX, EQU, CALL, CORR, NEWTON, FOLD, TRY, and RESID records plus ULP distances |
Does not enter RSP when RSP_flag is set (#963); skips XTRA and RESTART records without diffing them |
| Batch triage needed across many cached MESA step dumps | First-divergence summary table | python benchmarks/fortran_mesa/stepdumps/first_divergence_table.py --dumps <dir> |
Aggregated Markdown and JSON table of first divergence model, record, column, and ULP distance across cases or windows | Skips secondary stages of binary and astero dumps; passes --allow-unsupported-controls without flagging diagnostic rows in Markdown |
STATE matches, but EQU, CORR, TRY, or CALL dt differs |
Manual inspection of opt-in solver XTRA and Jacobian blocks (#962) |
run_stepdumps.py --xtra star alongside FLEXMESA_STEPDUMP_XTRA_JAC_ZONES |
MESA emits START_*, RESID0/RESID_*, CORR_*, and JAC_L/D/U; FlexMESA emits SCALAR_gradT_excess_alpha, JAC_L/D/U, and MLT_* only |
trace --compare skips all XTRA records and Rust omits START_*/RESID*/CORR_* (#962), so XTRA comparison is manual today |
AUX (Peos, opacity, gradT, mlt_vc, chiRho, chiT, Cp) differs at matching STATE |
Routine record/replay capture | benchmarks/fortran_mesa/replay/run_capture.py, FLEXMESA_REPLAY_TAP, and flexmesa-replay |
Exact bit-for-bit inputs and outputs on TDC, MLT, GETR, and EOS calls fed identically into both engines |
Captures TDC, MLT, GETR, and EOS only; does not intercept arbitrary star routines |
Binary implicit RLOF mdot or bracket convergence differs |
Binary RLOF XTRA or instrumented fixture |
run_stepdumps.py --xtra binary-rlo --xtra-binary-models FIRST:LAST or benchmarks/fortran_mesa/binary_rlof_fixture/instrumented/run_instrumented.py |
MESA explicit vs. implicit mdot, f, bracket bounds (mdot_lo, mdot_hi), find0_quadratic/find0 fallback, and rate clamps |
FlexMESA has no binary-rlo XTRA emitter yet, so compare manual .xtra values against FlexMESA solver/RLO logs; requires --xtra-binary-models |
Rotation omega or adjust1_omega differs across remeshes |
Recycled omega sequence comparator |
benchmarks/fortran_mesa/recycled_omega/mesa_omega_tap.patch + compare_omega_reads.py |
Out-of-range reads past the previous remesh (prev_nz_old), matched in remesh order per star |
Targets binary_other_irot remesh buffer reads only (rotmix_oracles/ covers 1D rotational diffusion coefficients) |
Oscillation frequencies, mode order, GYRE/FGONG/OSC exports, or astero tracks differ |
Pulsation call tap, exporter dump, and multi-track wrapper | benchmarks/fortran_mesa/gyre_pulse_data/compare_pulse_live_run.py, pulse_export_tap/, astero_track_tap/ |
Separates exporter differences from live evolution drift, tracks every GYRE/ADIPLS call (l, m, n_pg, hex frequency, inertia, growth rate), and preserves per-track astero histories |
Astero search cases write raw mode files via FLEXMESA_PULSE_TAP; export comparison requires compiled MESA tap run for pulse_export_tap |
Mid-run #684 windows (windows_e2e.toml) or radial profileN.data files differ |
No committed E2E window runner (#964, under #684) or profile comparator (#963) yet |
Plan/inspect windows with scripts/windows/{plan_windows.py,make_window_inlist.py} and emit profiles via flexmesa trace --write-profiles |
windows_e2e.toml records CRC32-seeded window boundaries and .mod rules; --write-profiles writes profileN.data files |
Requires external/manual comparison until the window runner (#964, under #684) and profile comparator (#963) land |
Single microphysics kernel (eos, kap, net, turb, atm, math, newuoa) shifts by 1 ULP or diverges |
Module-hex gate & standalone Fortran hex oracle suites | python -m flexmesa.testing.module_hex_gate, benchmarks/fortran_mesa/*_oracles/, op_mono_*, math_hex_vectors/, newuoa/, and scripts/mesa_reference/run_module_hex_tests.py |
Checks 0-ULP agreement for probed modules against known_module_gaps.toml (declared gaps allowed), and captures LD_PRELOAD libgfortran_hex_tap.so bit vectors |
Tests isolated module/oracle inputs outside coupled evolution; unprobed modules are declared in known_module_gaps.toml |
| Gap ledger drift or non-determinism across thread counts / hosts | Known-gaps gate & strict determinism audit | python -m flexmesa.testing.known_gaps_gate --fail-on-imperative-skips and scripts/check_strict_determinism.py |
Checks bijective test-gap declarations vs. known_gaps.toml, math hex vectors, and 1-thread vs. multi-thread / cross-architecture bit identity |
Checks repeatability and gap hygiene across FlexMESA configurations rather than divergence against MESA |
3. Exact Invocations by Workflow¶
Trajectory Triage (flexmesa harness, flexmesa trace)¶
Run a single case in strict mode while saving every accepted row to LOGS/history.data (or binary_history.data), or let harness run stop as soon as tracked history columns leave manifest bounds:
flexmesa trace star 1.3M_ms_high_Z --out run_out
flexmesa harness run --cases star/1.3M_ms_high_Z --early-stop-on-divergence
For multi-stage star cases whose rn script normally skips optional early stages under MESA_SKIP_OPTIONAL=t, keep default stage skipping to match stored references (--full-stages includes optional early stages for standalone runs). Pass --respect-intervals only when matching MESA's inlist history_interval instead of logging every step.
Generating and Comparing Solver Step Dumps¶
First generate a MESA 26.4.1 step dump in a private overlay under an empty --scratch directory (never modifying $MESA_DIR):
python benchmarks/fortran_mesa/stepdumps/run_stepdumps.py \
--mesa-dir "$MESA_DIR" \
--mesasdk-root "$MESASDK_ROOT" \
--scratch m_scratch \
--out m_dumps \
--steps 3 \
--cases star/1.3M_ms_high_Z
To target a later window in stage S at the K-th crossing of model F (reusing an already-built overlay with --reuse-overlay):
python benchmarks/fortran_mesa/stepdumps/run_stepdumps.py \
--mesa-dir "$MESA_DIR" \
--mesasdk-root "$MESASDK_ROOT" \
--scratch m_scratch \
--reuse-overlay \
--out m_dumps \
--stage 2 --first-model 1 --occurrence 2 --steps 3 \
--cases star/make_planets
Compare FlexMESA against that MESA .stepdump file (use --ignore to mask downstream columns or record tags once a lower-priority mismatch is already understood):
flexmesa trace star make_planets --out fm_out --compare m_dumps/star/make_planets.stepdump
flexmesa trace star make_planets --out fm_out --compare m_dumps/star/make_planets.stepdump --ignore EQU xa
flexmesa trace --compare exits 0 if every compared record is bit-identical, 2 if a difference is found, and 1 if the run fails. For remote single-case or windowed step-dump comparisons without tying up a local workstation, dispatch .github/workflows/case-run.yml in compare mode (against cached mesa_stepdumps or a specific -f window=<id> from mesa_stepdump_windows, failing on exit status 2):
gh workflow run case-run.yml --ref <branch> \
-f cases="star/high_z star/ns_h" -f mode=compare [-f window=<window_id>]
To summarize a local directory of dumps and mid-run windows into Markdown and JSON tables:
python benchmarks/fortran_mesa/stepdumps/first_divergence_table.py \
--dumps m_dumps \
--work table_scratch \
--markdown-out first_div.md \
--json-out first_div.json
Automated Step-Dump Bisection (flexmesa trace bisect)¶
When divergence begins deep inside a monotonic stage, run flexmesa trace bisect with a dedicated --work-dir (rerunning the same command resumes from state.json):
If cached bundles (mesa_stepdumps, mesa_stepdump_windows) do not cover the remaining interval, either provide --mesa-dir, --mesasdk-root, and --mesa-scratch so bisect generates the missing MESA window automatically, or let it print the exact run_stepdumps.py command and exit with code 3. Note that unlike flexmesa trace --compare (0 identical, 2 differs, 1 error), flexmesa trace bisect uses its own exit codes (trace_bisect.py):
0: first differing model found and report printed.1: a FlexMESA or MESA run failed or exceeded--timeout-sec/--max-rss-gb(partial dumps are not trusted; rerun with higher limits).3: a MESA window is needed and--mesa-dirwas not supplied.4: every window up to the harness's diverging model agreed.5: the target stage restarts its model numbers in-process (for example relax followed by evolve); localize those cases window by window withflexmesa trace --compare --occurrence.
When comparing a candidate source tree in parallel or under a compute wrapper, pass --flexmesa-src <worktree>/src, --run-prefix, and --mesa-prefix, or --skip-bundle mesa_stepdumps mesa_stepdump_windows together with explicit --mesa-dumps directories.
Solver XTRA Scalars, Jacobian Blocks, and Binary RLO Diagnostics (Manual Inspection)¶
When a step dump flags EQU, CORR, or CALL dt at a matching input STATE, you can capture additional solver scalars and block-tridiagonal Jacobian matrices (JAC_L, JAC_D, JAC_U) on MESA via --xtra star, and Jacobian + MLT_* + SCALAR_gradT_excess_alpha records on FlexMESA via FLEXMESA_STEPDUMP_XTRA_JAC_ZONES:
python benchmarks/fortran_mesa/stepdumps/run_stepdumps.py \
--mesa-dir "$MESA_DIR" \
--mesasdk-root "$MESASDK_ROOT" \
--scratch m_xtra_scratch \
--out m_xtra_dumps \
--xtra star \
--xtra-zones 36,37,262,474:481 \
--xtra-corr-zones 1,262,474:481 \
--stage 2 --first-model 9 --steps 3 \
--cases star/make_planets
FLEXMESA_STEPDUMP_XTRA_JAC_ZONES=1,262,474:481 \
flexmesa trace star make_planets --out fm_out \
--compare m_xtra_dumps/star/make_planets.stepdump
With FLEXMESA_STEPDUMP_XTRA_JAC_ZONES set, flexmesa trace --compare writes FlexMESA's step dump (including XTRA records) to fm_out/flexmesa.stepdump and prints skipped unknown record types: XTRA x... in the summary.
Manual XTRA inspection (#962)
flexmesa trace --compare skips and counts XTRA (and RESTART) lines without diffing them, and FlexMESA currently emits only SCALAR_gradT_excess_alpha, JAC_L/JAC_D/JAC_U, and MLT_* (no START_*, RESID0_*, RESID_*, or CORR_* records yet). Compare XTRA lines between m_xtra_dumps/star/<case>.stepdump and fm_out/flexmesa.stepdump manually, and match MLT_* derivatives by semantic variable rather than raw slot index because FlexMESA's internal 24-slot AD vector orders partials differently from MESA's 33-slot d1Array.
For implicit Roche-lobe overflow iterations in binary cases, capture binary/<case>.xtra on MESA across the target model range (FlexMESA has no binary-rlo XTRA emitter yet, so inspect the captured MESA .xtra iterations manually alongside binary step logs):
python benchmarks/fortran_mesa/stepdumps/run_stepdumps.py \
--mesa-dir "$MESA_DIR" \
--mesasdk-root "$MESASDK_ROOT" \
--scratch m_rlo_scratch \
--out m_rlo_dumps \
--xtra binary-rlo \
--xtra-binary-models 102:102 \
--cases binary/wind_fed_bhhmxb
Routine Record/Replay (flexmesa-replay)¶
When zone-level AUX values (Peos, opacity, gradT, mlt_vc, chiRho, chiT, Cp) differ on matching STATE inputs, capture TDC, MLT, GETR, and EOS routine calls from MESA and replay them inside flexmesa-replay:
python benchmarks/fortran_mesa/replay/run_capture.py \
--mesa-dir "$MESA_DIR" \
--mesasdk-root "$MESASDK_ROOT" \
--scratch replay_scratch \
--out replay_out \
--models 1 \
--cases star/conserve_angular_momentum
cargo run --release -p flexmesa-replay -- replay_out/star/conserve_angular_momentum.replay
To compare routine-level captures directly between MESA and FlexMESA (writing FlexMESA's capture with FLEXMESA_REPLAY_TAP=<file>, optionally scoped by FLEXMESA_REPLAY_TAP_MODELS and FLEXMESA_REPLAY_TAP_FIRST):
FLEXMESA_REPLAY_TAP=fm.replay FLEXMESA_REPLAY_TAP_MODELS=1 \
flexmesa trace star conserve_angular_momentum --out fm_out --max-steps 1
cargo run --release -p flexmesa-replay -- compare \
replay_out/star/conserve_angular_momentum.replay fm.replay --all-diffs
Pulsation, Astero Tracks, Recycled omega, and Module Hex Oracles¶
- Live oscillation calls (
GYRE/ADIPLS): compare every mode call and emission label(l, m, n_pg)against MESApulse_tap/modes.tsv:
python benchmarks/fortran_mesa/gyre_pulse_data/compare_pulse_live_run.py \
--suite astero --case example_astero \
--histories path/to/mesa_histories \
--work pulse_work --out pulse_cmp.tsv
- Pulse export isolation (
GYRE/FGONG/OSC): capture exactstar_infoarrays enteringexport_pulse_datawithbenchmarks/fortran_mesa/pulse_export_tap/(pulse_dump_tap.f90,pulse_dump_wrap.c). - Multi-track astero histories: preserve every
run1_starobjective evaluation withoutLOGS/history.dataoverwrites viabenchmarks/fortran_mesa/astero_track_tap/run_tracks.sh. - Recycled
omegareads pastprev_nz_old: match remesh buffer reads in order across MESA and FlexMESA tap files:
python benchmarks/fortran_mesa/recycled_omega/compare_omega_reads.py \
MESA_TAP.txt FLEXMESA_TAP.txt --limit 145
- Standalone microphysics, module-hex gate, and gap-ledger gates: build module oracle TSV/hex vectors against
$MESA_DIRusing each subdirectory'sMakefile(underbenchmarks/fortran_mesa/*_oracles/,op_mono_*,math_hex_vectors/,newuoa/) or intercept all MESA<module>/test/floating-point writes usingscripts/mesa_reference/run_module_hex_tests.py. Check repository-level module-hex conformance againstknown_module_gaps.tomland bijective test-gap declarations with:
python -m flexmesa.testing.module_hex_gate --check-summary
python -m flexmesa.testing.known_gaps_gate --fail-on-imperative-skips
math_hex_vectors conformance and 1-thread vs. multi-thread history identity with scripts/check_strict_determinism.py:
python scripts/check_strict_determinism.py --json-out det_host_a.json
python scripts/check_strict_determinism.py --compare det_host_a.json det_host_b.json
- Retry-cascade JSONL telemetry & cache bypass: enable
FLEXMESA_STEP_TRACE(1-based starting step number) withFLEXMESA_STEP_TRACE_FILEso subprocess-guardedflexmesa traceruns append single-line JSON events rather than losingstderr, or passFLEXMESA_DISABLE_RUNTIME_CACHE=1to rule out derived runtime cache effects:
FLEXMESA_STEP_TRACE=780 FLEXMESA_STEP_TRACE_FILE=step_trace.jsonl \
flexmesa trace star <case> --out fm_out
FLEXMESA_DISABLE_RUNTIME_CACHE=1 \
flexmesa trace star <case> --out fm_nocache
4. Interpreting Output and Avoiding Common Traps¶
- Zone records come before solver records. In
flexmesa trace --compare, zone arrays (STATE,DM,AUX,EQU) at a model's first solver call are compared beforeCALL,CORR,NEWTON,FOLD,TRY, andRESID. A timestep shift at the end of modelmtherefore shows up at modelm + 1first inSTATE/EQU(and inCALL'sdtline if zone arrays agree or are masked). - Reading mismatch classifications cleanly:
missing: one engine stopped early or wrote fewer models, zones, or solver iterations.zone: first zone-level bit mismatch inSTATE,DM,AUX, orEQU; inspect the per-column summary to see whether all zones shifted uniformly or one localized shell moved.control: solver iteration structure diverged (CALL/CORR/TRY/RESIDrecord tag or counter mismatch, such as an extra Newton iteration or line-search backtrack).value: identical solver step structure with differingbinary64bits; checkULP distance(1ULP often points to operation ordering, fused multiply-add, or elementary math evaluation, while> 10^6ULPs points to a missing term or sign).location: same scalar norm bits, different argmax(zone, index)tie-break.- Hex bit patterns preserve signed zero and special values. Step dumps and hex taps print 16-digit IEEE-754
binary64integers (0000000000000000for+0.0versus8000000000000000for-0.0, exact signaling/quietNaNpayloads). Treating-0.0 == +0.0at decimal readout can miss sign-bit differences that propagate later through branch conditions. - Understand MESA
sizequresidual weights. Whendo_burnordo_mixis active, MESA'sresidual_norm(sizequinstar/private/solver_support.f90) adds chemistry equations twice (j > nvar_hydro), dividing by(nvar + nvar_chem) * nz. ComparingRESID_EQUSUMagainstRESIDnorms reproduces this weighting directly. - Alignment rules when model numbers reset or overlap. In runs with relax phases before evolution,
--first-model F --occurrence Kcounts both upward crossings ofFand drops inmodel_numberlanding at or aboveF. For stage-by-stage dumps (--stage S), MESA numbers each./rnexecutable that reachesstar_solverby itsRUNrecord; in multi-star or restarted outputs, avoid deduplicating solely onmodel_number. - Guard private diagnostic edits strictly outside baselines. Never edit
$MESA_DIRin place or keep unverified privaterun_star_extras.f90edits in reference bundles; delete disposable scratch overlays after recording measurements.