-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_conda.sh
193 lines (163 loc) · 4.59 KB
/
install_conda.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
# Dedalus stack builder using conda, with options for own MPI and FFTW.
# Run this file after installing conda and activating the base environment.
#############
## Options ##
#############
# Conda environment name
CONDA_ENV="pf"
# Skip conda prompts
CONDA_YES=1
# Quiet conda output
CONDA_QUIET=1
# Install openmpi from conda, otherwise MPI_PATH must be set
INSTALL_MPI=1
#MPI_PATH=
# Install fftw from conda, otherwise FFTW_PATH must be set
INSTALL_FFTW=1
#FFTW_PATH=
# Install hdf5 from conda, otherwise HDF5_DIR must be set
INSTALL_HDF5=1
#HDF5_DIR=
# BLAS options for numpy/scipy: "openblas" or "mkl"
BLAS="openblas"
############
## Script ##
############
# Custom conda package installs here
conda install -y jupyter
conda install -y matplotlib
conda install -c conda-forge nb_conda_kernels
# Check requirements
if [ "${CONDA_DEFAULT_ENV}" != "base" ]
then
>&2 echo "ERROR: Conda base environment must be activated"
exit 1
fi
if [ ${INSTALL_MPI} -ne 1 ]
then
if [ -z ${MPI_PATH} ]
then
>&2 echo "ERROR: MPI_PATH must be set"
exit 1
else
echo "MPI_PATH set to '${MPI_PATH}'"
fi
fi
if [ ${INSTALL_FFTW} -ne 1 ]
then
if [ -z ${FFTW_PATH} ]
then
>&2 echo "ERROR: FFTW_PATH must be set"
exit 1
else
echo "FFTW_PATH set to '${FFTW_PATH}'"
fi
fi
if [ ${INSTALL_HDF5} -ne 1 ]
then
if [ -z ${HDF5_DIR} ]
then
>&2 echo "ERROR: HDF5_DIR must be set"
exit 1
else
echo "HDF5_DIR set to '${HDF5_DIR}'"
fi
fi
prompt_to_proceed () {
while true; do
read -p "Proceed ([y]/n)? " proceed
case "${proceed}" in
"y" | "") break ;;
"n") exit 1 ;;
*) ;;
esac
done
}
CARGS=(-n ${CONDA_ENV})
if [ ${CONDA_YES} -eq 1 ]
then
CARGS+=(-y)
fi
if [ ${CONDA_QUIET} -eq 1 ]
then
CARGS+=(-q)
fi
echo "Setting up conda with 'source ${CONDA_PREFIX}/etc/profile.d/conda.sh'"
source ${CONDA_PREFIX}/etc/profile.d/conda.sh
echo "Preventing conda from looking in ~/.local with 'export PYTHONNOUSERSITE=1'"
export PYTHONNOUSERSITE=1
echo "Preventing conda from looking in PYTHONPATH with 'unset PYTHONPATH'"
unset PYTHONPATH
# Check if conda environment exists
conda activate ${CONDA_ENV} >&/dev/null
if [ $? -eq 0 ]
then
echo "WARNING: Conda environment '${CONDA_ENV}' already exists"
prompt_to_proceed
else
echo "Building new conda environment '${CONDA_ENV}'"
conda create "${CARGS[@]}" -c conda-forge python=3.6
conda activate ${CONDA_ENV}
fi
echo "Updating conda-forge pip, setuptools, cython"
conda install "${CARGS[@]}" -c conda-forge pip setuptools cython
case "${BLAS}" in
"openblas")
echo "Installing conda-forge openblas, numpy, scipy"
conda install "${CARGS[@]}" -c conda-forge numpy=*=*openblas* scipy=*=*openblas*
# Dynamically link FFTW
export FFTW_STATIC=0
;;
"mkl")
echo "Installing defaults numpy, scipy"
conda install "${CARGS[@]}" -c defaults numpy scipy
# Statically link FFTW to avoid MKL symbols
export FFTW_STATIC=1
;;
*)
>&2 echo "ERROR: BLAS must be 'openblas' or 'mkl'"
exit 1
;;
esac
#if [ ${INSTALL_MPI} -eq 1 ]
#then
# echo "Installing conda-forge openmpi, mpi4py"
# conda install "${CARGS[@]}" -c conda-forge openmpi mpi4py
#else
# echo "Not installing openmpi"
# echo "Installing mpi4py with pip"
# # Make sure mpicc will appear on path
# export PATH=${MPI_PATH}/bin:${PATH}
# # no-cache to avoid wheels from previous pip installs
# python3 -m pip install --no-cache mpi4py
#fi
# Install MPI the normal way; ${CARGS{@}} seems to fuck it up
# so just make sure you grab it from the correct channel
conda install -c conda-forge -y openmpi
conda install -c conda-forge -y mpi4py
if [ ${INSTALL_FFTW} -eq 1 ]
then
echo "Installing cryoem fftw-mpi"
# no-deps to avoid pulling cryoem openmpi
conda install "${CARGS[@]}" -c cryoem --no-deps fftw-mpi
else
echo "Not installing fftw"
fi
if [ ${INSTALL_HDF5} -eq 1 ]
then
echo "Installing conda-forge hdf5, h5py"
conda install "${CARGS[@]}" -c conda-forge hdf5 h5py
else
echo "Not installing hdf5"
echo "Installing h5py with pip"
# no-cache to avoid wheels from previous pip installs
# no-binary to build against linked hdf5
python3 -m pip install --no-cache --no-binary=h5py h5py
fi
echo "Installing conda-forge docopt, matplotlib"
conda install "${CARGS[@]}" -c conda-forge docopt matplotlib
echo "Installing dedalus with pip"
# no-cache to get latest version
python3 -m pip install --no-cache --pre dedalus
echo "Installation complete in conda environment '${CONDA_ENV}'"
conda deactivate