Skip to content

feat(engine): season simulator, portable sampler and benchmarks - #14

Merged
kymanirjarrett merged 4 commits into
mainfrom
feat/5-season-simulator
Dec 1, 2026
Merged

kymanirjarrett merged 4 commits into
mainfrom
feat/5-season-simulator

Conversation

@kymanirjarrett

Copy link
Copy Markdown
Owner

What

Milestone M1 for the engine:

  • One Poisson draw per side per match. A sum of independent Poisson variables is Poisson with the summed rate, so one draw gives the same distribution as the old 90 per-minute draws at 1/90 of the random draws. The existing closed-form convergence tests still pass unchanged.
  • Portable sampler. std::poisson_distribution uses implementation-defined algorithms, so the same seed gave different goals on libstdc++ and libc++. It is replaced with Knuth's multiplication method fed by a bit-exact uniform (top 53 bits of mt19937_64). split_mix moves into the shared random module.
  • Season simulator (simulate_season). Takes the current table, remaining fixtures and per-match goal rates; runs N seasons across std::thread workers with per-thread SplitMix64 seeds; returns each team's finishing-position and points distributions, mean points, and title, top-N and relegation probabilities. Ranking is points, goal difference, goals scored, then a seeded random tiebreak (head-to-head is not modelled).
  • Google Benchmark target (SUBSPOT_BUILD_BENCHMARKS, off by default) measuring seasons per second at 1, 2, 4 and 8 threads. Results table in the README.
  • pybind11 binding for simulate_season, with pytest tests replacing the inline smoke test.

Closes #5

Why

The season simulator drives the title, top-4 and relegation odds in the app. The portable sampler makes a seed reproducible across the g++ and clang++ builds, which the backtests and the iOS app both rely on.

How it was tested

  • Unit tests added or updated
    • PoissonKnuth.FixedSeedGivesKnownSequence: a hard-coded 20-draw sequence that must match on both compilers in the CI matrix
    • Two-team league matches the hand-computed answer, P(A champions) = P(home win) + P(draw)/2
    • Position probabilities sum to 1 per team and per position; points distributions sum to 1; same seed is deterministic; thread count does not bias results; invalid input throws
  • Locally: Release and ASan/UBSan builds pass (20/20) with Apple clang 21; Python binding tests pass (4/4)
  • CI passes (engine)

Benchmark (Apple M4, Release, median of 3)

Threads Seasons per second
1 63,400
2 122,800
4 233,500
8 327,600

@kymanirjarrett
kymanirjarrett merged commit cad1a3c into main Dec 1, 2026
5 checks passed
@kymanirjarrett
kymanirjarrett deleted the feat/5-season-simulator branch December 1, 2026 06:27
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.

Season simulator for title, top-four and relegation odds

1 participant