py-SP(k) Model - #194
Conversation
…ize test structure
…sion calculations
…erage unignore and add SPk_demo.ipynb to the repo add an end-to-end SP(k) demo comparing CAMB vs pyspk with relative-error diagnostics make SP(k) unit references more stable with dense transfer sampling (k_per_logint=100) tighten relation-match tolerances to 1e-6 / 1e-9 add a high-k boundary continuity regression test (k <= 12) to prevent cutoff artifacts
- Introduced warnings for redshift values outside the calibrated range, notifying users when SP(k) calculations are skipped. - Added clamping warnings for input k values exceeding the calibrated maximum, ensuring users are informed when values are adjusted. - Implemented logical flags to prevent repeated warnings during execution.
|
Hi @cmbant , This PR is ready for review. Could you please assign some reviewers? Thanks! |
|
Any chance this is reviewed @cmbant? |
|
Odd, thought I'd add least added a comment. |
…ible cosmology objects
…dev dependencies in pyproject.toml
Thanks @cmbant !. The changes in .vscode and camb_test came from development/testing while I was iterating on the implementation, but I’ve cleaned those up in the latest revision. And yes, the |
|
AI review: The SP(k) integration builds cleanly, and the in-range power-law suppression matches
|
… limit calculations in SPkNonLinear
…e for detailed guidance
|
Thanks @cmbant, these comments should now be addressed. The SP(k) implementation now reproduces the reference pyspk fitting-limit behaviour. In particular, the baryon-fraction limits are computed from the calibrated tables and any out-of-range points are set to NaN, with a one-time warning emitted when encountered. This avoids invalid parameter combinations. I also added full write_ini() support for SPkNonLinear, together with regression coverage in the Python test suite. I also updated the documentation to clarify the calibrated validity domain, boundary behaviour, NaN propagation, and MCMC/Cobaya implications, including guidance on using the interpolator interface for reliable NaN detection. |
|
AI followup: P1 fortran/spk_model.f90 (line 94): SPk_GetFbLimits uses linear interpolation for the fitting-limit coefficients, but the reference pyspk implementation uses Akima1DInterpolator for each coefficient before computing min_fb/max_fb (pyspk source). Since those limits decide whether fortran/SPkNonLinear.f90 (line 182) returns finite suppression or NaN, CAMB can accept/reject the wrong parameter points at off-node redshifts. The current NaN test uses z=0.5, which is a table node, so it would not catch this. |
…r spectra comparison
|
I replaced the linear interpolation with Akima for the limit coefficients. I checked this, and the discrepancy was ≤1% for z < 1 (absorbed by the 20% safety margin) but grew to ~20% at z = 2.5. Now matches pyspk exactly at all redshifts. I also added an off-node-z test to prevent regression. I updated the documentation to clarify interpolation guidance and NaN preservation. |
|
AI review (may be intentional, but ini inconsistency ma be real?): Medium — SPkNonLinear.set_params() cannot configure the wrapped Halofit model except for halofit_version, so common CAMB/HMCode options become unusable through the standard API. |
Good point. Originally I intended to keep this independent, but yes, the three HMCode parameters were being silently reset to defaults on every I added all three to the signature (matching I updated the docstring and |
|
For the next CAMB version AI tools made some optimizations/restructuring of your changes let me know if you think any issues: |
Hi @cmbant, Looks good to me. I've verified the changes against master by building both commits and comparing the SPK suppression ratio on the raw internal k-grid (using The changes make sense. Happy with this. |
Overview
This PR implements the SP(k) baryon-suppression model (Salcido et al. 2023) in CAMB.
Model references:
What is implemented
1. SP(k) non-linear wrapper
fortran/SPkNonLinear.f90wraps a base non-linear model (e.g. HMCode/halofit) and applies SP(k) suppression multiplicatively.zrange, SP(k) correction is skippedkabove calibrated limit, suppression evaluation is clamped at calibratedk_maxFeedbackLevel > 0) are emitted for both out-of-range behaviors.2. Python API path and integration coverage
camb/tests/camb_test.pyincludes coverage thatset_classes(non_linear_model="SPkNonLinear")selects and runs correctly.3. Dedicated SP(k) validation tests
camb/tests/spk_test.pyadds dedicated SP(k) tests.pyspkacross supported relation modes.4. SP(k) demo notebook
Supporting updates
pyproject.toml: addspyspk>=2.0.0to dev extras for validation workflows.Validation run
python -m unittest camb.tests.spk_testReviewer notes
pyspkimplementation.