Skip to content

Conversation

@jordanflitter
Copy link
Contributor

This is a draft for the Lya multiple scattering branch.
There are now two new flags, called LYA_MULTIPLE_SCATTERING and TEST_SL_WITH_MS_FILTER, the latter becomes relevant only when the former is True, while the former is relevant only if USE_HALO_FIELD=True.
When LYA_MULTIPLE_SCATTERING=True, if TEST_SL_WITH_MS_FILTER=False, the code uses a modified window function that replaces the window function of Eq. (22) in Davies, Mesinger, Murray 2025 (it replaces only the window function that is applied on the SFRD, not the one that is applied on X-ray luminosity). It is a subtraction of two hypergeometric functions 2F3 (instead of a subtraction of two Bessel functions) where the parameters of 2F3, $\alpha$ and $\beta$, are determined by the current redshift $z$, the filter radius $R$ and the ionization fraction $x_\mathrm{HI}$. Unfortunately GSL doesn't support computing 2F3 so I had to come up with my own implementation, which works pretty well based on the tests that I made.
When LYA_MULTIPLE_SCATTERING=True, and TEST_SL_WITH_MS_FILTER=True, the code uses the same modified window function but with $\alpha\gg\beta$, as in this limit 2F3 approaches the Bessel function. This configuration should be used only as a sanity check that the new window function (multiple scattering = MS) yields the same output as the old one (straight line = SL) in the appropriate limit.
Currently, this branch is designed to work only when USE_MINI_HALOS=False. With mini-halos, the SFRD is also used for the Lyman-Werner feedback, but the applied filter should correspond to the old one (as LW photons travel in straight lines), which is not supported by the current implementation when LYA_MULTIPLE_SCATTERING=True. In the future, two new more fields in XraySourceBox (like filtered_sfr_lw and filtered_sfr_lw_mini) should be introduced in this setting (thereby increasing the amount of used memory), or alternatively we can throw an error when USE_MINI_HALOS and LYA_MULTIPLE_SCATTERING are both True.

@jordanflitter jordanflitter added the type: feature: physical New feature that adds new analysis/physical model label Jul 17, 2025
@github-actions
Copy link

github-actions bot commented Jul 17, 2025

🐰 Bencher Report

Branchmult_scatter
Testbedubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
seconds (s)
(Result Δ%)
Upper Boundary
seconds (s)
(Limit %)
tests/test_integration_features.py::test_power_spectra_lightcone[dexm]📈 view plot
🚷 view threshold
5.08 s
(+0.06%)Baseline: 5.08 s
5.59 s
(90.97%)
tests/test_integration_features.py::test_power_spectra_lightcone[fftw_wisdom]📈 view plot
🚷 view threshold
4.14 s
(-69.44%)Baseline: 13.54 s
14.89 s
(27.78%)
tests/test_integration_features.py::test_power_spectra_lightcone[fixed_halogrids]📈 view plot
🚷 view threshold
4.25 s
(+1.66%)Baseline: 4.18 s
4.60 s
(92.42%)
tests/test_integration_features.py::test_power_spectra_lightcone[inhomo]📈 view plot
🚷 view threshold
13.02 s
(-0.11%)Baseline: 13.03 s
14.34 s
(90.81%)
tests/test_integration_features.py::test_power_spectra_lightcone[inhomo_ts]📈 view plot
🚷 view threshold
24.72 s
(+1.21%)Baseline: 24.42 s
26.87 s
(92.01%)
tests/test_integration_features.py::test_power_spectra_lightcone[mini]📈 view plot
🚷 view threshold
72.67 s
(+1.98%)Baseline: 71.26 s
78.38 s
(92.71%)
tests/test_integration_features.py::test_power_spectra_lightcone[mini_gamma_approx]📈 view plot
🚷 view threshold
24.52 s
(+5.20%)Baseline: 23.30 s
25.64 s
(95.64%)
tests/test_integration_features.py::test_power_spectra_lightcone[minimize_mem]📈 view plot
🚷 view threshold
25.64 s
(+0.83%)Baseline: 25.42 s
27.97 s
(91.66%)
tests/test_integration_features.py::test_power_spectra_lightcone[no-mdz]📈 view plot
🚷 view threshold
3.68 s
(-0.41%)Baseline: 3.69 s
4.06 s
(90.54%)
tests/test_integration_features.py::test_power_spectra_lightcone[photoncons-z]📈 view plot
🚷 view threshold
36.33 s
(+0.87%)Baseline: 36.02 s
39.62 s
(91.70%)
tests/test_integration_features.py::test_power_spectra_lightcone[sampler]📈 view plot
🚷 view threshold
9.16 s
(+0.49%)Baseline: 9.11 s
10.02 s
(91.35%)
tests/test_integration_features.py::test_power_spectra_lightcone[sampler_hires]📈 view plot
🚷 view threshold
10.31 s
(+1.67%)Baseline: 10.14 s
11.15 s
(92.43%)
tests/test_integration_features.py::test_power_spectra_lightcone[sampler_ir]📈 view plot
🚷 view threshold
23.70 s
(-7.79%)Baseline: 25.70 s
28.27 s
(83.82%)
tests/test_integration_features.py::test_power_spectra_lightcone[sampler_mini]📈 view plot
🚷 view threshold
69.34 s
(+1.17%)Baseline: 68.54 s
75.39 s
(91.97%)
tests/test_integration_features.py::test_power_spectra_lightcone[sampler_noncubic]📈 view plot
🚷 view threshold
9.54 s
(+0.39%)Baseline: 9.50 s
10.45 s
(91.26%)
tests/test_integration_features.py::test_power_spectra_lightcone[sampler_ts]📈 view plot
🚷 view threshold
39.44 s
(-7.53%)Baseline: 42.65 s
46.91 s
(84.07%)
tests/test_integration_features.py::test_power_spectra_lightcone[sampler_ts_ir]📈 view plot
🚷 view threshold
41.48 s
(-6.32%)Baseline: 44.28 s
48.71 s
(85.17%)
tests/test_integration_features.py::test_power_spectra_lightcone[sampler_ts_ir_onethread]📈 view plot
🚷 view threshold
56.87 s
(-7.37%)Baseline: 61.40 s
67.54 s
(84.21%)
tests/test_integration_features.py::test_power_spectra_lightcone[simple]📈 view plot
🚷 view threshold
3.97 s
(-0.70%)Baseline: 4.00 s
4.40 s
(90.27%)
tests/test_integration_features.py::test_power_spectra_lightcone[ts]📈 view plot
🚷 view threshold
23.40 s
(+1.28%)Baseline: 23.10 s
25.41 s
(92.07%)
tests/test_integration_features.py::test_power_spectra_lightcone[ts_nomdz]📈 view plot
🚷 view threshold
21.34 s
(+1.68%)Baseline: 20.99 s
23.09 s
(92.44%)
🐰 View full continuous benchmarking report in Bencher

jordanflitter and others added 21 commits July 30, 2025 11:44
…d to introduce two new 4D arrays for LW flux as LW photons travel in straight lines). Also included USE_ADIABATIC_FLUCTUATIONS to allow the possibility to begin the simulation with homogeneous T_k
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 51.28205% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.68%. Comparing base (e02fc7f) to head (4140c03).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/py21cmfast/drivers/single_field.py 11.76% 13 Missing and 2 partials ⚠️
src/py21cmfast/wrapper/outputs.py 80.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #534      +/-   ##
==========================================
- Coverage   87.99%   87.68%   -0.32%     
==========================================
  Files          31       31              
  Lines        4556     4595      +39     
  Branches      773      781       +8     
==========================================
+ Hits         4009     4029      +20     
- Misses        388      403      +15     
- Partials      159      163       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature: physical New feature that adds new analysis/physical model

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants