Giter Club home page Giter Club logo

mcmc-tutorial's Introduction

Intro to MCMC for Swansea Cosmology students

This repository contains the different files required to do the coding exercises presented in the lectures.

Instructions for setting up Cobaya on the Swansea cluster or your laptop

Login to the cluster through the terminal

Once logged in load the following modules

module load anaconda/2023.09 compiler/gnu/12/1.0 mpi/openmpi/4.1.5

If you are working on your own laptop and not the cluster, you should skip the first two steps. For running the codes on your laptop you will still need python and the gcc (or another) compiler installed, mpi optional. Installation issues mainly happen with MacOS or Windows, for the former I recommend using Homebrew to manage the installation of these and then use anaconda/miniconda for managing the python environments. For Windows look into WSL which provides a Linux enviroment to use on Windows or work directly on the cluster.

You can then create a conda environment but for the cluster I recommend using a python virtual environment. Create this using

python -m venv /path/to/your/virtual/environment

Activate your new environment.

source /path/to/your/virtual/environment/bin/activate

Now, you can follow the instructions on the cobaya homepage to install cobaya (reproduced below). You can first install the python MPI wrapper if you want to use parallel processing to run multiple MCMC chains (you will need to install an MPI package if you are working on your laptop). Although this is not necessary to get started it is highly recommended to do so since this will make the sampling more efficient.

python -m pip install "mpi4py>=3" --upgrade --no-binary :all:
python -m pip install cobaya --upgrade
python -c "import cobaya"

If everything went well, the last command should not give you an error.

Cobaya input files are provided in the .yaml format. To install the cosmological theory codes and likelihoods used in a particular inputfile type

cobaya-install inputfile.yaml -p /path/to/packages

For more information, see the cobaya documentation.

To run cobaya with your input file, type

cobaya-run inputfile.yaml 

to run without MPI or

mpirun -n nproc cobaya-run inputfile.yaml 

if using nproc MPI processes.

Note! You should not run programs directly on the login node. It is ok however to add the --test flag to the cobaya-run command when on the login node. This will check that the input file provided is valid and the required theory codes and likelihoods are already installed. To do a full MCMC run, start an interactive job for short runs or use the provided job scripts for longer runs.

For moving the input files to the cluster or downloading files from the cluster to your system, see the Swansea Sunbird documentation. To analyse the results of the MCMC, you can work directly on the cluster or download the chains to your own system. Getdist notebooks for analysing the chains are provided in the repository. Note that python notebooks will not work directly on the cluster.

mcmc-tutorial's People

Contributors

ameek94 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.