The only pre-requisites are Python (version ≥ 2.7 or ≥ 3.6) and the Python package manager pip (external modules may have additional dependencies).
To check if you have Python installed, type
python --version in the shell, and you should get
Python 2.7.[whatever] or
Python 3.6.[whatever]. Then, type
pip in the shell, and if you get usage instructions instead of a
command not found message, you are golden. If you don’t have any of those two installed, use your system’s package manager or contact your local IT service.
Python 2 support will eventually be dropped (it is already unsupported by many scientific Python modules). Please use Python 3.
In some systems, the Python 3 command may be
python3 instead of
python. If that is the case, use
pip3 instead of
pip in all the instructions below.
If any of the
pip install commands below fails (most likely with an
[Errno 13] Permission denied), add a
--user flag at the end of the command.
MPI parallelization (optional but encouraged!)¶
Enabling MPI parallelization is optional but highly recommended: it will allow you to better utilise the size of your CPU or cluster. MPI enables inter-process communication, of which many samplers can take advantage, e.g. for achieving a faster convergence of an MCMC proposal distribution, or a higher effective acceptance rate in a nested sampler.
First, you need to install an MPI implementation in your system, or load the corresponding module in a cluster with
module load (it will appear as
pmi; check your cluster’s usage guidelines).
For your own laptop we recommend OpenMPI. Install it using your system’s package manager (
sudo apt install libopenmpi in Debian-based systems) or contact your local IT service.
Second, you need to install the Python wrapper for MPI,
mpi4py, with version
$ pip install "mpi4py>=3" --upgrade --no-binary :all:
If you are using Anaconda, do instead
conda install -c [repo] mpi4py
[repo] must be either
conda-forge (if you are using GNU compilers) or
To test the installation, run in a terminal
$ mpirun -n 2 python -c "from mpi4py import MPI, __version__; print(__version__ if MPI.COMM_WORLD.Get_rank() else '')"
(You may need to substitute
srun in certain clusters.)
This should print the version of
3.0.0. If it prints a version smaller than 3, doesn’t print anything, or fails with an error similar to
ImportError: libmpi.so.12, make sure that you have installed/loaded an MPI implementation and repeat the installation, or ask your local IT service for help.
Installing and updating cobaya¶
To install cobaya or upgrade it to the last release, simply type in a terminal
$ pip install cobaya --upgrade
To go on installing cosmological modules, see Installing cosmological codes and data.
In general, use
conda) instead of cloning directly from the github repo: there is where development happens, and you may find bugs and features just half-finished.
Unless, of course, that you want to help us develop cobaya. In that case, take a look at Method 1: Using git (recommended!).
Making sure that cobaya is installed¶
If everything went well, you should be able to import cobaya in Python from anywhere in your directory structure:
$ python -c "import cobaya"
If you get an error message, something went wrong. Check twice the instructions above, try again, or contact us or your local Python guru.
cobaya also installs some shell scripts. If everything went well, if you try to run in the shell
cobaya-run, you should get a message asking you for an input file, instead of a
command not found error.
If you do get a
command not found error, this means that the folder where your local scripts are installed has not been added to your path.
To solve this, look for the
cobaya-run script from your
scratch folders with
$ find `pwd` -iname cobaya-run -printf %h\\n
This should print the location of the script, say
$ export PATH=$PATH:"/home/you/.local/bin"
at the end of your
~/.bashrc file, and restart the terminal or do
source ~/.bashrc. Alternatively, simply add that line to your cluster scripts just before calling
Simply do, from anywhere
$ pip uninstall cobaya
If you installed cobaya in development mode (see below), you will also have to delete its folder manually, as well as the scripts installed in the local
bin folder (see note above about how to find it).
This section will be filled with the most common problems that our users encounter, so if you followed the instructions above and still something failed (or if you think that the instructions were not clear enough), don’t hesitate to contact us!
Low performance: install OpenBLAS (or MKL)¶
BLAS is a collection of algorithms for linear algebra computations. There will most likely be a BLAS library installed already in your system. It is recommended to make sure that it is an efficient one, preferably the highly-optimized OpenBLAS or MKL.
To check whether
numpy is actually using OpenBLAS or MKL, do
$ python -c "from numpy import show_config; show_config()" | grep 'mkl\|openblas_info' -A 1
Check that it prints a list of libraries and not a
NOT AVAILABLE below at least one of
If you just got
NOT AVAILABLE’s, load the necessary libraries with
module load if you are in a cluster, or install OpenBlas or MKL.
To check if OpenBLAS is installed, in Debian-like systems, type
$ dpkg -s libopenblas-base | grep Status
The output should end in
install ok installed. If you don’t have it installed, in a Debian-like system, type
sudo apt install libopenblas-base or ask your local IT service.
You may need to re-install
numpy after loading/installing OpenBLAS.
To check that this worked correctly, run the following one-liner with the same Python that Cobaya is using, and check that
top reports more than 100% CPU usage:
import numpy as np ; (lambda x: x.dot(x))((lambda n: np.reshape(np.random.random(n**2), (n,n)))(10000))
Installing cobaya in development mode¶
Use this method if you want to make modifications to the code, either for yourself, or to collaborate with us by implementing a new feature.
Notice that you don’t need to modify cobaya’s source to use your own priors, likelihoods, etc. Take a look at the documentation of the modules that you would like to modify to check if can do that in an easier way.
Method 1: Using
To download and install cobaya in development mode you will need
git (learn how to use git). Type
git in the shell and check that you get usage instructions instead of a
command not found error. In the later case, in a Debian-like system, install it with a
sudo apt install git.
The recommended way is to get a GitHub user and fork the cobaya repo. Then clone your fork and install it as a Python package in development mode (i.e. your changes to the code will have an immediate effect, without needing to update the Python package):
$ git clone https://YOUR_USERNAME@github.com/YOUR_USERNAME/cobaya.git $ pip install --editable cobaya[test] --upgrade
(add the –user option if you don’t have write access to the default pip installation location). Here
cobaya[test] should include the square brackets.
Alternatively, you can clone from the official cobaya repo (but this way you won’t be able to upload your changes!).
$ git clone https://github.com/CobayaSampler/cobaya.git $ pip install --editable cobaya[test] --upgrade
In any of both cases, this puts you in the last commit of cobaya, and install the requisites for both running and testing (to ignore the testing requisites, remove
[test] from the commands above). If you want to start from the last release, say version 1.0, do, from the cobaya folder,
$ git checkout v1.0
Finally, take a look at Making sure that cobaya is installed.
Method 2: Simplest, no
git (not recommended!)¶
This method is not recommended: you will not be able to keep track of your changes to the code! We really encourage you to use
git (see method 1).
Download the latest release (the one on top) from cobaya’s GitHub Releases page. Decompress it in some folder, e.g.
/path/to/cobaya/, and install it as a python package:
$ cd /path/to/cobaya/ $ pip install --editable cobaya
Finally, take a look at Making sure that cobaya is installed.