Repository navigation
refactor(core): consistent call conventions in the mass-definition modules - #445
Conversation
…dules - Keyword-only m, r, z, x, c and omega_m_z in the public and *_kernel methods of mass_definitions, concentration, mass_conversion and profiles. - Rename MassDefinition.m_to_r / r_to_m (and their kernels) to radius_from_m / m_from_radius, as in MassVariance and MassFunction. - One calibration-domain API: the Calibrated mixin in hmf.core.domain gives every kind with calibration ranges (fits, concentration, profiles, filters, transfer and growth models) an instance property `calibration`, defaulting to the class's calibration_domain. Duffy08 overrides it per redshift range; evaluate_fsigma and the fits use it. - Rename FittingFunction.in_calibration_domain to in_calibration_domain_kernel; it checks the valid domain, like every kernel. - Remove the NFW kernels only the tests used (nfw_ln_mu, nfw_ln_mu_slope, nfw_concentration_ratio_solve, nfw_convert); the tests go through NFW(). - MassDefinition.from_name parses SOGeneric names, and names write numbers that :g would round in full, so every name round-trips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019U8u424ZT3yjRFWgUZTC2n
|
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 4 days and 5 hours by commenting |
Reviewer's GuideData structuresIntroduce the
Make concentration, fits, filters and density profiles calibrated model kinds, and route instance calibration checks and fit evaluation through
Make mass-definition names round-trip precisely, including parsing valid
APIStandardize public and kernel call signatures on keyword-only operation inputs, and rename mass-radius operations for clarity.
Rename the fit calibration check to its kernel API, validate inputs against the valid domain, and remove unused low-level NFW conversion entry points.
Uses of the APIUpdate internal consumers to pass renamed operation arguments by keyword and to use the profile conversion API and instance calibration checks.
Update the regression provider to call the mass-definition kernel with its keyword-only argument.
ImplementationImplement the shared NFW profile calculations through combined log-mass-and-slope evaluation and adjust their kernel documentation and exports.
DocumentationRevise core and model documentation to describe instance calibration and the renamed mass-radius and profile conversion APIs.
TestsExercise calibration inheritance and instance-specific behavior, keyword-only APIs, name round-trips, and profile-backed conversion behavior.
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 #445 +/- ##
==========================================
- Coverage 99.70% 99.70% -0.01%
==========================================
Files 69 69
Lines 9537 9536 -1
==========================================
- Hits 9509 9508 -1
Misses 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Makes the mass-definition, concentration, conversion and profile modules of
hmf.corecall the same way asMassFunctionandLinearPower: keyword-only arguments, one name per operation, one calibration-domain API. These modules are unreleased and experimental, so there are no deprecation aliases. Results are bit-identical.Renames and signature changes (old → new)
hmf.core.mass_definitions.MassDefinitionm_to_r(m, *, omega_m_z, rho_mean0)radius_from_m(*, m, omega_m_z, rho_mean0)r_to_m(r, *, omega_m_z, rho_mean0)m_from_radius(*, r, omega_m_z, rho_mean0)m_to_r_kernel(m, *, omega_m_z, rho_mean0)radius_from_m_kernel(*, m, omega_m_z, rho_mean0)r_to_m_kernel(r, *, omega_m_z, rho_mean0)m_from_radius_kernel(*, r, omega_m_z, rho_mean0)delta_halo_mean(omega_m_z)delta_halo_mean(*, omega_m_z)delta_halo_mean_kernel(omega_m_z)delta_halo_mean_kernel(*, omega_m_z)hmf.core.concentration.ConcentrationModelconcentration(m, *, z)concentration(*, m, z)ln_concentration_and_slope_kernel(m, *, z)ln_concentration_and_slope_kernel(*, m, z)in_calibration_domain_kernel(m, *, z)in_calibration_domain_kernel(*, m, z)hmf.core.mass_conversion.MassConversionconvert(m, *, z, omega_m_z, source, target)convert(*, m, z, omega_m_z, source, target)convert_kernel(m, *, z, omega_m_z, source, target)convert_kernel(*, m, z, omega_m_z, source, target)hmf.core.profiles.DensityProfilemu(x)mu(*, x)ln_mu_and_slope_kernel(x)ln_mu_and_slope_kernel(*, x)convert_concentration_kernel(c, *, slope, ln_q)convert_concentration_kernel(*, c, slope, ln_q)hmf.core.fits.FittingFunctionin_calibration_domain(x)in_calibration_domain_kernel(x). It now checksxagainstvalid_domain(raisingDomainError), like every other*_kernel.evaluate_fsigmadoesn't repeat that check, becausefsigma_kernelhas already done it.xstays positional here, to matchfsigma_kernel(x): it's aFitInputsbundle, not an array.The calibration-domain API
hmf.core.domain.Calibratedis a mixin with empty__slots__. Every model kind with calibration ranges now uses it:FittingFunction,ConcentrationModel,DensityProfile,Filter, andTransferModel/GrowthModel(through_CosmologyModel).model.calibration(instance property) is the API. It gives where this instance was calibrated, orNoneif it wasn't.cls.calibration_domain(class variable) is the calibration of the class's default parameters, andcalibrationreturns it unless the model overrides it.Duffy08.calibrationgives z = 0 forredshifts="0", whileDuffy08.calibration_domainstays the z = 0–2 default.FittingFunction.in_calibration_domain_kernel,evaluate_fsigma,ConcentrationModel.in_calibration_domain_kernelandProfileConversionall readcalibration. A fit whose calibration depends on its parameters is masked by its own range (tested).concentration,fitsanddomainmodule docs,docs/core.rst(one sentence in "Domains") and the model-class doc template now point tocalibration.Removed kernels
hmf.core._kernels.mass_conversion:nfw_ln_mu,nfw_ln_mu_slope,nfw_concentration_ratio_solve,nfw_convert. The library didn't use them. Their physical tests (closed form and series, ψ against a numerical derivative, round-off residual of the solve over 1e-3 < c < 1e4 and 1e-4 < q < 1e4, batch independence, the exact identity at q = 1, agreement with the v3 brentq solve, the Hu & Kravtsov accuracy, the Jacobian against a finite difference) now run throughNFW().ln_mu_and_slope_kernelandNFW().convert_concentration_kernel.nfw_ln_mean_densityandhu_kravtsov_inversestay, becausenfw_startuses them.SOGenericnames round-tripMassDefinition.from_nameparses"so(preferred <name>)".ValueErrorwhen the preferred definition isn't anSOMean,SOCriticalorSOVirial.:gwould round it. Before,SOMean(18 pi^2).namewas"177.653m", which read back as a different definition. Names that were already exact ("200m","500c","fof(b=0.2)", …) don't change.Call sites
mass_function.py: four one-line changes (m=m,omega_m_z=omega_m_z, and twoin_calibration_domain_kernelcalls).tests/regression/v4_providers.py: one keyword.Checks
uv run pytest tests/core tests/regression: 2319 passed, 11 skipped. Every touchedhmf.corefile is at 100% coverage. The global 95% gate counts v3 code, so it needs the full suite.uv run pytest benchmarks/test_gates.py: 25 passed.uv run mypy: clean.uv run prek run --files …: clean.sphinx-build -W --keep-going: succeeded.Type of change
Checklist
I have
Generated by Claude Code
Summary by Sourcery
Standardize experimental core model interfaces and calibration-domain handling while consolidating profile kernels and preserving existing numerical results.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests:
Chores: