Repository navigation
refactor(core): CDM+baryon mass radius, one KAccuracy, sigma(R) kernels, stage domains - #421
steven-murray wants to merge 3 commits into
Conversation
…l arguments _wrap_many converted every dimensional argument through _convert_argument and finished every output through _finish. It now takes the same fast paths as _wrap_one: an argument that is a plain Quantity in exactly its canonical unit is viewed as an ndarray, and a plain ndarray output gets its unit inline. The units-boundary gate in benchmarks/test_gates.py now also measures a method with two dimensional arguments: 2.64 µs per call before, 1.81 µs after (budget 2 µs; the one-argument wrapper measures 1.30 µs on the same machine). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MuqUZzdEaJGwATE9r1ELXo
Growth gains a k_accuracy field (default KAccuracy()), which the CAMB and CLASS growth models use for a run they make themselves, so KAccuracy.high() refines those runs as it does the transfer stage's. Growth.from_transfer takes the transfer stage's k_accuracy, and a growth stage shares its transfer stage's run only when their accuracies are equal. accuracy.py documents which KAccuracy settings each stage reads, and the rule that a composing stage passes one KAccuracy to all of them; check_consistent() checks it (ValueError on a mismatch), for the coming LinearPower stage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MuqUZzdEaJGwATE9r1ELXo
* A PowerSource's rho_mean0 is the mean density of CDM + baryons, whatever the species of its power: Transfer's power source returns rho_mean0(cosmology, "cb") for "tot" too, so R(M) matches v3 and the fits' calibrations. TabulatedPower documents its mean_density as CDM + baryons. * MassVariance.ln_sigma_at_radius_kernel: sigma at filter radii (Mpc/h), evaluated directly with the stage's filter and power, without the lattice (for sigma_8). It agrees with the lattice to INTERPOLATION_RTOL (1e-5). * MassVariance.m_from_radius_kernel, radius_from_m_kernel and m_from_sigma_kernel, the kernel-level counterparts of the public converters. * MassVariance and TabulatedPower have an instance-level valid_domain (the lattice with mass_accuracy.extension="raise", the table with extension="raise"). Their public methods check it with Domain.check and their kernels with check_extent, so every stage reports out-of-domain input the same way. m_from_radius and radius_from_m now reject masses and radii that are not finite and > 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MuqUZzdEaJGwATE9r1ELXo
|
Sorry @steven-murray, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 2 days and 18 hours by commenting |
Reviewer's GuideThis PR refactors core stage composition around a single KAccuracy, makes all mass–radius conversions use CDM+baryon density, adds direct MassVariance kernels and explicit stage domains, and unifies unit-boundary handling with multi-argument performance coverage; documentation and extensive physical, domain, numerical, and regression tests are updated accordingly. Sequence diagram for accuracy-aware growth constructionsequenceDiagram
participant Transfer
participant Growth
participant GrowthModel
participant Boltzmann
Transfer->>Growth: from_transfer(transfer)
Growth->>Growth: copy transfer.k_accuracy
Growth->>GrowthModel: solve(cosmology, k_accuracy)
alt matching backend and k_accuracy
GrowthModel->>Transfer: reuse boltzmann_run
Transfer-->>GrowthModel: shared run
else accuracy or backend differs
GrowthModel->>Boltzmann: run(cosmology, k_accuracy)
Boltzmann-->>GrowthModel: growth solution
end
Entity relationship diagram for CDM+baryon mass-radius mappingerDiagram
POWER_SOURCE {
float rho_mean0_cb
string species_power
}
MASS_VARIANCE {
float mass_assignment
float mass
float radius
}
POWER_SOURCE ||--|| MASS_VARIANCE : sets
MASS_VARIANCE }o--|| POWER_SOURCE : uses_rho_mean0_cb
Flow diagram for MassVariance radius and sigma kernelsflowchart LR
R[r > 0] --> S["ln_sigma_at_radius_kernel(r)"]
R --> M["m_from_radius_kernel(r)"]
Mv[m > 0] --> RR["radius_from_m_kernel(m)"]
Sv[sigma > 0] --> MS["m_from_sigma_kernel(sigma)"]
S --> D[Direct sigma integral on k grid]
M --> CB[CDM+baryon rho_mean0]
RR --> CB
S --> V[check_extent against valid_domain]
M --> V
RR --> V
MS --> V
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #421 +/- ##
=======================================
Coverage 99.57% 99.57%
=======================================
Files 59 59
Lines 7210 7279 +69
=======================================
+ Hits 7179 7248 +69
Misses 31 31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
The last decided changes to
hmf.corebeforeLinearPower(σ8, P(k, z)) andMassFunction. Neither stage is built here.hmf.coreis experimental, so there is no deprecation path.1. Mass ↔ radius always uses the CDM + baryon density
PowerSource.rho_mean0protocol is now defined as the CDM + baryon mean density, whatever species the power is.UnnormalisedPower.rho_mean0(fromTransfer.power_kernel(species)) returnsrho_mean0(cosmology, "cb")for"tot"too.TabulatedPower.mean_densityis documented as cb.power_source.py,transfer.py,mass_variance.py(new "Mass and radius" section) anddocs/core.rst."tot"and"cb"MassVariancegive bit-identical R(M);critical_density0 · Om0;2. One
KAccuracydrives the k-space calculationGrowth.k_accuracyis a new field (defaultKAccuracy()).GrowthModel.solvetakesk_accuracy, andCambGrowth/ClassGrowthuse it for their own runs instead of a hard-codedKAccuracy(). SoKAccuracy.high()now switches those runs to high precision.Growth.from_transferdefaultsk_accuracyto the transfer stage's.accuracy.check_consistent(first, *others):KAccuracy, or raisesValueErrorlisting each stage's;HasKAccuracyprotocol.accuracy.py(a table) anddocs/core.rstdocument which fields each stage reads, and the one-KAccuracyrule.LinearPowerwill own theKAccuracy.Which
KAccuracyfields each stage readsTransferdln_khigh_precision). Other models read nothing.Growthdln_kMassVariancedln_k,ln_k_min,k_max_r_minThe effect of each preset:
KAccuracy.high()refines the runs and the σ grid.fast()and the defaults leave the Boltzmann codes at their own precision.3. New kernels on
MassVarianceAll of these work in canonical units and check their input with
check_extentagainstvalid_domain.ln_sigma_at_radius_kernel(r)mass_accuracy.extensiondoes not apply. RaisesDomainErrorwhere the k grid can't resolve the integral, like the lattice. For σ8: a TopHatMassVarianceon the normalisation species at R = 8.m_from_radius_kernel(r)radius_from_m_kernel(m)m_from_sigma_kernel(sigma)m_from_sigma; the public method now calls it.INTERPOLATION_RTOL = 1e-5. It records the existing documented accuracy of the lattice interpolant against direct evaluation at default settings.ln_sigma_at_radius_kernelmatches the lattice σ toINTERPOLATION_RTOL, for EH and BAO spectra and all three filters. At lattice nodes they agree to 1e-13.4. Stage domains
MassVariance.valid_domainis instance-level:m: > 0, or the default lattice range whenmass_accuracy.extension="raise";randsigma: > 0.TabulatedPower.valid_domainis instance-level:k> 0, or the table's range (to round-off) whenextension="raise".Domain.check, kernels withcheck_extent. The ad-hoc checks (check_finite_positive/check_in_range/ the hand-written table and lattice errors) are gone. Messages and inf/NaN handling now match Transfer, Growth, the filters and the fits.m_from_radius/radius_from_mnow reject r or m that is not finite and > 0. They had no check before.wherestring still namesextension='raise'.5. Two-argument boundary benchmark gate
test_unit_boundary_overhead_gateis parametrised over one and two dimensional arguments._wrap_manynow takes_wrap_one's identity fast paths: it views canonical Quantities as ndarrays and finishes ndarray outputs inline._wrap_many)_wrap_one, unchanged, for reference)These numbers are from this container. The margin is ~10%. A specialised loop-free two-argument wrapper measured about 0.3 µs faster, but I kept the generic version.
What
LinearPower/MassFunctionwill callMassVariance(power=transfer.power_kernel(sigma_8_species), filter=TopHat(), k_accuracy=K).ln_sigma_at_radius_kernel(8.0)accuracy.check_consistent(transfer, growth, mass_variance)(LinearPower ownsK)Transfer.power_kernel(species).ln_power_kernel(ln_k)(being renamed topower_sourcein #parallel)MassVariance.ln_sigma_and_slope_kernel(m)mass_variance.n_eff_kernel(dlnsigma_dlnm)MassVariance.m_from_sigma_kernel(sigma)MassVariance.m_from_radius_kernel(r),MassVariance.radius_from_m_kernel(m)power_source.rho_mean0(any species)Growth.growth_factor_kernel(z, species),Growth.growth_rate_kernel(z, species)_species.omega_m(cosmology, z, "cb")(becoming publicspeciesin the parallel PR)MeasuredMassDefinition.delta_halo_mean_kernel(omega_m_z)FittingFunction.fsigma_kernel(FitInputs(...))orfits.evaluate_fsigma(..., owner=self)FittingFunction.modify_dndm_kernel(...)Transfer/Growthmodelvalid_domain,MassVariance.valid_domain,TabulatedPower.valid_domain, fits'valid_domain/calibration_domainMassFunctionCoordination
This PR conflicts with
refactor/core-naming-visibilityon these names:power_kernel→power_source;_species→species;window_derivatives→window_derivatives_kernel.It will merge
origin/main(no rebase) and adopt the new names once that PR lands.Type of change
Checklist
I have
Checks run locally:
tests/core+tests/regression: 1835 passed;benchmarks/test_gates.py: 19 passed;-Werroron the touched test files;mypystrict: clean;prekon the changed files: clean;sphinx-build -W: clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01MuqUZzdEaJGwATE9r1ELXo
Generated by Claude Code
Summary by Sourcery
Standardize core k-space accuracy, CDM+baryon mass-radius conversions, kernel APIs, and domain validation across the calculation stages.
New Features:
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: