-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-session.sh
executable file
·87 lines (56 loc) · 1.81 KB
/
run-session.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
#!/bin/bash
GITHUB_USERNAME="QUMIA"
GITHUB_REPOSITORY="train-scripts"
OUTPUT_DIR="/projects/0/einf6214/output/"
### Label ###
# Check if a label is provided
if [ "$#" -ne 1 ]; then
echo "Error: A label argument is required."
exit 1
fi
# The label is the first argument
LABEL=$1
# Check if the label contains invalid characters
if echo "$LABEL" | grep -q "[/:*?\"<>|\]"; then
echo "Error: The label contains invalid characters for a file name."
exit 1
fi
### Convert notebook ###
./convert-notebook.sh train.ipynb
### git commit ###
# Check for untracked files (we don't want to automatically add these, but they may be required)
untracked_files=$(git ls-files --others --exclude-standard)
if [ -n "$untracked_files" ]; then
echo "There are untracked files:"
echo "$untracked_files"
exit 1
fi
# Add all changes
git add .
# Create a new git commit with the label
git commit -m "[SESSION] $LABEL" --allow-empty
### Prepare output directory ###
# Create an output directory with the current date and time
OUTPUT_DIR="${OUTPUT_DIR}/$(date +%Y-%m-%d_%H-%M-%S)_${LABEL}"
mkdir "$OUTPUT_DIR"
# Copy the contents of the current directory to the output directory
cp -r ./* "$OUTPUT_DIR"
# Clean the output's output directory
if [ -d "$OUTPUT_DIR/output" ]; then
rm -rf "$OUTPUT_DIR/output"/*
fi
# Get the SHA of the latest commit
COMMIT_SHA=$(git rev-parse HEAD)
# Construct the GitHub commit link
GITHUB_COMMIT_URL="https://github.com/${GITHUB_USERNAME}/${GITHUB_REPOSITORY}/commit/${COMMIT_SHA}"
### Write details to .env ###
cat <<EOF > "$OUTPUT_DIR/.env"
SESSION_LABEL=$LABEL
GIT_SHA=$COMMIT_SHA
GITHUB_COMMIT_URL=$GITHUB_COMMIT_URL
EOF
### Queue the job ###
# Queue the train job inside the output directory (we want to have the log there also)
cd "$OUTPUT_DIR"
sbatch train-job.sh
echo Done