-
Notifications
You must be signed in to change notification settings - Fork 299
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
fast P(k,z) access #145
Comments
Hi Stephane Are you calling CLASS through the Python wrapper, the C++ wrapper or directly through C? Cheers, |
Hi Thomas, |
Hi again Computing P(k,z) requires most of the CLASS modules except for the transfer module (that computes transfer functions in harmonic space) the lensing module (that computes CMB lensing) and the non-linear module (unless halofit is required). This takes of the order 1 second. After this computation the P(k,z) can be recovered using A real speedup in this computation can be obtained by For the last part, you can play with the settings mentioned in this issue #32. Cheers, |
thanks Thomas, |
Hi again Okay, you must have many k-values then! But then spectra_pk_at_k_and_z() is indeed pretty slow, since for each k, the k-array at the given tau is constructed from interpolation and then splined. You will need to write a new fast function, but first a question: Do you know all the k-values you want to compute P(k) from the beginning, or do you generate them on the fly? (The latter would be the case if you are for instance doing adaptive integration in k...) Cheers, |
right, this is for tomography where up to 10^10 P(k,z) values may be required. But good news k and z |
Hi Stephane I have written two functions that should solve your problem, you can find them in the attached .txt file. (I have done some testing, but not extensive, so I apologise in advance for any bugs or weird behaviour.) This is exceptional of course, normally I would just provide some hints to the solution :) The two functions are If you read the code you can see that I made several tricks to increase the interpolation speed. Let me know how it works. Cheers, PS You need to add the functions to spectra.c and you need to add the functions to spectra.h. |
thanks that's great. I will try it and report (this may take some time)
stephane
Le 31/03/2017 à 10:26, Thomas Tram a écrit :
…
Hi Stephane
I have written two functions that should solve your problem, you can
find them in the attached .txt file. (I have done some testing, but
not extensive, so I apologise in advance for any bugs or weird
behaviour.) This is exceptional of course, normally I would just
provide some hints to the solution :)
The two functions are
´´´´
int spectra_fast_pk_at_kvec(
struct background * pba,
struct spectra * psp,
double * kvec,
int kvec_size,
double * pk_tot_out /* (must be already allocated with kvec_size/psp) //
);
''''
and
´´´´
int spectra_fast_pk_at_kvec_and_zvec(
struct background * pba,
struct spectra * psp,
double * kvec,
int kvec_size,
double * zvec,
int zvec_size,
double * pk_tot_out // (must be already allocated with
kvec_size/zvec_size) */
''''
The first one returns P(k,z_class) on the grid of log(tau) values
found in psp->ln_tau[]. This array is computed by CLASS, and the
largest values is slightly before the maximum z required in input. The
second function is probably what you want, since it is interpolated in
zvec as well. So you just pass the z_array and the k_array you want
and it is interpolated.
If you read the code you can see that I made several tricks to
increase the interpolation speed. Let me know how it works.
Cheers,
Thomas
pkfunctions.txt
<https://github.com/lesgourg/class_public/files/884904/pkfunctions.txt>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#145 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALVf5iyyHgnPKqjkjdmFob3ftUEeE6KEks5rrLi-gaJpZM4MoFVr>.
|
Hi Thomas,
so it compiled smoothly and runs indeed much fatser (about a factor 20
on my bench). But I have troubles accessing the output values that are
always 0 (this is maybe just my C++ implementation that use sa
std::vector and &vector[0] to access double*, but this generally work)
Just to be sure: pk_tot_out should only be sized kvec_size, right?
Also a last point: does it worth producing a
spectra_fast_pk_at_kvec_at_z with a fixed z values or is it equivalent
to using your last function with a z vector of one value?
thanks very much
stephane
Le 31/03/2017 à 10:26, Thomas Tram a écrit :
…
Hi Stephane
I have written two functions that should solve your problem, you can
find them in the attached .txt file. (I have done some testing, but
not extensive, so I apologise in advance for any bugs or weird
behaviour.) This is exceptional of course, normally I would just
provide some hints to the solution :)
The two functions are
´´´´
int spectra_fast_pk_at_kvec(
struct background * pba,
struct spectra * psp,
double * kvec,
int kvec_size,
double * pk_tot_out /* (must be already allocated with kvec_size/psp) //
);
''''
and
´´´´
int spectra_fast_pk_at_kvec_and_zvec(
struct background * pba,
struct spectra * psp,
double * kvec,
int kvec_size,
double * zvec,
int zvec_size,
double * pk_tot_out // (must be already allocated with
kvec_size/zvec_size) */
''''
The first one returns P(k,z_class) on the grid of log(tau) values
found in psp->ln_tau[]. This array is computed by CLASS, and the
largest values is slightly before the maximum z required in input. The
second function is probably what you want, since it is interpolated in
zvec as well. So you just pass the z_array and the k_array you want
and it is interpolated.
If you read the code you can see that I made several tricks to
increase the interpolation speed. Let me know how it works.
Cheers,
Thomas
pkfunctions.txt
<https://github.com/lesgourg/class_public/files/884904/pkfunctions.txt>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#145 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALVf5iyyHgnPKqjkjdmFob3ftUEeE6KEks5rrLi-gaJpZM4MoFVr>.
|
OK I cured my problem: I was using a z_max_pk =1 in my test (and shoud not with spectra_fast_pk_at_kvec). I guess the output is of size kvecsize*psp->ln_tau_size right? |
That's correct. For z_max_pk of 100, psp->ln_tau_size is roughly 450. I think the other function is probably the one you want since you can choose the z-vector yourself. (So this function is potentially much faster if you need less redshifts.) Cheers, |
OK I confirm the other routine works also well (and is probably less dangerous while as efficient) Any chance the code enters the master (or other) branch? it might interest others. |
Hi Stephane Yes that should be fine. I think this new method should be implemented in the master branch in the next release. I will leave this issue open so that I remember! Cheers, |
Hi Thomas, thanks, |
Hi Thomas, I could copy the ba structure at the start of the Pk function so that it does not change during the computation. Is there a way to do this easily? |
* Fixing 142 by using cubic interpolation of lnPk * Making makefile compatible with the pypi installation by promoting the CLASSDIR to an environment variable that can be passed during installation --------- Co-authored-by: schoeneberg <[email protected]>
Dear Class support,
I would like to gain on the speed of P(k,z) computations (which is too low by default) and wonder how to do that efficiently so I have a few questions:
-there is a z_max_pk (that I set) : is there a z_min_pk one?
-how is performed the P(k,z) evolution in z? (in which part of the code?)
any other idea?
thanks, my best
stephane
The text was updated successfully, but these errors were encountered: