-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ionbox refactor #427
Ionbox refactor #427
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v4-prep #427 +/- ##
===========================================
+ Coverage 74.11% 79.51% +5.40%
===========================================
Files 23 23
Lines 3747 3764 +17
Branches 641 644 +3
===========================================
+ Hits 2777 2993 +216
+ Misses 742 549 -193
+ Partials 228 222 -6 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @daviesje, this is going to make things much easier!
// This should be very rare, and even when it occurs, it will usually use a different initialiser, | ||
// as well as be applied to different cells/halos, so I can't forsee any issues. | ||
//Just in case I'm not using it for the initial conditions, which is okay since the slower version is only used once | ||
void seed_rng_threads_fast(gsl_rng * rng_arr[], unsigned long long int seed){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a line that just checks if any of the seeds are the same and re-samples if so.
//TODO: these seeding functions should probably be somewhere else | ||
// Possibly make an rng.c/h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this
@@ -299,6 +299,46 @@ int stoc_halo_sample(struct HaloSamplingConstants *hs_constants, gsl_rng * rng, | |||
return 0; | |||
} | |||
|
|||
//same as stoc_halo_sample but with a mass tolerance for comparison with Ivan | |||
int stoc_halo_sample_tol(struct HaloSamplingConstants *hs_constants, gsl_rng * rng, int *n_halo_out, float *M_out){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function needs to be documented a bit to say what it does and why it's here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
src/py21cmfast/src/IonisationBox.c
Outdated
//Making a dummy previous box which has the required fields for the first snapshot: | ||
void setup_first_z_prevbox(IonizedBox *previous_ionize_box, PerturbedField *previous_perturb, int n_radii){ | ||
LOG_DEBUG("first redshift, do some initialization"); | ||
int i,j,k; | ||
unsigned long long int ct; | ||
|
||
#pragma omp parallel shared(box) private(ct) num_threads(user_params->N_THREADS) | ||
//z_re_box is used in all cases | ||
previous_ionize_box->z_re_box = (float *) calloc(HII_TOT_NUM_PIXELS, sizeof(float)); | ||
#pragma omp parallel shared(previous_ionize_box) private(i,j,k) num_threads(user_params_global->N_THREADS) | ||
{ | ||
#pragma omp for | ||
for (ct=0; ct<HII_TOT_NUM_PIXELS; ct++) { | ||
box->z_re_box[ct] = -1.0; | ||
#pragma omp for | ||
for (i=0; i<user_params_global->HII_DIM; i++){ | ||
for (j=0; j<user_params_global->HII_DIM; j++){ | ||
for (k=0; k<HII_D_PARA; k++){ | ||
previous_ionize_box->z_re_box[HII_R_INDEX(i, j, k)] = -1.0; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this not something that's better done from the python wrapper?
src/py21cmfast/src/IonisationBox.c
Outdated
//TODO: moved from inside the R loop, either place verification in python wrapper or write a function to verify backend parameters | ||
if (global_params.FIND_BUBBLE_ALGORITHM != 2 && global_params.FIND_BUBBLE_ALGORITHM != 1){ // center method | ||
LOG_ERROR("Incorrect choice of find bubble algorithm: %i", | ||
global_params.FIND_BUBBLE_ALGORITHM); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done in the GlobalOptions
validator. I think we should be writing the C functions essentially without validation, assuming all has been validated externally.
src/py21cmfast/src/IonisationBox.c
Outdated
//boxes which aren't guaranteed to have every element assigned to need to be initialised | ||
//TODO: they should be zero'd in the wrapper, right? | ||
if(flag_options->INHOMO_RECO) { | ||
if(INIT_RECOMBINATIONS) { | ||
init_MHR(); | ||
INIT_RECOMBINATIONS=0; | ||
} | ||
|
||
// remember to add the factor of VOLUME/TOT_NUM_PIXELS when converting from | ||
// real space to k-space | ||
// Note: we will leave off factor of VOLUME, in anticipation of the inverse FFT below | ||
#pragma omp parallel shared(deltax_unfiltered,xe_unfiltered,N_rec_unfiltered,prev_deltax_unfiltered,\ | ||
log10_Mturnover_unfiltered,log10_Mturnover_MINI_unfiltered,stars_unfiltered) \ | ||
private(ct) num_threads(user_params->N_THREADS) | ||
#pragma omp parallel shared(box) private(ct) num_threads(user_params->N_THREADS) | ||
{ | ||
#pragma omp for | ||
for (ct=0; ct<HII_KSPACE_NUM_PIXELS; ct++){ | ||
deltax_unfiltered[ct] /= (HII_TOT_NUM_PIXELS+0.0); | ||
if(flag_options->USE_TS_FLUCT) { xe_unfiltered[ct] /= (double)HII_TOT_NUM_PIXELS; } | ||
if (recomb_filter_flag){ N_rec_unfiltered[ct] /= (double)HII_TOT_NUM_PIXELS; } | ||
if(flag_options->USE_HALO_FIELD) { | ||
stars_unfiltered[ct] /= (double)HII_TOT_NUM_PIXELS; | ||
sfr_unfiltered[ct] /= (double)HII_TOT_NUM_PIXELS; | ||
} | ||
if(flag_options->USE_MINI_HALOS){ | ||
prev_deltax_unfiltered[ct] /= (HII_TOT_NUM_PIXELS+0.0); | ||
log10_Mturnover_unfiltered[ct] /= (HII_TOT_NUM_PIXELS+0.0); | ||
log10_Mturnover_MINI_unfiltered[ct] /= (HII_TOT_NUM_PIXELS+0.0); | ||
} | ||
#pragma omp for | ||
for (ct=0; ct<HII_TOT_NUM_PIXELS; ct++) { | ||
box->Gamma12_box[ct] = 0.0; | ||
box->MFP_box[ct] = 0.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is all wrapper stuff.
src/py21cmfast/src/IonisationBox.c
Outdated
// perform a very rudimentary check to see if we are underresolved and not using the linear approx | ||
if ((user_params->BOX_LEN > user_params->DIM) && !(global_params.EVOLVE_DENSITY_LINEARLY)){ | ||
LOG_WARNING("Resolution is likely too low for accurate evolved density fields\n It Is recommended \ | ||
that you either increase the resolution (DIM/BOX_LEN) or set the EVOLVE_DENSITY_LINEARLY flag to 1\n"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this also should be in the wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks @daviesje !
@daviesje most recent changes look good -- I didn't understand the switch from The two failing tests with |
This was a bug introduced in the refactor where the wrong interpolation tables were being initialised (the previous redshift instead of the current).
This is entirely arbitrary, but doesn't effect the test results. I just need to make sure that it can hold all the halos that the tests produce, I thought about 500MB should be enough.
This has just been fixed, it was an error on my part incorrectly setting interpolation table limits when USE_MASS_DEPENDENT_ZETA=False. For some reason running tests with |
This is a coarse modularisation of the ionised box calculation which separates the large function into a number of smaller steps. This should make future development easier. I have tested that we get the same results under a few variations of parameters, and it has not slowed down.
Key differences:
Further modularisation is possible, but best left to another PR