Skip to content
Snippets Groups Projects
slurm_calibrate.sh 1.68 KiB
Newer Older
Steffen Hauf's avatar
Steffen Hauf committed
#!/bin/bash

# set paths to use
nb_path=$1
python_path=$2
ipcluster_profile=$3
notebook=$4
detector=$5
caltype=$6
final=$7
finalize=$8
cluster_cores=$9
Steffen Hauf's avatar
Steffen Hauf committed

echo "Running with the following parameters:"
echo "Notebook path: $nb_path"
echo "Python path: $python_path"
echo "IP-Cluster profile: $ipcluster_profile"
echo "notebook: $notebook"
echo "detector: $detector"
echo "caltype: $caltype"
echo "final: $final"
echo "finalize: $finalize"
echo "cluster_cores: $cluster_cores"
echo "job ID: $SLURM_JOB_ID"
Steffen Hauf's avatar
Steffen Hauf committed

export CAL_NOTEBOOK_NAME=$notebook

# set-up enviroment
source /etc/profile.d/modules.sh
module load anaconda/3
module load texlive/2019
Steffen Hauf's avatar
Steffen Hauf committed

echo "Starting influx feeder"
./cal_influx_feeder.sh $notebook $detector $caltype > /dev/null 2>&1  &

Steffen Hauf's avatar
Steffen Hauf committed
# make sure we use agg backend
export MPLBACKEND=AGG

# start an ip cluster if requested
Thomas Kluyver's avatar
Thomas Kluyver committed
if [ "${ipcluster_profile}" != "NO_CLUSTER" ]
Steffen Hauf's avatar
Steffen Hauf committed
then
    ${python_path} -m IPython profile create ${ipcluster_profile} --parallel
    ${python_path} -m ipyparallel.cluster start --n=${cluster_cores} --profile=${ipcluster_profile} --daemonize &
Steffen Hauf's avatar
Steffen Hauf committed
    sleep 15
fi


echo "Running notebook"
${python_path} -m princess ${nb_path} --save --on-error-resume-next
${python_path} -m nbconvert --to rst --TemplateExporter.exclude_input=True ${nb_path}
Steffen Hauf's avatar
Steffen Hauf committed

# stop the cluster if requested
Thomas Kluyver's avatar
Thomas Kluyver committed
if [ "${ipcluster_profile}" != "NO_CLUSTER" ]
Steffen Hauf's avatar
Steffen Hauf committed
then
    ${python_path} -m ipyparallel.cluster stop --profile=${ipcluster_profile}
    profile_path=$(${python_path} -m IPython locate profile ${ipcluster_profile})
Steffen Hauf's avatar
Steffen Hauf committed
    echo "Removing cluster profile from: $profile_path"
    rm -rf $profile_path
fi

if [ "${final}" == "FINAL" ]
Steffen Hauf's avatar
Steffen Hauf committed
then
   ${python_path} ${finalize} $SLURM_JOB_ID
Steffen Hauf's avatar
Steffen Hauf committed
fi
Steffen Hauf's avatar
Steffen Hauf committed
killall -9 cal_influx_feeder.sh || true