-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconda_env_installer.bash
81 lines (65 loc) · 2.61 KB
/
conda_env_installer.bash
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
#!/bin/bash
# Copyright (c) 2025, Amogh S. Joshi
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# FILENAME: conda_env_installer
# necessary loading. DO NOT MODIFY
source config_rcac.bash
# system constants. DO NOT CHANGE
USER=$(whoami)
FLAG=false
# usage help message
usage() {
echo "usage: $0 [-h] [-f YML_FILENAME] [-p YML_PATH] [-n ENV_NAME]" 1>&2;
echo "-h: Display help message"
echo "-f YML_FILENAME: Name of env yml file. Defaults to 'environment.yml'"
echo "-p YML_PATH: Path to yml file. Defaults to '${HOME}/rcac-utils'"
echo "-n ENV_NAME: Name of env to be created. Defaults to 'environment'"
exit 1;
}
# arg init
YML_FILENAME=environment.yml
YML_PATH=$HOME/rcac-utils
ENV_NAME=environment
# read args
while getopts "hf:p:n:" opts; do
case "${opts}" in
h) usage;;
f) YML_FILENAME=$OPTARG;;
p) YML_PATH=$OPTARG;;
n) ENV_NAME=$OPTARG;;
*) usage;;
esac
done
# navigate to home dir
cd $HOME
if [ -d "anaconda3" ]; then
read -p " $( echo -e "[${yellow}WARNING${nc}] Anaconda installation found! This conflicts with Lmod module conda and causes job failures. Should it be deleted? (y/n) ")" confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || FLAG=true
if $FLAG; then
exit 1
fi
# remove custom anaconda dir
rm -rf $HOME/anaconda3/
# remove old conda installation scripts (if any)
rm -f $HOME/Anaconda*.bash
fi
# import lmod conda module
module load conda
# import lmod cuda module to ensure the correct version of pytorch gets installed
module load cuda
# create env
conda env create -n $ENV_NAME --file $YML_PATH/${YML_FILENAME}
echo -e "[${green}DONE${nc}]"