fix(thermo): n_H_0 should use hydrogen atom mass, not proton mass - #18
Open
MinhMPA wants to merge 2 commits into
Open
fix(thermo): n_H_0 should use hydrogen atom mass, not proton mass#18MinhMPA wants to merge 2 commits into
MinhMPA wants to merge 2 commits into
Conversation
The tau_reio bisection in `_find_z_reio` computes n_H_0 with the proton mass m_p = 1.672621637e-27 kg. CLASS uses the hydrogen atom mass m_H = 1.673575e-27 kg (thermodynamics.c:812, also _m_H_ in thermodynamics.h). clax's RECFAST block (line 534) already uses m_H = 1.67353284e-24 g correctly; this commit makes the tau_reio site consistent. m_H/m_p = 1.000570 -> n_H_0 was 0.057% too large -> tau_reio_for_zreio overshot the target -> bisection converged to a z_reio that was too low. Empirical impact at Planck 2018 fiducial: - z_reio offset (clax vs CLASS reference): 0.00335 -> 0.00033 (10x). - x_e at z=8 (steepest part of reion transition): -1.1% -> -0.11%. - g(tau) at the secondary visibility peak: -1.0% -> -0.11%. - g(tau) at the recombination peak (z=1090): unchanged at +0.002%. This was misattributed in the README "Known limitations" as "EE l=20-30: ~0.2% from RECFAST visibility function bias. HyRec recombination would improve to sub-0.1%." In fact: - RECFAST physics is fine (clax/RECFAST x_e and HyRec agree to 0.09% at the recombination peak z=1090). - The 0.2% EE l=20-30 bias is dominantly this tau_reio inversion bug, upstream of recombination physics. HyRec would not have fixed it because the wrong z_reio would still be passed downstream. Adds m_H_kg = 1.67353284e-27 to clax/constants.py so future call sites cannot drift apart from the recombination-block value. Validation: - pytest tests/test_thermodynamics.py: 9/9 pass. - z_reio, x_e, g(tau) match CLASS reference at the levels above. - Background, harmonic, lensing test suites: unchanged at the level this fix could affect them (n_H_0 shifted by 0.057%, recombination peak visibility unchanged); a full CI run is recommended.
3 tasks
Documents the one-line tau_reio → z_reio inversion fix from this PR, the empirical impact at Planck 2018 (z_reio 7.6885 → 7.6915, x_e(z=8) -1.06% → -0.11%, EE l=20-30 residual ~1% → <0.1%), and the README "Known limitations" line that should be reassessed in a follow-up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a one-line bug in
clax/thermodynamics.pythat biased thetau_reio→z_reioinversion at fiducial Planck. Then_H_0calculation used the proton massm_pwhere it should have used the hydrogen atom massm_H.CLASS uses
_m_H_ = 1.673575e-27 kgatthermodynamics.c:812. clax's RECFAST block (line 534) already usesm_H = 1.67353284e-27 kgcorrectly. Only thetau_reioinversion site (line 710) was usingm_p; this PR restores consistency.Why it matters
m_H / m_p = 1.000570→ clax'sn_H_0was 0.057% too large at this site →_tau_reio_for_zreioovershot the target by 0.057% → bisection converged to az_reiothat was too low (clax 7.6885 vs CLASS 7.6918).That 0.0033 absolute offset in
z_reiotranslates to ~1% systematic inx_eacross the reionization transition (z=7-9) and ~1% ing(τ)at the secondary visibility peak — propagating to most of the EE ℓ=20-30 residual the README has been attributing to "RECFAST visibility function bias".Empirical impact at Planck 2018 fiducial
z_reio(tau_reio = 0.0544)x_e(z=8)g(τ)at z=8g(τ)at z=1090 (recomb peak)The fix closes 90% of the
z_reiooffset. The remaining ~3e-4 absolute residual is from the small numerical difference between clax'sm_H = 1.67353284e-27 kg(atomic mass of 1H-1) and CLASS's_m_H_ = 1.673575e-27 kg(rounded value); both agree to 2.5e-5 relative, well below any current accuracy target.Changes
clax/constants.py: addm_H_kg = 1.67353284e-27constant with a comment flagging thatm_pis not the right choice here.clax/thermodynamics.py:710: replace local_m_pwithconst.m_H_kgin then_H_0formula used by_find_z_reio.Diff is +13 / -2 across 2 files.
Note on README "Known limitations" framing
The README currently says:
This is misleading. Empirically (separate investigation, see
docs/hyrex_integration_assessment.mdoninvestigate-hyrex-integrationbranch):x_eand HyRec agree to 0.09% at z=1090 (the recombination peak where the visibility function lives). RECFAST physics is fine.n_H_0bug, upstream of recombination in thetau_reioinversion. HyRec/HyRex would not have fixed it because the wrongz_reiowould still be passed downstream.After this PR lands, the EE ℓ=20-30 limitation should be reassessed — expect the residual to drop to <0.05%. A follow-up README update is recommended but left out of this PR to keep the change focused.
Test plan
pytest tests/test_thermodynamics.py -v— 9/9 passpytest tests/test_background.py tests/test_harmonic.py tests/test_lensing.py -v --fast— 37/37 pass (15 background + 11 harmonic + 11 lensing)Independence from other open PRs
clax/thermodynamics.pyorclax/constants.py.