Skip to content

Commit 50bffdf

Browse files
committed
adds yaml parsing and optional build argument to not start with a clone of the srbench base environment
1 parent e30b47b commit 50bffdf

File tree

4 files changed

+85
-27
lines changed

4 files changed

+85
-27
lines changed

algorithms/feat/environment.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ channels:
44
dependencies:
55
- python=3.10
66
- cmake
7-
- gcc
8-
- gxx
7+
# - gcc
8+
# - gxx
99
- ninja
1010
- eigen
1111
- shogun-cpp=6.1.4

algorithms/feat/metadata.yml

+5
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ description: | # anything you'd like here to describe the method.
1111
ICLR 2019. arxiv:1807.0091
1212
1313
url: http://cavalab.org/feat # a link to the project
14+
########################################
15+
# Option arguments for the build process.
16+
# Unless you know what you are doing, do not change these.
17+
build:
18+
clone_base_env: yes #
1419

configure.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# install conda environment
2-
conda env create -f environment.yml
1+
# install base srbench environment
2+
conda env create -f base_environment.yml
33

44
eval "$(conda shell.bash hook)"
55

install.sh

+76-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
# note: make sure conda srbench environment is installed
22
set -e
33

4+
# script to read yaml
5+
function parse_yaml {
6+
local prefix=$2
7+
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
8+
sed -ne "s|^\($s\):|\1|" \
9+
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
10+
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
11+
awk -F$fs '{
12+
indent = length($1)/2;
13+
vname[indent] = $2;
14+
for (i in vname) {if (i > indent) {delete vname[i]}}
15+
if (length($3) > 0) {
16+
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
17+
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
18+
}
19+
}'
20+
}
21+
22+
# install base srbench environment if it doesn't exist
23+
if conda info --envs | grep srbench | grep -v "srbench-"; then
24+
echo "existing base srbench environment (not installing)";
25+
else
26+
echo "installing base srbench environment"
27+
28+
mamba env create -y -f base_environment.yml
29+
30+
eval "$(conda shell.bash hook)"
31+
32+
conda init bash
33+
fi
34+
35+
36+
437
if (($#==1)); #check if number of arguments is 1
538
then
639
subnames=($1)
@@ -13,56 +46,76 @@ succeeded=()
1346

1447
# install methods
1548
echo "////////////////////////////////////////"
16-
echo "installing SR methods..."
49+
echo "installing these SR methods:"
1750
echo ${subnames}
1851
echo "////////////////////////////////////////"
1952

2053
# install all methods
2154
for SUBNAME in ${subnames[@]} ; do
2255

56+
build_clone_base_env="yes"
57+
2358
echo "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv"
2459
echo ".................... Installing $SUBNAME ..."
2560

2661
SUBFOLDER=algorithms/$SUBNAME
2762
SUBENV=srbench-$SUBNAME
28-
# install method
29-
# cd $SUBFOLDER
30-
pwd
31-
echo "Installing dependencies for ${SUBNAME}"
32-
echo "........................................"
33-
echo "Making environment"
34-
echo "........................................"
35-
# conda create --name $SUBENV --clone srbench
36-
mamba env create --name $SUBENV -f base_environment.yml -f ${SUBFOLDER}/environment.yml
37-
# if test -f "environment.yml" ; then
38-
# echo "Update alg env from environment.yml"
39-
# echo "........................................"
40-
# mamba env update -n $SUBENV -f ${SUBFOLDER}/environment.yml
41-
# fi
42-
43-
if test -f "requirements.txt" ; then
63+
64+
########################################
65+
# read yaml
66+
eval $(parse_yaml $SUBFOLDER/metadata.yml)
67+
########################################
68+
69+
if [ "${build_clone_base_env}" == "yes" ] ; then
70+
echo "$build_clone_base_env" is set to yes
71+
72+
echo "........................................"
73+
echo "Cloning base environment"
74+
echo "........................................"
75+
76+
if conda info --envs | grep -q $SUBENV ; then
77+
echo "not cloning base because ${SUBENV} already exists"
78+
else
79+
conda create --name $SUBENV --clone srbench
80+
# update from base environment
81+
if test -f "${SUBFOLDER}/environment.yml" ; then
82+
echo "Update alg env from environment.yml"
83+
echo "........................................"
84+
mamba env update -n $SUBENV -f ${SUBFOLDER}/environment.yml
85+
fi
86+
fi
87+
else
88+
89+
echo "........................................"
90+
echo "Creating environment ${SUBENV} from scratch"
91+
echo "........................................"
92+
mamba create -n $SUBENV -f ${SUBFOLDER}/environment.yml
93+
fi
94+
95+
96+
if test -f "${SUBFOLDER}/requirements.txt" ; then
4497
echo "Update alg env from requirements.txt"
4598
echo "........................................"
4699
mamba run -n srbench-${SUBENV} pip install -r ${SUBFOLDER}/requirements.txt
47100
fi
48101

49-
eval "$(conda shell.bash hook)"
50-
conda init bash
51-
conda activate $SUBENV
102+
# eval "$(conda shell.bash hook)"
103+
# conda init bash
104+
# conda activate $SUBENV
52105
cd $SUBFOLDER
53106
if test -f "install.sh" ; then
54107
echo "running install.sh..."
55108
echo "........................................"
56-
bash install.sh
109+
mamba run -n $SUBENV bash install.sh
57110
else
58111
echo "::warning::No install.sh file found in ${SUBFOLDER}."
59112
echo " Assuming the method is a conda package specified in environment.yml."
60113
fi
61114
cd ../../
62115

63116
# Copy files and environment
64-
# echo "Copying files and environment to experiment/methods ..."
65-
# echo "........................................"
117+
echo "Copying files and environment to experiment/methods ..."
118+
echo "........................................"
66119
# cd ../../
67120
mkdir -p experiment/methods/$SUBNAME
68121
cp $SUBFOLDER/regressor.py experiment/methods/$SUBNAME/

0 commit comments

Comments
 (0)