Skip to content
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

FlowPM Blog Post Out of Date #96

Open
bhorowitz opened this issue Oct 8, 2021 · 3 comments
Open

FlowPM Blog Post Out of Date #96

bhorowitz opened this issue Oct 8, 2021 · 3 comments

Comments

@bhorowitz
Copy link
Contributor

bhorowitz commented Oct 8, 2021

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...

@EiffL
Copy link
Member

EiffL commented Oct 8, 2021

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

@EiffL
Copy link
Member

EiffL commented Oct 8, 2021

@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)
  ....

@adamrouhiainen
Copy link

adamrouhiainen commented Apr 27, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants