-
Notifications
You must be signed in to change notification settings - Fork 1
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
Adds basic infrastructure with prototype code for PM pipeline #9
Conversation
…-pipelines-cosmology into u/EiffL/infrastructure
Co-authored-by: Alexandre Boucaud <[email protected]>
bpcosmo/pm.py
Outdated
|
||
# Extract the lensplanes | ||
density_planes = [] | ||
for i in range(len(a_center)): |
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.
for i in range(len(a_center)): | |
for i in range(n_lens): |
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.
line 123: is it the same 0.01 as in line 84? If so, maybe worth defining a new variable?
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.
indeed, done!
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.
Looking good, but please homogenise the code indentation in the file.
bpcosmo/pm.py
Outdated
dz = density_plane_width | ||
plane = density_plane(res[0][::-1][i], | ||
nc, | ||
(i+0.5)*density_plane_width/box_size[-1]*nc[-1], |
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.
What is the "+0.5"? Some corner assignment scheme?
density_plane_smoothing: Gaussian scale of plane smoothing | ||
box_size: [sx,sy,sz] size in Mpc/h of the simulation volume | ||
nc: number of particles/voxels in the PM scheme | ||
neural_spline_params: optional parameters for neural correction of PM scheme |
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.
Do we need a reference cited for the neural spline?
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 indeed, unfortunately we don't have one yet ^^' this is some very recent trick that @dlanzieri is still working on. We might have an arxiv ref in few weeks
bpcosmo/pm.py
Outdated
neural_spline_params: optional parameters for neural correction of PM scheme | ||
Returns: | ||
list of [r, a, plane], slices through the lightcone along with their | ||
comoving distance and scale factors. |
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.
Being pedantic here, but maybe it's worth clarifying: "list of [r, a, plane], slices through the lightcone along with their comoving distance (r) and scale factors (a), with 'plane' being the index of the density slice.", or something along those lines.
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.
plane would range from 0 to nc[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.
yep thank you, added more clarification
bpcosmo/pm.py
Outdated
a_center = jc.background.a_of_chi(cosmology, r_center) | ||
|
||
# Create a small function to generate the matter power spectrum | ||
k = jnp.logspace(-4, 1, 128) |
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.
why 128 bins?
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've upped to to 256 to be safe. These are points used to interpolate the matter power spectrum, needed when building initial conditions. It shouldn't be very sensitive to this parameter choice.
bpcosmo/pm.py
Outdated
|
||
# Initial displacement | ||
cosmology._workspace = {} # FIX ME: this a temporary fix | ||
dx, p, f = lpt(cosmology, initial_conditions, particles, 0.01) |
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.
where does 0.01 come from?
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.
Ah yes, 0.01 is the the initial scale factor at which we initialize the simulation.
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 added explicitly the keyword
bpcosmo/pm.py
Outdated
@jax.jit | ||
def neural_nbody_ode(state, a, cosmo, params): | ||
""" | ||
state is a tuple (position, velocities) |
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.
velocities in km/s?
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.
hummm yeah good question... I think what I added there is correct
bpcosmo/pm.py
Outdated
# Computes gravitational potential | ||
pot_k = delta_k * laplace_kernel(kvec) * longrange_kernel(kvec, r_split=0) | ||
|
||
# Apply a correction filter |
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.
why do we need this correction? what filter is this?
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 is the magic sauce from this spline correction function that @dlanzieri is building. I hope we'll soon have a paper to describe it.
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.
it corrects power on small scales, to effectively increase the resolution of the simulation
I've tried to address all your comments @elts6570, let me know what you think and if you approve this PR :-) |
@EiffL looks great! looking forward to the magic splines paper! :) |
This PR adds some basic infra, like adds a setup.py. It also adds some code based on jaxpm to generate density planes from an nbody simulation, which can be used in a forward model.
A demo notebook is provided here
It generates DC2-like maps:
This provides a few first elements towards solving #8