Skip to content

Honor ran_seed in deterministic runs#476

Merged
krystophny merged 1 commit into
mainfrom
fix/deterministic-ran-seed-main
Jul 12, 2026
Merged

Honor ran_seed in deterministic runs#476
krystophny merged 1 commit into
mainfrom
fix/deterministic-ran-seed-main

Conversation

@krystophny

Copy link
Copy Markdown
Member

Re-lands #452 on main. That pull request was squash-merged into its stacked
base fix/ci-slow-test-gates (#454), so main never received the fix. This
branch cherry-picks the squash commit d8506f9 onto current main
(3cfba79); it applied without conflicts.

Deterministic runs ignored ran_seed and always produced the default stream,
so distinct seeds could not generate independent particle sets. params.f90
now forwards the configured seed, test_deterministic_seed.f90 checks that
distinct seeds change the stream while the default seed reproduces the
previous one, and the orbit-output example input records the seed it uses.

Verification

Test fails on main

src/params.f90 reverted to origin/main, test kept:

$ fo test test_deterministic_seed
test_deterministic_seed                    FAIL       0.11s
Summary: 0 passed, 1 failed, 0 skipped (  0.11s)

Test passes after fix

$ fo test test_deterministic_seed
test_deterministic_seed                    PASS       0.12s
Summary: 1 passed, 0 failed, 0 skipped (  0.12s)

fo build and fo lint pass on the branch (no new warnings; 0 unused
imports).

Fixes #464

## Risk tier

- [ ] T0: docs, comments, small build metadata
- [ ] T1: pure refactor, no behavior change intended
- [ ] T2: local numerical logic
- [x] T3: physics, output behavior, coordinate convention
- [ ] T4: parallelism, GPU, dependency, CI, or security-sensitive build
logic

## Correctness contract

### Intended behavior change

`ran_seed` controls the Fortran random stream when
`deterministic=.true.`. Equal seeds reproduce the stream; different
seeds change it.

### Behavior that must not change

Orbit equations, integrators, field evaluation, loss criteria, parallel
dispatch, and deterministic replay for an explicitly fixed seed are
unchanged.

### Coordinate / unit conventions

No coordinate, unit, boundary, or symmetry convention changes.

### Numerical invariants

Only sampled initial conditions may change. The historical NetCDF
fixture now explicitly requests seed 42. The chartmap pipeline keeps its
existing calculations, assertions, and plots.

## Tests added

- unit: namelist-level deterministic seed regression
- integration: existing NetCDF orbit output, verification, and plot
tests
- system: full `fo` pipeline
- golden record: not regenerated

## Golden-record impact

- [x] unchanged
- [ ] changed

## Failure modes considered

Same-seed non-reproducibility, ignored distinct seeds, invalid orbit
fixture sample, and plot-enabled chartmap runtime exceeding its former
60 s timeout.

## Manual validation

The NetCDF fixture passes with its historical seed 42. The plot-enabled
chartmap pipeline passes in 59.71 s with a 120 s timeout.

## Verification

### Test fails on main

```text
fo test test_deterministic_seed
ERROR STOP different ran_seed values produce the same random stream
Summary: 0 passed, 1 failed
```

### Test passes after fix

```text
fo test test_deterministic_seed
test_deterministic_seed PASS 0.06s
Summary: 1 passed, 0 failed, 0 skipped

fo
Static: OK
Build: OK
Tests: OK
Lint: OK
All stages passed
```
@krystophny krystophny merged commit 63ab6cb into main Jul 12, 2026
7 checks passed
@krystophny krystophny deleted the fix/deterministic-ran-seed-main branch July 12, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant