Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/DifferentiableUniverseInitiative/jax_cosmo

A differentiable cosmology library in JAX
https://github.com/DifferentiableUniverseInitiative/jax_cosmo

Last synced: 3 months ago
JSON representation

A differentiable cosmology library in JAX

Awesome Lists containing this project

README

        

# jax-cosmo

[![Join the chat at https://gitter.im/DifferentiableUniverseInitiative/jax_cosmo](https://badges.gitter.im/DifferentiableUniverseInitiative/jax_cosmo.svg)](https://gitter.im/DifferentiableUniverseInitiative/jax_cosmo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Documentation Status](https://readthedocs.org/projects/jax-cosmo/badge/?version=latest)](https://jax-cosmo.readthedocs.io/en/latest/?badge=latest) [![CI Test](https://github.com/DifferentiableUniverseInitiative/jax_cosmo/workflows/Python%20package/badge.svg)]() [![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![PyPI](https://img.shields.io/pypi/v/jax-cosmo)](https://pypi.org/project/jax-cosmo/) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](CODE_OF_CONDUCT.md) [![PyPI - License](https://img.shields.io/pypi/l/jax-cosmo)](https://github.com/google/jax-cosmo/blob/master/LICENSE)
[![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors-)

Finally a differentiable cosmology library, and it's in JAX!

Have a look at the [GitHub issues](https://github.com/DifferentiableUniverseInitiative/jax_cosmo/issues) to see what is needed or if you have any thoughts on the design, and don't hesitate to join the [Gitter room](https://gitter.im/DifferentiableUniverseInitiative/jax_cosmo) for discussions.

## TL;DR

This is what `jax-cosmo` aims to do:

```python
...
def likelihood(cosmo):
# Compute mean and covariance of angular Cls, for specific probes
mu, cov = jax_cosmo.angular_cl.gaussian_cl_covariance_and_mean(cosmo, ell, probes)
# Return likelihood value
return jax_cosmo.likelihood.gaussian_log_likelihood(data, mu, cov)

# Compute derivatives of the likelihood with respect to cosmological parameters
g = jax.grad(likelihood)(cosmo)

# Compute Fisher matrix of cosmological parameters
F = - jax.hessian(likelihood)(cosmo)
```

This is how you can compute **gradients and hessians of any functions in `jax-cosmo`**,
all of this without any finite differences.

Check out a full example here: [![colab link](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DifferentiableUniverseInitiative/jax_cosmo/blob/master/docs/notebooks/jax-cosmo-intro.ipynb)

Have a look at the [design document](design.md) to learn more about the structure of the code.

## What is JAX?

[JAX](https://github.com/google/jax) = NumPy + autodiff + GPU

JAX is a framework for automatic differentiation (like TensorFlow or PyTorch) but following the NumPy API, and using the GPU/TPU enable XLA backend.

What does that mean?

- You write plain Python/NumPy code, no need to learn a different language
- It runs on GPU, you don't need to do anything particular
- You can take derivatives of any quantity with respect to any parameters by
automatic differentiation.

Checkout the [JAX](https://github.com/google/jax) project page to learn more!

## Install

`jax-cosmo` is pure Python, so installing is a breeze:

```bash
$ pip install jax-cosmo
```

## Philosophy

Here are some of the design guidelines:

- Implementation of equations should be human readable, and documentation should always live next to the implementation.
- Should always be trivially installable: external dependencies should be kept
to a minimum, especially the ones that require compilation or with restrictive licenses.
- Keep API and implementation simple and intuitive, minimize user and developer
surprise.
- β€œDebugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” -Brian Kernighan, quote stolen from
[here](https://flax.readthedocs.io/en/latest/philosophy.html).

## Contributing

`jax-cosmo` aims to be a community effort, contributions are most welcome and
can come in several forms

- Bug reports
- API design suggestions
- (Pull) requests for more features
- Examples and notebooks of cool things that can be done with the code

You can chime-in on any aspects of the design by proposing a PR to the [design document](design.md). The issue page is a good place to start, but don't hesitate to come chat in the Gitter room.

Please take a look at the [Contributing Document](CONTRIBUTING.md) for more information.

This project follows the [All Contributors](https://allcontributors.org/) guidelines aiming at recognizing and valorizing
contributions at any levels.

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



Francois Lanusse

πŸ’»

Santiago Casas

πŸ› πŸ’»

Austin Peel

πŸ’»

Minas Karamanis

πŸ’»

David Kirkby

πŸ’» πŸ›

Alexandre Boucaud

πŸ’»

Denise Lanzieri

πŸ’»



jecampagne

πŸ›

Yin Li

πŸ’» πŸ›

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!