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

Integrating the Sympy-based Boltzmann solver from PyCosmo #87

Open
EiffL opened this issue Jan 29, 2022 · 5 comments
Open

Integrating the Sympy-based Boltzmann solver from PyCosmo #87

EiffL opened this issue Jan 29, 2022 · 5 comments
Labels
Cosmology Issue related to implementing cosmology features enhancement New feature or request

Comments

@EiffL
Copy link
Member

EiffL commented Jan 29, 2022

Following a very nice talk from Beatrice Moser, I looked a little bit at how PyCosmo is implementing their own Boltzmann code and it's actually pretty nice and could be pretty easily ported to JAX I think.

The ODE is specificied using Sympy, which makes it pretty easy to write down the equations, and then they use their own sympy2c code to transform the python code into JIT compiled code to run the actual ODE solver.

So that's pretty cool :-) But we could make it way cooler by doing the following:

  • Copy/Paste the Sympy equations from PyCosmo (which is GPL licensed)
  • Use Miles' sympy2jax library https://github.com/MilesCranmer/sympy2jax to turn the equations into JAX functions
  • Use jax.experimental.odeint to integrate in time the system
  • Profit!

And boom! You got yourself a diffable Boltzman solver!

@EiffL EiffL added Cosmology Issue related to implementing cosmology features enhancement New feature or request labels Jan 31, 2022
@EiffL
Copy link
Member Author

EiffL commented Jan 31, 2022

And tagging @moserb94 on this issue.

After reading more of the PyCosmo code I realized that it still relied on an external RecFast implementation however :-( so not completely as easy as I was hoping. One would have to recode RecFast also in JAX, in the same way as Zack did it for Bolt.jl here: https://github.com/xzackli/Bolt.jl/blob/main/src/ionization/recfast.jl

The whole thing is still doable :-) But slightly more involved than I was hoping.

@EiffL
Copy link
Member Author

EiffL commented Jan 31, 2022

Also I'm thinking it would be worthwhile to host a JAX Boltzmann solver as a separate project, as opposed to integrating it directly into jax-cosmo.

@moserb94
Copy link

moserb94 commented Feb 2, 2022

Thank you for tagging me. It sounds pretty cool (even though I just started looking into JAX)! Yes, we rely on RecFast++ to compute the evolution of thermodynamic quantities and we are actually planning to move to HYREC-2 in the near future.

@EiffL
Copy link
Member Author

EiffL commented Feb 2, 2022

interesting :-) By any chance.... would you be thinking of doing an implementation in sympy as well for hyrec-2 ?

@EiffL EiffL closed this as completed Feb 2, 2022
@EiffL EiffL reopened this Feb 2, 2022
@moserb94
Copy link

moserb94 commented Feb 2, 2022

The idea was to use hyrec-2 the way we use RecFast++ (meaning a python wrapper and an interpolator), rather than rewriting the code in sympy... so that wouldn't help I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cosmology Issue related to implementing cosmology features enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants