Skip to content

Fortran reference binary is not reproducible; single-run parity gate is unstable #228

Closed

Description

@neuromechanist

test_end_to_end_correlation_vs_fortran_from_sample_params_json fails intermittently (correlation 0.90-0.94 against its >0.95 gate). It is not a regression: it reproduces on unmodified main.

Root cause

The reference binary is not reproducible. Two runs on identical data and an identical input.param give different answers:

condition identical? max abs diff in W run-to-run agreement
max_threads 10 (as shipped) no 0.42 0.987 mean best-match corr
max_threads 1 no 0.59 —

Single-threaded rules out reduction-order nondeterminism. amica15.f90 has no seed parameter — grep "case('seed')" returns nothing — so its initialization cannot be pinned from the parameter file.

Consequence: the test compares a deterministic, seeded NG fit against a random draw from the reference. A single-run threshold cannot be a stable gate, because the reference does not agree with itself to better than ~0.987 at this iteration budget, and lands in different basins across runs.

run_fortran_amica accepts a seed argument (validate_implementations.py:87) and never uses it. It cannot: there is nothing to pass it to.

Second, independent problem

run_fortran_amica writes only files, outdir, max_iter, lrate, pdftype, num_mix_comps into the parameter file; every other key in the caller's params dict is silently dropped for the Fortran side while still being honored on the Python side.

So params["do_newton"] = False configures NG without Newton and leaves Fortran at do_newton 1 from input.param. The harness already warns about params the NG backend cannot honor; the reverse direction is unguarded, and it is the direction that silently makes a parity comparison uncontrolled. (Found while trying to isolate whether Newton drove the nondeterminism — it does not, but the experiment was invalid until I noticed this.)

Why the failure looked order-dependent

The test passes run in isolation and fails when other tests precede it in the same process, which is what first drew attention. With a randomized reference that split may be coincidence rather than causation — 3 isolated passes and 4 loaded failures is not enough to establish a mechanism, and I could not find any global-state mutation in the preceding file (test_amica_ng_wrapper.py). The nondeterminism above is sufficient on its own to explain an unstable gate.

What this does not undermine

The paper's single-model numbers come from a 2000-iteration, Newton-disabled configuration, a far more converged regime than this test's 300 iterations with do_newton 1. Multi-model parity is already assessed distributionally against the reference's own run-to-run spread (#27), which is the correct treatment for exactly this reason. This issue is that a single-run gate was left in place for the single-model path.

Options

  1. Gate against the reference's own run-to-run spread rather than a fixed threshold — the Multi-model NG partition matching vs Fortran (>0.95 cross-corr) #27 treatment, applied to single-model.
  2. Compare against a committed reference output instead of re-running the binary, making the test deterministic.
  3. Raise the iteration budget until the reference is stable, and measure that it is.
  4. Keep the fit-based checks as a smoke test and drop the numeric gate, leaving the deterministic do_approx_sphere assertion (which the test's own docstring already calls "the actual regression guard") as the real check.

Option 2 or 4 for the test itself; option 1 if we want a genuine single-model parity gate. Fixing run_fortran_amica's parameter forwarding is required regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions