-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.sh
executable file
·413 lines (362 loc) · 11 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/bin/bash
# This script installs all dependencies and sets up a conda environment.
# The user must have the loadable kernel modules 'intel' and 'mkl' installed
#
# Author: Andreas Nygaard (2022)
NO='\033[0;31mno\033[0m'
YES='\033[0;32myes\033[0m'
echo -e "--------------------------------------------------------------\n\n"
cat source/assets/logo_colour.txt
echo -e "\n--------------------------------------------------------------\n"
echo -e "Running setup script for connect\n"
echo -e "The following things can be done (but can also be skipped):"
echo -e " - create conda environment with all dependencies"
echo -e " - install and setup Monte Python or use previous installation"
echo -e " - install and setup CLASS or use previous installation"
echo -e " - install Cobaya and CAMB (in environment)\n\n"
echo -e "--------------------------------------------------------------\n\n"
while [ -z $create_env ]
do
echo "Creating conda environment. Proceed? [yes, skip]"
read create_env
done
if [ $create_env == "yes" ]
then
echo "Enter name of conda environment to create, or leave blank to use"
echo "default name 'ConnectEnvironment':"
read env_name
if [ -z $env_name ]
then
env_name="ConnectEnvironment"
fi
fi
if ! [ $create_env == "yes" ]
then
echo "Enter name of conda environment to use, or leave blank to not use"
echo "an environment:"
read env_name
fi
while [ -z $setup_mp ]
do
echo "Do you want to use Monte Python with CONNECT? [yes, no]"
read setup_mp
echo "Do you want to install MultiNest and PolyChord? [yes, no]"
read MN_PC
done
if [ $setup_mp == "yes" ]
then
echo "Enter absolute path to montepython_public, or leave blank to"
echo "download and install it here:"
read montepython_path
echo "Enter absolute path to clik data (../code/plc_3.0/plc-3.01/),"
echo "or leave blank to download and install it here:"
read clik_path
fi
while [ -z $cobaya ]
do
echo "Do you want to install Cobaya in the environment? [yes, no]"
read cobaya
done
if [ -z $clik_path ] && [ $cobaya == "yes" ] && [ $setup_mp != "yes" ]
then
echo "Enter absolute path to clik data (../code/plc_3.0/plc-3.01/),"
echo "or leave blank to download and install it here:"
read clik_path
fi
while [ -z $class ]
do
echo "Do you want to install CLASS in the environment? [yes, no]"
read class
done
if [ $class == "yes" ]
then
echo "If you already have a CLASS installation, enter the absolute"
echo "path. Otherwise, leave blank and CLASS repo will be cloned:"
read class_path
fi
while [ -z $camb ]
do
echo "Do you want to install CAMB in the environment? [yes, no]"
read camb
done
echo -e "\n--------------------------------------------------------------\n"
if [ $create_env == "yes" ]
then
Ans1=$YES
env_name_string="\n Name of conda environment:\n \033[0;34m${env_name}\033[0m"
else
Ans1=$NO
fi
if [ $setup_mp == "yes" ]
then
Ans2=$YES
if [ $MN_PC == "yes" ]
then
Ans2_1=$YES
else
Ans2_1=$NO
fi
if ! [ -z $clik_path ]
then
clik_mp="\n Path to clik:\n \033[0;34m${clik_path}\033[0m"
else
clik_mp="\n Downloading clik to \033[0;34mconnect/resources\033[0m"
fi
if ! [ -z $montepython_path ]
then
if [[ $montepython_path == *montepython_public/ ]]
then
montepython_path=${montepython_path::-1}
elif [[ $montepython_path == */ ]]
then
montepython_path="${montepython_path}montepython_public"
elif ! [[ $montepython_path == *montepython_public ]]
then
montepython_path="${montepython_path}/montepython_public"
fi
path_mp="\n Path to Monte Python:\n \033[0;34m${montepython_path}\033[0m"
else
path_mp="\n Cloning Monte Python repo to \033[0;34mconnect/resources\033[0m"
fi
else
Ans2=$NO
fi
if [ $cobaya == "yes" ]
then
Ans3=$YES
if ! [ $Ans2 == $YES ]
then
if ! [ -z $clik_path ]
then
clik_cobaya="\n Path to clik:\n \033[0;34m${clik_path}\033[0m"
else
clik_cobaya="\n Downloading clik to \033[0;34mconnect/resources\033[0m"
fi
fi
else
Ans3=$NO
fi
if [ $class == "yes" ]
then
Ans4=$YES
if ! [ -z $class_path ]
then
path_class="\n Path to CLASS:\n \033[0;34m${class_path}\033[0m"
else
path_class="\n Cloning CLASS repo to \033[0;34mconnect/resources\033[0m"
fi
else
Ans4=$NO
fi
if [ $camb == "yes" ]
then
Ans5=$YES
else
Ans5=$NO
fi
echo -e "You have selected the following:\n"
echo -e "Create conda environment : ${Ans1}${env_name_string}"
echo -e "Setup link to Monte Python : ${Ans2}${path_mp}${clik_mp}"
echo -e "Install MultiNest and PolyChord : ${Ans2_1}"
echo -e "Install Cobaya : ${Ans3}${clik_cobaya}"
echo -e "Install CLASS : ${Ans4}${path_class}"
echo -e "Install CAMB : ${Ans5}"
echo -e "\n--------------------------------------------------------------\n"
while [ -z $proceed ]
do
echo -e "\nProceed? [yes, abort]"
read proceed
done
if [ $proceed == "abort" ]
then
echo -e "\nYou have aborted the setup. Please try again\n"
exit 0
fi
##################################################################################
############################## Actual setup ##############################
##################################################################################
function install_clik {
connect_path=$PWD
mkdir -p resources
cd resources
rm -rf planck2018
mkdir planck2018
cd planck2018
echo "--> Downloading Planck likelihood code and data..."
for file in COM_Likelihood_Code-v3.0_R3.01.tar.gz COM_Likelihood_Data-baseline_R3.00.tar.gz COM_Likelihood_Data-baseline_R2.00.tar.gz
do
echo "Handling" ${file} "..."
curl https://pla.esac.esa.int/pla/aio/product-action?COSMOLOGY.FILE_ID=${file} --output ${file}
tar xf ${file}
done
echo "--> ...done!"
# Move 2015 data directory to the expected location
cp -r plc_2.0 code/plc_3.0/
rm -rf plc_2.0
echo "--> Downloading and installing cfitsio..."
cd code/plc_3.0/plc-3.01/
wget http://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio-3.47.tar.gz
tar xf cfitsio-3.47.tar.gz
# The gcc compiler which will be silently loaded alongside
# the intel compiler cannot compile cfitsio, so load later.
cd cfitsio-3.47
./configure
make -j
make install
cd ..
echo "--> ...done!"
cd $connect_path
clik_path="${PWD}/resources/planck2018/code/plc_3.0/plc-3.01/"
}
source ~/.bashrc 2> /dev/null
source ~/.bash_profile 2> /dev/null
source "$(conda info | grep -i 'base environment' | awk '{for(i=1;i<=NF;i++) if($i ~ /\//) print $i}')/etc/profile.d/conda.sh"
module load gcc openmpi cmake 2> /dev/null
conda init
if [ $Ans1 == $YES ]
then
echo "--> Creating Conda environment, this will take a few minutes..."
conda clean --index-cache -y
# Remove ConnectEnvironment if it exists
conda env remove -y --name $env_name
conda create -y --name $env_name python=3.10 cython=3.0 scipy=1.11 numpy=1.26 astropy=5.1 pip=23.2 numexpr=2.8 pandas=2.0
conda activate $env_name
export LD_LIBRARY_PATH=/lib64:$LD_LIBRARY_PATH
pip install matplotlib==3.7
pip install mpi4py==3.1.4
pip install tensorflow==2.10
pip install tensorflow-probability==0.18.0
pip install sshkeyboard
pip install playsound
if [ "$Ans2_1" == "$YES" ]
then
pip install pymultinest==2.12
pip install git+https:/PolyChord/PolyChordLite@master
fi
echo "--> ..done!"
fi
if [ $Ans2 == $YES ]
then
if [ -z $montepython_path ]
then
echo "--> Cloning Monte Python into resources..."
mkdir -p resources
cd resources
git clone -b 3.5 https:/brinckmann/montepython_public.git
cd ..
montepython_path="${PWD}/resources/montepython_public"
echo "--> ..done!"
if [ $Ans2_1 == $YES ]
then
echo "--> Installing MultiNest..."
cd resources
git clone https:/JohannesBuchner/MultiNest.git
rm -rf MultiNest/build/*
cd MultiNest/build
CC=gcc CXX=g++ cmake -D CMAKE_Fortran_COMPILER=gfortran ..
make
cd ../../..
echo "--> ...done!"
# Remember to add MultiNest to LD_LIBRARY_PATH when using
# export LD_LIBRARY_PATH=$PWD/MultiNest/lib/:$LD_LIBRARY_PATH
fi
fi
if [ -z $clik_path ]
then
install_clik
fi
echo "--> Installing Planck likelihood code..."
connect_path=$PWD
cd $clik_path
if ! [ -z $env_name ]
then
source activate $env_name
fi
./waf configure --lapack_mkl=$MKLROOT --cfitsio_prefix=$PWD/cfitsio-3.47
./waf install
cd $connect_path
echo "-->...done!"
echo "--> Linking Monte Python..."
cp mcmc_plugin/connect.conf.template mcmc_plugin/connect.conf
echo "path['cosmo'] = '${PWD}/mcmc_plugin'" > mcmc_plugin/connect.conf
echo "path['clik'] = '${clik_path}'" >> mcmc_plugin/connect.conf
echo "path['montepython'] = '${montepython_path}'" >> mcmc_plugin/connect.conf
cp -r mcmc_plugin/mp_likelihoods/Planck_lowl_EE_connect $montepython_path/montepython/likelihoods/
echo "--> ...done!"
fi
if [ $Ans3 == $YES ]
then
echo "--> Installing Cobaya..."
if ! [ -z $env_name ]
then
conda activate $env_name
fi
python -m pip install cobaya --upgrade
echo "--> ...done!"
if [ $Ans2 != $YES ]
then
if [ -z $clik_path ]
then
install_clik
fi
echo "--> Installing Planck likelihood code..."
connect_path=$PWD
cd $clik_path
./waf configure --lapack_mkl=$MKLROOT --cfitsio_prefix=$PWD/cfitsio-3.47
./waf install
cd $connect_path
echo "-->...done!"
fi
if ! [ -f "mcmc_plugin/connect.conf" ]
then
cp mcmc_plugin/connect.conf.template mcmc_plugin/connect.conf
fi
line1="path['cosmo'] = '${PWD}/mcmc_plugin'"
line2="path['clik'] = '${clik_path}'"
line3=$(grep -hr "montepython" mcmc_plugin/connect.conf)
echo $line1 > mcmc_plugin/connect.conf
echo $line2 >> mcmc_plugin/connect.conf
echo $line3 >> mcmc_plugin/connect.conf
fi
if [ $Ans4 == $YES ]
then
if ! [ -z $env_name ]
then
conda activate $env_name
fi
if ! [ -z $class_path ]
then
echo "--> Building classy wrapper..."
connect_path=$PWD
cd $class_path
make clean
make -j
cd $connect_path
echo "--> ...done!"
else
echo "--> Cloning CLASS into resources..."
mkdir -p resources
cd resources
git clone https:/lesgourg/class_public.git
cd class_public
git checkout aa92943e4ab86b56970953589b4897adf2bd0f99
echo "--> Building classy wrapper..."
sed -i 's/cpdef/cdef/g' python/classy.pyx
make clean
make -j
cd $connect_path
echo "--> ...done!"
fi
fi
if [ $Ans5 == $YES ]
then
echo "--> Installing CAMB..."
if ! [ -z $env_name ]
then
conda activate $env_name
fi
pip install camb --upgrade
echo "--> ...done!"
fi
python -c "from source.assets.animate import play; play()"
echo -e "\nSetup is all done!\n"