21cmfast / 21cmFAST

Official repository for 21cmFAST: a code for generating fast simulations of the cosmological 21cm signal
MIT License
58 stars 37 forks source link

Stochasticity #349

Closed daviesje closed 5 months ago

daviesje commented 9 months ago

DRAFT PR FOR v4

This update focuses around two things:

The state of the halo model currently:

State of the C modularisation

Biggest Issues

MISC

review-notebook-app[bot] commented 7 months ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

daviesje commented 6 months ago

The last few commits have a lot of changes, I'm writing a summary here:

This set of commits mostly deals with the creation of tests for the sampler, most importantly the interpolation tables over the mass function (Nion, SFRD, inverse CMF) as well as the sampler itself. The interpolation tables are tested against the integrals, and the sampler is tested in bins against the UMF.

Making these tests required a reorganisation of the interpolation tables and mass integrals as follows:

daviesje commented 5 months ago

When the halo sampler is switched off, results very closely resemble the master branch, I have noticed only < 10^-3 level differences when examining global quantities and individual cells. However there seem to be bigger differences in various power spectra. Attached are paired lightcone and global plots for three cases, default parameters (titled _KS_OLD[_MASTER]), setting USE_MASS_DEPENDENT_ZETA=True (titled _KS[_MASTER]) and USE_MINI_HALOS=TRUE (titled _KSMINI[MASTER]).

lc_global

lc_slice

Most of the tests fail since the interpolation tables and integral structure has changed, causing floating point errors (some float -> double conversion has been done, and many interpolation tables have different binning). The failures without the spin temperature fluctuations have very small differences at the smallest scales in the power spectra.

tests.test_integration_features.py--test_power_spectra_lightcone[mdzeta].pdf

With the spin temperature fluctuations, global values appear identical but power spectra show significant differences at moderate and small scales. This difference is not something I've been able to track down looking at individual cells, but it seems to not affect the history very much.

tests.test_integration_features.py--test_power_spectra_lightcone[tsfluct].pdf

tests.test_integration_features.py--test_power_spectra_lightcone[mini_halos].pdf

Obviously, with USE_HALO_FIELD=True, the results are very different. I am currently performing some runs with just DexM on this branch to examine but these are very slow. I would expect differences from the new gridding structure and the different implementation of the halos in ComputeIonizedBox.

tests.test_integration_features.py--test_power_spectra_lightcone[halo_field].pdf

steven-murray commented 5 months ago

@daviesje this is looking great, thanks for the plots!

I think we need to bring in @andreimesinger here to weigh in on what kind of tolerance we should have for changes. The good thing is that the simplest cases (no spin temp, no halos) is working great. Happy to give that my stamp of approval.

Even with the spin temperature fluctuations, I think we're doing pretty well. The differences, as expected, are only evident in the fields dependent on Ts. The mini-halos example is a little concerning (~100% differences in some spectra), so I'd like @andreimesinger to weigh in there.

When using the halo field, we expect differences, and we see them. However, we should be careful to understand what kind of differences we might expect, and whether their magnitude is reasonable here. I'm seeing ~20% differences in the globally-averaged quantities which I don't think I expected, but perhaps I'm too naive.

daviesje commented 5 months ago

To give a little more context, the halo field differences will always be a bit of an apples-to-oranges comparison. In the master branch, the halo field is converted to collapsed fraction by dividing the halo mass in a cell by the cell mass, then either the constant zeta is applied (if USE_MASS_DEPENDENT_ZETA=False) or it is assumed all that mass is at 10^10 solar and the constant escape and stellar fractions are used (if USE_MASS_DEPENDENT_ZETA=True). The new model assigns stellar mass and sfr to the halos in accordance with the Park+19 model, with or without the lognormal scatter depending on parameters. For debugging I could create an option which uses the constant zeta with the halo boxes but I don't see this ever being useful.