# CMBLensing.jl

CMBLensing.jl is a next-generation tool for analysis of the lensed Cosmic Microwave Background. It is written in Julia and transparently callable from Python.

At its heart, CMBLensing.jl maximizes or samples the Bayesian posterior for the CMB lensing problem. It also contains tools to quickly manipulate and process CMB maps, set up modified posteriors, and take gradients using automatic differentation.

### Highlights

• Fully Nvidia GPU compatible (speedups over CPU are currently 3x-10x, depending on the problem size and hardware).
• Automatic differentation (via Zygote.jl) provides for-free gradients of your custom posteriors.
• Includes the following algorithms to lense a map:
• Maximize and sample $\mathcal{P}(f,\phi,\theta\,|\,d)$, the joint maximum a posteriori estimate of the lensing potential, $\phi$, the temperature and/or polarization fields, $f$, and cosmological parameters, $\theta$ (Millea, Anderes, & Wandelt 2017, Millea, Anderes, & Wandelt 2020)
• Maximize $\mathcal{P}(\phi\,|\,d,\theta)$, i.e. the marginal maximum a posteriori estimate of the lensing potential, $\phi$, at fixed cosmological parameters, $\theta$ (Carron & Lewis 2017)
• Do basic quadratic estimation of $\phi$ (Hu & Okamoto 2003)

## Documentation

The best place to get started is to read the documentation (which is a work-in-progress, but contains many useful examples).

Most of the pages in the documentation are Jupyter notebooks, and you can click the "launch binder" link at the top of each page to launch a Jupyterlab server running the notebook in your browser (courtesy of binder).

You can also clone the repostiory and open the notebooks in docs/src if you want to run them locally (which will usually lead to higher performance). The notebooks are stored as .md files rather than .ipynb format. Its recommented to install Jupytext (pip install jupytext) and then you can run these .md directly from Jupyterlab by right-clicking on them and selecting Open With -> Notebook. Otherwise, run the script docs/make_notebooks.sh to convert the .md files to .ipynb which you can then open as desired.

## Installation

### Requirements

• Julia 1.5
• (recommended) An Nvidia GPU and CUDA.jl for GPU support
• (recommended) FFTW.jl built with JULIA_FFTW_PROVIDER=MKL for faster CPU FFTs
• (recommended) Python 3 + matplotlib (used for plotting)
• (recommended) pycamb to generate $C_\ell$'s
• (optional) healpy for experimental curved sky support

### Native installation

To install the Julia package locally, run:

pkg> add CMBLensing

(type ] at the Julia REPL to reach the pkg> prompt)

It's recommended to link Julia to Intel MKL FFT libraries, which provide significantly faster FFTs when running on CPU. This can be done easily by running ENV["JULIA_FFTW_PROVIDER"]="MKL"; using Pkg; Pkg.build("FFTW") from Julia and restarting the session (see also here).

### Docker installation

Also provided is a Docker container which includes a Jupyterlab server and all the recommended and optional dependencies to run and use CMBLensing.jl. Launch this container with:

git clone https://github.com/marius311/CMBLensing.jl.git
cd CMBLensing.jl
docker-compose pull
docker-compose up

The first time you run this, it will automatically download the (~1Gb) container from the Docker hub. The command will prompt you with the URL which you should open in a browser to access the notebook.

To run the notebook on a different port than the default 8888, do PORT=1234 docker-compose up where 1234 is whatever port number you want.

You can also build the container locally by replacing docker-compose pull with docker-compose build above.