Skip to content

Release v0.8.0: B-splines, Neff backgrounds, and growth prescriptions - #57

Open
marcobonici wants to merge 31 commits into
mainfrom
develop
Open

marcobonici wants to merge 31 commits into
mainfrom
develop

Conversation

@marcobonici

@marcobonici marcobonici commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

v0.8.0 release candidate (develop → main)

Migration: the two old registry keys are removed, not aliases. The dictionary exposes 16 new scalar models. Rebuild inputs from each model’s ordered metadata and select outputs by label (7 → 11). The old flat nine-vector ended Mnu, w0, wa; the new flat one-mass, default-helium vector ends w0, wa, Neff. One-mass models fix (0.06, 0, 0) eV; degenerate models take a mass sum. sigma8 keys denote total matter at z=0.

Analytic API: pass three physical masses, not a scalar. Hybrid is the default: temperature rescaling below Neff=3.044, radiation at and above the switch, using the radiation-side derivative at equality in Float32 and Float64. Pass temperature explicitly to recover the previous convention. Cold+baryon growth and approximate matter growth are distinct; the latter is not full scale-dependent perturbation growth. Reusable cubic B-spline plans include banded construction and local evaluation.

Curvature derivatives (25779d3): S_of_K now uses the analytic series for |Ωk r²| ≤ 0.25 in its derivative rule, avoiding cancellation near flatness and restoring the correct flat Hessian. The public API and primal distances are unchanged. Positive Ωk denotes open (sinh) geometry; negative Ωk denotes closed (sin) geometry. At r=1 and Ωk=0, the curvature gradient is 1/6 and the Hessian is 1/60.

Local curvature validation: 575 Python CPU tests and both documentation JavaScript tests passed for the derivative fix. All 25 curvature tests passed again after correcting the geometry labels. Tests cover Float32/64, forward and reverse AD, mixed second derivatives, and dM_z. A separate 46-point comparison against 70-digit references covered both curvature signs and the series switch. These are local results; see Checks for CI at this head. No wall-clock performance claim.

Validation: matched CLASS fixtures check analytic expansion and distances; separate growth-ODE and CAMB background checks are not independent tests of all 11 neural outputs. Registry checks establish loading and inference, not full-domain accuracy. The archives report internal errors and some nonpositive distance predictions. Independent 10k evaluation and amplitude round trips remain pending. Use the Checks tab for current-head CI; historical counts below apply only to the revisions named. No merge or tag is part of this update.

Historical release notes and validation at earlier revisions (superseded where inconsistent)

Release preparation

Merge develop into main for v0.8.0. pyproject.toml and the runtime __version__ agree at 0.8.0; the latest release is v0.7.0. This is a pre-1.0 minor release with new APIs and a deliberate change to the explicit vector-mass convention.

No tag or GitHub release is created by this PR. Tag the merged main commit later.

Reviewed head: 20a0712 (20a071266702e12540b06236a16629db31468c4c). Companion Julia release: ACE v0.12.0, CosmologicalEmulators/AbstractCosmologicalEmulators.jl#100

Changes

  • Cubic B-spline interpolation with tests, documentation, saved Julia references and benchmarks.
  • Growth-source prescriptions (Gerrit's work) with the source selected outside the numerical ODE RHS: static species="cb" / "m", dynamic cosmological parameters.
  • Three individual neutrino masses and differentiable Neff for backgrounds, distances and growth, matching ACE's CLASS-anchored temperature / radiation prescriptions. The massless subtraction includes every species.
  • Raw initial-condition growth normalisation is kept.

Review fixes (40d4ce8, 20a0712)

  • Growth state. Scalar and three-mass growth now integrate the equivalent flux state Q = a² E D'. The initial value Q_i = a_i³ E(a_i) stays live for AD, and D' = Q/(a² E) is recovered on output. The compatibility growth_ode_system entry point still uses (D, D').
  • Masked gradients. Invalid Neff or masses still return NaN. Nested calls now get a finite placeholder before any reciprocal, square root or distance transform, so masking out invalid batch entries no longer turns valid shared-parameter gradients into NaN.
  • B-spline endpoints. Derivatives at endpoint equality now use the interior polynomial. Outside the range, clamp/zero modes give zero query derivatives. Sites are validated, and there is a dense-workspace guard.
  • Growth domain. Growth rejects queries outside the integration interval 1/139 ≤ a ≤ 1.01 instead of relying on solver-specific out-of-range saveat behaviour. Distances and backgrounds are not restricted.

Compatibility and physics notes

  • Explicit mass vectors now mean exactly three physical masses in eV, zeros included. They replace the previous naive vector sum, so previous vector-path outputs can change.
  • Variable Neff requires the three-mass path. The two presets are explicit models, not CAMB's default hybrid prescription.
  • species="m" adds ρν(masses) − ρν(massless reference) at the same thermal model. It is neither ρν − 3pν nor scale-dependent total-matter perturbation growth.
  • The flux formulation changes scalar growth at the default-solver tolerance level: up to about 2e-6 in D and f versus the pre-flux code at default reltol=1e-6, according to the parent's drift log. The current scalar path is not claimed to be bitwise identical to v0.7.0. Accuracy is established against the independent oracle below.
  • Trained emulator inputs are unchanged. No datasets were regenerated and no emulators were retrained.

Validation

Immutable evidence. Historical scalar, CLASS and Julia fixtures are byte-for-byte unchanged; the independent review compared all nine existing data files. New references were added alongside them, not substituted.

Original-equation oracle. A NumPy/SciPy solve of the original (D, D') state calls neither JAX nor Diffrax. It restarts DOP853 at every Akima knot and uses a complex step for mass sensitivities. It covers 48 rows: six redshifts, both sources, two cosmologies. The independent reviewer recomputed every row. Production D, f and both mass sensitivities are tested against it (tests/test_growth_dispatch.py).

Test counts. All were run locally at 20a0712; the CI links are listed below.

Run Result Who ran it
Full suite, locked stack (JAX/jaxlib 0.6.2, Diffrax 0.7.0, quadax 0.2.13) 320 passed parent local run; reproduced by the independent reviewer
Focused suites, older stack (JAX 0.4.38, quadax 0.2.11) 36 passed (parent); 67 passed (reviewer, broader subset) older-stack runs were focused, not full
Strict MkDocs build passed requires the workflow's doc-plot generation step first
Convergence report (scripts/scalar_growth_convergence.py) all 48 rows reproduced by the reviewer

Current-head CI at 20a0712: all 19 checks reported SUCCESS at snapshot 2026-10-04 21:35 UTC.

Performance (separate from correctness)

  1. JAX scalar reverse-mode growth tradeoff (this PR). With the flux formulation, scalar growth reverse mode cost about 10–15% more in the parent's paired local runs. The independent reviewer measured about 3% in a reversed-order repetition. Both runs were on the same shared laptop, so the size is host- and run-dependent. Previous default reverse gradients were less accurate, so this is an accuracy/cost tradeoff and needs explicit maintainer acceptance. At equal tolerances, three-mass growth and the unprepared long-grid spline path became faster; the prepared spline plan stayed roughly flat.

  2. Julia Zygote regression (ACE #100 only). Covered in that PR:

    • distances: an uncommitted local follow-up exists, pending verification;
    • growth: an unresolved residual remains.

    It does not affect jaxace. Neither PR makes a blanket "no performance regression" claim.

Deferred, not part of this release: a banded/local B-spline construction (R9). Dense construction keeps its documented guards.

marcobonici and others added 8 commits August 8, 2026 13:28
Add Julia-compatible not-a-knot cubic B-splines, prepared objects, and dense
fixed-grid plans with JIT and reverse-mode support. Validate the translation
against committed Julia fixtures at production shapes, add synchronized
benchmarks and documentation, and prepare the 0.8.0 release version.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
growth_solver/D_z/f_z/D_f_z (and the w0waCDMCosmology wrappers) gain a
`species` selector for the growth-equation source term:

- "cb" (default, unchanged behaviour): sources growth with Ωm_a, the
  cold+baryon density only (Effort.jl convention; correct for the growth
  of the field that sources galaxy RSD).
- "m": sources growth with the new Ωm_a_total = Ω_cb(a) + Ω_ν,massive(a),
  appropriate for scaling the total matter power spectrum P_mm (e.g. the
  high-z tails that source CMB lensing).

Ω_ν,massive(a) is built from the package's actual Fermi-Dirac-integral
neutrino density ΩνE2(a) (the same function used in E_a/dlogEdloga), as
ΩνE2(a; mν) - ΩνE2(a; 0). The subtraction of the massless baseline is
necessary: with N_eff massless neutrinos, ΩνE2(a; mν=0) is not zero -- it
is the (nonzero) purely relativistic neutrino radiation density, its own
separate ∝a^-4 term in E(a)^2, not matter at any epoch. Subtracting it
isolates the density genuinely attributable to nonzero neutrino mass, so
it vanishes identically at mν=0 (species="m" then degenerates exactly to
species="cb", as required) and grows into the true non-relativistic
ρν(a)∝a^-3 once a drops below the transition z_nr ≈ 110(Σmν/0.06eV).

species is a static string threaded through jax.jit via static_argnames
(new to this module) and closed over -- not passed through diffrax's
traced ODE `args` -- inside growth_solver's odefunc. All new parameters
are appended after existing ones with defaults reproducing the exact
pre-existing behaviour, so every existing call site is unaffected.

Neither prescription is exact for a free-streaming species; both source
terms carry O(f_nu) residuals relative to a full multi-fluid growth
calculation.
Adds TestGrowthSpeciesPrescriptions:
- default species="cb" is bit-identical to omitting the kwarg
- Ωm_a_total reduces to Ωm_a exactly at mν=0
- species="m" degenerates exactly to species="cb" at mν=0 across
  cosmologies including w0/wa != (-1, 0) and Ωk0 != 0
- at Σmν=0.06eV, D_m(z) is larger than D_cb(z) at every z (more source ->
  more accumulated growth), while the *normalized* ratio D(z)/D(z=0) is
  smaller for "m" than "cb" at every z>0 by an O(f_nu) fraction (reasoning
  for the sign is in the test docstring; verified numerically first)
- species="m" is jit-compilable and differentiable w.r.t. mν and h

The mν-gradient is checked for finiteness only, not against a finite
difference. Investigated directly: reverse-mode AD through diffrax's
adjoint disagrees with a well-converged finite difference by a real,
non-shrinking relative offset (0.02-6%, worst near a mν where dD/dmν
passes through zero) whenever the adaptive PIDController is used, but
matches to ~1e-6 with a fixed-step solver -- i.e. this is a known
adjoint/adaptive-step-control interaction, already present on the
pre-existing species="cb" path, not a bug introduced here. It's
presumably why the repo's own AD-vs-FD regression test fixes mν=0 and
never differentiates w.r.t. it. dD/dh is unaffected and is FD-checked
tightly.
Preserve scalar predictions and subtract the full massless species reference in the matter-source approximation.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Keep the scalar convention stable, propagate thermal models through distances and growth, and validate both source prescriptions against saved CLASS and Julia primal/gradient fixtures.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
The original and refactored implementations agree exactly under CI dependencies; preserve the frozen references while allowing their measured cross-version numerical drift.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.21448% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.50%. Comparing base (018cf74) to head (d874443).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
jaxace/_bspline.py 96.23% 11 Missing ⚠️
jaxace/_bspline_banded.py 96.64% 5 Missing ⚠️
jaxace/background.py 98.36% 3 Missing ⚠️
jaxace/_neutrinos.py 98.78% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #57      +/-   ##
==========================================
+ Coverage   88.53%   92.50%   +3.96%     
==========================================
  Files           5        8       +3     
  Lines        1317     1760     +443     
==========================================
+ Hits         1166     1628     +462     
+ Misses        151      132      -19     
Files with missing lines Coverage Δ
jaxace/core.py 92.92% <100.00%> (+1.46%) ⬆️
jaxace/initialization.py 95.80% <100.00%> (ø)
jaxace/utils.py 83.15% <100.00%> (-0.22%) ⬇️
jaxace/_neutrinos.py 98.78% <98.78%> (ø)
jaxace/background.py 96.41% <98.36%> (+6.10%) ⬆️
jaxace/_bspline_banded.py 96.64% <96.64%> (ø)
jaxace/_bspline.py 96.23% <96.23%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 018cf74...d874443. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

marcobonici and others added 3 commits October 4, 2026 12:32
…ties

Sanitize invalid thermal models before arithmetic, preserve endpoint polynomial derivatives, and validate equivalent flux growth against independent Julia references.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
… oracle

Preserve knot-restarted complex-step D/f references and convergence tables, and cover masked growth, non-polynomial spline endpoints and exact domain boundaries.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Sanitize invalid thermal models before their background coefficients multiply the shared ODE state, and mask only the final RHS. Cover both growth sources and thermal prescriptions with state and cosmology gradient regressions.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
@marcobonici

Copy link
Copy Markdown
Member Author

Independent Computer Scientist review found a remaining masked-gradient failure in the public compatibility growth_ode_system: an invalid thermal model in a masked batch could still poison reverse gradients of the shared ODE state.

Fixed in a87ab3a: sanitize thermal inputs before calling the existing RHS, and mark invalid outputs only at the public boundary. The production flux solver and valid-model equations are unchanged.

Validation:

  • The new regression failed in all four source/prescription combinations before the fix and passes afterward.
  • Tests cover six invalid mass/Neff cases per combination, eager/JIT reverse-mode Jacobians, and all 12 shared state/cosmology inputs against valid-only forward-mode derivatives.
  • 324 tracked tests passed on JAX 0.6.2 / quadax 0.2.13; unrelated local untracked tests are excluded.
  • Twenty additional valid scalar/vector cases retain exact forward values and state Jacobians against the unchanged numerical RHS.

The same independent reviewer has been asked to verify this pushed head while completing the paired ACE/jaxace review. New-head CI is running. No merge or release is authorized.

@marcobonici

Copy link
Copy Markdown
Member Author

Independent Computer Scientist follow-up: correctness approved at a87ab3a. The original masked-state-gradient reproduction now passes all four source/prescription combinations. Reviewer independently ran all 324 tests from an exact clean archive and checked the original-state oracle and nonuniform spline/derivative comparisons. Previously disclosed scalar-growth AD performance tradeoffs are NOT implicitly accepted by this correctness verdict; maintainer acceptance remains separate. Current-head CI is tracked separately. PR stays open and unmerged.

…PIs.

Retire the scalar model and its quadrature tables so Neff derivatives use one physical prescription. Keep emulator total-mass inputs unchanged and add rejection, constructor-AD, default-radiation, and migration coverage.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
@marcobonici

Copy link
Copy Markdown
Member Author

Pushed 368596b for Marco’s approved breaking API change: analytic backgrounds/growth and cosmology constructors now require exactly three physical neutrino masses. Scalars, including zero and traced scalars, raise migration errors; no total-mass splitting is implicit. Omitted masses mean the explicit massless triple. Neural-emulator total-mass inputs and artifacts remain unchanged.

Removed the obsolete scalar density/lookup implementation and its now-unused production quadax dependency. Every other locked package is unchanged; poetry check --lock passes. Existing three-mass numerical references are retained; scalar-era references are historical, not reinterpreted as the new model.

Independent local validation: 144 focused tests, 3 final targeted gradient/radiation checks, and 326 full-suite tests passed. Benchmark entrypoints run, but laptop temperatures made timing comparisons invalid, so no performance claim. Fresh CI is running. The Julia counterpart is still completing validation; no merge or release performed.

@marcobonici

Copy link
Copy Markdown
Member Author

Functional-scope audit after ACE #97 merged into develop (ACE c5f9ca0; this PR remains at 368596b):

The high-level not-a-knot cubic B-spline interfaces are present: one-shot interpolation, CubicBSpline, CubicBSplinePlan, vector/matrix values, scalar/vector spline queries, extrapolation policies, JIT and differentiation. This is not complete Julia public-API parity: the exported custom-basis object, knot/domain/support accessors, basis_row/stencil/matrix, and plan-based bspline_coefficients/bspline_basis interfaces do not have public JAX equivalents here. The spline object does expose its coefficients and knots as fields.

The pushed implementation is still dense construction plus dense prepared operators (512 MiB workspace estimate / 64 MiB operator guards). Native Julia plans use band factorizations and four-entry query stencils; the dense JAX plan is closer to the Julia Reactant plan strategy. The local banded-construction candidate is uncommitted and therefore not part of this PR. That candidate retains dense query evaluation/operator application, so publishing it alone would not deliver complete native-Julia scaling or low-level API parity.

Bounded execution check today loaded this PR’s committed utils.py directly, bypassing modified working-tree code, on JAX 0.4.38. All three forward interfaces matched existing saved Julia references at N=4,5,6,8,81 with rtol=atol=1e-12. Coefficient-loss value/site gradients were finite and agreed with those saved Julia gradients to maximum absolute differences of about 1.34e-15 / 1.31e-14 across these cases. Reused JIT plan construction/application and live value/site/query gradients also passed the bounded check. Reference provenance is Julia 132a6e5 plus recorded local source hashes, not a fresh full-suite run of the exact merged tree. No new universal performance or conditioning guarantee is implied.

ACE release PR100’s description has been updated to reflect the merged B-splines and removed scalar-neutrino mode. This audit does not merge either release PR or publish the local banded candidate.

marcobonici and others added 12 commits October 26, 2026 21:52
Replace dense interpolation paths with local stencils and banded solves while preserving live geometry derivatives. Include frozen references, CPU/GPU correctness coverage, and the unresolved performance caveat.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Add independent regression checks and eager preparation benchmark coverage while keeping performance acceptance explicit.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
…s reproducible.

Use cancellation-aware precision references and synchronized benchmark reports instead of random relative-error failures and shared-runner deadlines.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Keep user documentation and fixture provenance; historical reports remain in Git history.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Add reference and AD regression tests, clarify background and growth conventions, and credit Gerrit Farren.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Keep generators in git while restoring checksum-verified reference data for local tests and cached CI runs.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
…computation.

Drop the near-zero constant branch, use the integer radiation power, simplify identical normalization paths, and record numerical and measured performance validation.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
… using externally hosted figures.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
…nstant navigation.

Clarify naming, validation scope and figure reproducibility.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Preserve fixed masses and existing defaults while selecting cooling below Neff=3.044 and radiation at or above it. Validate JIT and gradient reuse across the switch, vector queries, invalid-input masking, and independent CLASS background fixtures.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Keep generated references out of git and verify complete empty-checkout restoration, including hybrid data, through the normal test bootstrap. Preserve checksum validation and offline reuse without executing archived generators.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Match the cached directory to the artifact tree used by the downloader so subsequent runs can reuse the verified Zenodo archive.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
marcobonici and others added 7 commits November 16, 2026 12:12
Reuse banded-spline and masked-gradient callables, remove duplicate dtype and source-layout checks, and publish per-test timing diagnostics for CI comparisons.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Use the shared physics-based dictionary keys, expose the thermal prescription in model metadata, and document registry lookup. Pin the published Zenodo archives and test the eleven-output contract.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Select temperature rescaling below Neff=3.044 and the radiation branch at and above the switch. Retain both explicit prescriptions and test the omitted setting on both sides and at equality.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
…ut precision.

Document the changed input ordering and eleven outputs, and cover the radiation-side derivative at the represented threshold in both float precisions.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Preserve invalid-input masking in the growth solver. Read the next layer offset from the unpacker rather than building an array of the same offsets.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Use the analytic series in Ωk r² for first and higher derivatives near flatness. Preserve primal distances and the public API. Correct the open/closed geometry labels and exercise both precisions and the public distance Hessian.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>
Retain the Hermite grid, runtime lookup and total node count. Check the
table against independent adaptive quadrature and document initialization
and automatic emulator postprocessing.

👾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta Code <noreply@letta.com>

This branch has not been deployed

No deployments
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.

2 participants