Open bhorowitz opened 3 years ago
so yes, the code from the blog post is out of date, but I think it should still work, no?
We just need newer examples
@bhorowitz if you want to see a recent demo, have a look at this notebook: https://colab.research.google.com/drive/1k6cTniiRZGF4F_RAA4XDuBCY16FxyUcZ?usp=sharing
This is doing a lensing sim, but you'll get the picture.
You want to encapsulate your function in something like this:
@tf.function
def make_map(Omega_c=0.2589, sigma8=0.8159):
# Instantiates a cosmology with desired parameters
cosmology = flowpm.cosmology.Planck15(Omega_c=Omega_c, sigma8=sigma8)
....
The minimal example flowpm_demo.ipynb is outdated, but it should work if the 4th cell is replaced with
import flowpm
from flowpm.tfpower import linear_matter_power
@tf.function
def simulation(om, s8):
cosmo = flowpm.cosmology.Planck15(Omega_c=om, sigma8=s8)
stages = np.linspace(a0, af, n_steps, endpoint=True) #time-steps for the integration
initial_conditions = flowpm.linear_field(N, # size of the cube
L, # Physical size of the cube
lambda k: tf.cast(linear_matter_power(cosmo, k), tf.complex64), # Initial powerspectrum
batch_size=16)
# Sample particles
state = flowpm.lpt_init(cosmo, initial_conditions, a0)
# Evolve particles down to z=0
final_state = flowpm.nbody(cosmo, state, stages, 32)
# Retrieve final density field
final_field = flowpm.cic_paint(tf.zeros_like(initial_conditions), final_state[0])
return final_field
The flowpm_blog.ipynb file which is lined from the main README still uses tensorflow 1.x rather than 2.6. I'm not sure what the highest 2.x flowpm has been tested on so far...