Repository navigation
Expand file tree
/
Copy pathlicorice_activate.sh
More file actions
124 lines (101 loc) · 2.75 KB
/
Copy pathlicorice_activate.sh
File metadata and controls
124 lines (101 loc) · 2.75 KB
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
# run via: source licorice_activate.sh
# this MUST be run from within the licorice repository directory
REPO_CHECK=1
if [ ! -d "examples" ] || [ ! -d "install" ] || [ ! -d "templating" ]
then
echo "This does not look like a LiCoRICE repository!"
REPO_CHECK=0
fi
if [ $REPO_CHECK -eq 1 ]
then
LICORICE_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
LICORICE_TEMPLATING_DIR=$LICORICE_ROOT/templating
LICORICE_EXEC_STR="sudo PYTHONHOME=$VIRTUAL_ENV taskset 0x1 nice -n -20 ./timer"
LICORICE_PS1_STR=LiCoRICE
EXPERIMENT_DIR=$LICORICE_ROOT/..
MODEL_DIR=$EXPERIMENT_DIR/models
BINARY_DIR=$EXPERIMENT_DIR/run/out
FILE_MODEL_NAME=$BINARY_DIR/model_name
# export env variables
export LICORICE_ROOT
export LICORICE_TEMPLATING_DIR
export LICORICE_EXEC_STR
export LICORICE_PS1_STR
export EXPERIMENT_DIR
export MODEL_DIR
export BINARY_DIR
export FILE_MODEL_NAME
# parse LiCoRICE model
licorice_parse_model() {
pushd $LICORICE_TEMPLATING_DIR
python lico_parse.py -m $MODEL_DIR/$1.yaml
popd
printf "%s" "$1" > $FILE_MODEL_NAME
}
# compile LiCoRICE model
licorice_compile_model() {
printf 'Compiling: %s\n\n' "`cat $FILE_MODEL_NAME`"
pushd $BINARY_DIR
make clean
make -j 2
popd
}
# run LiCoRICE model
licorice_run_model() {
printf 'Running: %s\n\n' "`cat $FILE_MODEL_NAME`"
pushd $BINARY_DIR
licorice_shm_clear
$LICORICE_EXEC_STR
popd
}
# remove any compiled binaries
licorice_wipe_binaries() {
if [ -n "$BINARY_DIR" ]
then
rm -rf $BINARY_DIR/*
else
echo "WARNING: Could not find binaries directory. Not wiping anything."
fi
}
# remove shm mappings
licorice_shm_clear() {
sudo rm -rf /dev/shm/*
}
# parse, compile, & run LiCoRICE model
licorice_go() {
licorice_wipe_binaries
licorice_parse_model $1
licorice_compile_model
licorice_run_model
}
# deactivate licorice environemnt
licorice_deactivate() {
PS1=${PS1:(${#LICORICE_PS1_STR}+3)}
unset LICORICE_ROOT
unset LICORICE_TEMPLATING_DIR
unset LICORICE_EXEC_STR
unset LICORICE_PS1_STR
unset EXPERIMENT_DIR
unset MODEL_DIR
unset BINARY_DIR
unset FILE_MODEL_NAME
unset -f licorice_parse_model
unset -f licorice_compile_model
unset -f licorice_run_model
unset -f licorice_wipe_binaries
unset -f licorice_shm_clear
unset -f licorice_go
unset -f licorice_deactivate
}
export LICORICE_ROOT
# export shell functions
export -f licorice_parse_model
export -f licorice_compile_model
export -f licorice_run_model
export -f licorice_wipe_binaries
export -f licorice_shm_clear
export -f licorice_go
# change prompt
PS1="[$LICORICE_PS1_STR] $PS1"
export PS1
fi