Last active
October 19, 2021 11:31
-
-
Save ntessore/ef1da77f650e0b1cadfc75abda249957 to your computer and use it in GitHub Desktop.
CosmoSIS installation script for conda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -i | |
cat << EOF && read -n1 -srp "press key to start, Ctrl+C to abort" && echo | |
--- | |
to get this script: | |
$ curl -OL https://git.io/cosmosis-conda.sh | |
$ chmod +x cosmosis-conda.sh | |
to run this script: | |
$ ./cosmosis-conda.sh | |
after the script runs, you should have a conda environment called | |
"cosmosis" which you can activate to run cosmosis: | |
$ conda activate cosmosis | |
$ cosmosis --help | |
if the installation fails, you can remove the "cosmosis" environment | |
and start from the beginning: | |
$ conda env remove -n cosmosis | |
--- | |
EOF | |
# ------------------ | |
# user configuration | |
# ------------------ | |
# name of the cosmosis environment | |
COSMOSIS_ENV=cosmosis | |
# set the cosmosis branch to check out (leave empty for release) | |
COSMOSIS_BRANCH=develop | |
# use OpenMP in cosmosis (=1) or don't (=0) | |
COSMOSIS_OMP=1 | |
# conda BLAS and LAPACK versions: mkl, openblas, blis, netlib | |
CONDA_BLAS="mkl" | |
CONDA_LAPACK="mkl" | |
# -------------------- | |
# detect some settings | |
# -------------------- | |
# get operating system name | |
OS=$(uname -s) | |
# ----------- | |
# get to work | |
# ----------- | |
# halt on error | |
set -e | |
# create environment file | |
ENVFILE=cosmosis-conda.yml | |
# write conda environment | |
cat << EOF > ${ENVFILE} | |
name: ${COSMOSIS_ENV} | |
channels: | |
- conda-forge | |
- nodefaults | |
dependencies: | |
- compilers | |
- mpi | |
- python=3 | |
- future | |
- mpi4py | |
- numpy | |
- scipy | |
- matplotlib-base | |
- astropy | |
- libblas=*=*${CONDA_BLAS} | |
- liblapack=*=*${CONDA_LAPACK} | |
- emcee | |
- minuit2 | |
- nose | |
- pyyaml | |
- gsl | |
- fftw | |
- cfitsio | |
EOF | |
# load conda integration | |
eval "$(conda shell.bash hook)" | |
# create environment from file | |
conda env create -f ${ENVFILE} | |
# activate the environment | |
conda activate "${COSMOSIS_ENV}" | |
# change to environment directory | |
cd ${CONDA_PREFIX} | |
# install SDK on macOS | |
if [ "$OS" == "Darwin" ]; then | |
mkdir opt | |
cd opt | |
curl -L https://github.com/phracker/MacOSX-SDKs/releases/download/10.13/MacOSX10.13.sdk.tar.xz | tar -xJ | |
cd .. | |
echo "export CONDA_BUILD_SYSROOT=\${CONDA_PREFIX}/opt/MacOSX10.13.sdk" > etc/conda/activate.d/sysroot.sh | |
source etc/conda/activate.d/sysroot.sh | |
echo "sysroot set to ${CONDA_BUILD_SYSROOT}" | |
fi | |
# clone cosmosis repositories | |
git clone https://bitbucket.org/joezuntz/cosmosis | |
cd cosmosis | |
git checkout ${COSMOSIS_BRANCH} | |
git clone https://bitbucket.org/joezuntz/cosmosis-standard-library | |
cd cosmosis-standard-library | |
git checkout ${COSMOSIS_BRANCH} | |
cd .. | |
# write setup script | |
cat << EOF > setup-my-cosmosis | |
export COSMOSIS_SRC_DIR=\${CONDA_PREFIX}/cosmosis | |
export COSMOSIS_OMP=${COSMOSIS_OMP} | |
export COSMOSIS_ALT_COMPILERS=1 | |
export CC="\${CC} \${CFLAGS} \${LDFLAGS}" | |
export CXX="\${CXX} \${CXXFLAGS} \${LDFLAGS}" | |
export FC="\${FC} \${FFLAGS} \${LDFLAGS}" | |
export MPIFC="mpif90 \${FFLAGS} \${LDFLAGS}" | |
export GSL_INC=\${CONDA_PREFIX}/include | |
export GSL_LIB=\${CONDA_PREFIX}/lib | |
export CFITSIO_INC=\${CONDA_PREFIX}/include | |
export CFITSIO_LIB=\${CONDA_PREFIX}/lib | |
export FFTW_LIBRARY=\${CONDA_PREFIX}/lib | |
export FFTW_INCLUDE_DIR=\${CONDA_PREFIX}/include | |
export MINUIT2_INC=\${CONDA_PREFIX}/include/Minuit2 | |
export MINUIT2_LIB=\${CONDA_PREFIX}/lib | |
export LAPACK_LINK="-L\${CONDA_PREFIX}/lib -lblas -llapack" | |
export DYLD_LIBRARY_PATH=\${COSMOSIS_SRC_DIR}/cosmosis/datablock/:\${COSMOSIS_SRC_DIR}/cosmosis-standard-library/likelihood/:\${COSMOSIS_SRC_DIR}/cosmosis-standard-library/likelihood/planck/plc-1.0/lib/:\${COSMOSIS_SRC_DIR}/cosmosis-standard-library/likelihood/planck2015/plc-2.0/lib/:\${DYLD_LIBRARY_PATH} | |
export LD_LIBRARY_PATH=\${COSMOSIS_SRC_DIR}/cosmosis/datablock/:\${COSMOSIS_SRC_DIR}/cosmosis-standard-library/likelihood/planck/plc-1.0/lib/:\${COSMOSIS_SRC_DIR}/cosmosis-standard-library/likelihood/planck2015/plc-2.0/lib/:\${LD_LIBRARY_PATH} | |
export PYTHONPATH=\${COSMOSIS_SRC_DIR}:\${PYTHONPATH} | |
export PATH=\${COSMOSIS_SRC_DIR}/bin:/path/to/gcc:/path/to/python/:\${PATH} | |
alias cd_cosmosis="cd \${COSMOSIS_SRC_DIR}" | |
EOF | |
# load the new setup script | |
source setup-my-cosmosis | |
# link setup script to run when environment is activated | |
mkdir -p ${CONDA_PREFIX}/etc/conda/activate.d | |
ln -s ${COSMOSIS_SRC_DIR}/setup-my-cosmosis ${CONDA_PREFIX}/etc/conda/activate.d/cosmosis.sh | |
# build cosmosis | |
make | |
# all done! | |
cat << EOF | |
--- | |
activate the new environment: | |
$ conda activate ${COSMOSIS_ENV} | |
change to the cosmosis source directory: | |
$ cd_cosmosis | |
run the first cosmosis demo: | |
$ cosmosis demos/demo1.ini | |
--- | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment