From 6c0d1cc44f41a6edba3af72e3c45349ed29e9398 Mon Sep 17 00:00:00 2001 From: Max Liu Date: Thu, 22 Mar 2018 14:09:19 -0400 Subject: [PATCH] New local testing workflow --- local/install_local.sh | 117 +++++++++++++++++++++++++++++++++++++++++ local/run.sh | 66 +++++++++++++++++++++++ local/run_job.sh | 100 +++++++++++++++++++++++++++++++++++ local/submit.sl | 39 ++++++++++++++ local/submit_job.sl | 8 +++ local/thermo_val.sh | 46 ++++++++++++++++ 6 files changed, 376 insertions(+) create mode 100644 local/install_local.sh create mode 100644 local/run.sh create mode 100644 local/run_job.sh create mode 100644 local/submit.sl create mode 100644 local/submit_job.sl create mode 100644 local/thermo_val.sh diff --git a/local/install_local.sh b/local/install_local.sh new file mode 100644 index 00000000..542dac54 --- /dev/null +++ b/local/install_local.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +# Exit immediately on failure +set -e + +################### +# BENCHMARK SETUP # +################### + +# Prepare temporary directory for benchmark RMG-Py and RMG-db +benchmark=$DATA_DIR/code/benchmark/$(date +%Y-%m-%d:%H:%M:%S) +rm -rf $benchmark +mkdir -p $benchmark +cd $benchmark + +# Prepare benchmark RMG-Py +git clone -q https://github.com/ReactionMechanismGenerator/RMG-Py.git +cd RMG-Py +git checkout $RMGPY_BENCHMARK_BRANCH +export benchmark_py_sha=$(git rev-parse HEAD) +cd .. + +# Prepare benchmark RMG-database: +git clone -q https://github.com/ReactionMechanismGenerator/RMG-database.git +cd RMG-database +git checkout $RMGDB_BENCHMARK_BRANCH +export benchmark_db_sha=$(git rev-parse HEAD) + +# Rename benchmark code folder +cd $DATA_DIR/code/benchmark + +export benchmark_tag=py${benchmark_py_sha:0:12}_db${benchmark_db_sha:0:12} + +if [ ! -d "${benchmark_tag}" ]; then + mv $benchmark $benchmark_tag +else + rm -rf $benchmark +fi + +export benchmark=$DATA_DIR/code/benchmark/$benchmark_tag + +# Prepare benchmark environment if requested +if [ "$CLEAN_ENV" == true ]; then + cd $benchmark/RMG-Py + export benchmark_env="benchmark_env" + conda remove --name $benchmark_env --all -y + conda env create -n $benchmark_env -f environment_${CURRENT_OS}.yml +else + export benchmark_env="rmg_env" +fi + +# Compile benchmark RMG-Py: +cd $benchmark/RMG-Py +source activate $benchmark_env +make +source deactivate + +export RMG_BENCHMARK=$benchmark/RMG-Py +export RMGDB_BENCHMARK=$benchmark/RMG-database + +################# +# TESTING SETUP # +################# + +# Prepare temporary directory for testing RMG-Py and RMG-db +testing=$DATA_DIR/code/testing/$(date +%Y-%m-%d:%H:%M:%S) +rm -rf $testing +mkdir -p $testing +cd $testing + +# Prepare testing RMG-Py: +git clone -q https://github.com/ReactionMechanismGenerator/RMG-Py.git +cd RMG-Py +git checkout ${RMG_TESTING_BRANCH} +export testing_py_sha=$(git rev-parse HEAD) +cd .. + +# Prepare testing RMG-database +git clone -q https://github.com/ReactionMechanismGenerator/RMG-database.git +cd RMG-database +git checkout ${RMGDB_TESTING_BRANCH} +export testing_db_sha=$(git rev-parse HEAD) + +# Rename testing code folder +cd $DATA_DIR/code/testing + +export testing_tag=py${testing_py_sha:0:12}_db${testing_db_sha:0:12} + +if [ ! -d "${testing_tag}" ]; then + mv $testing $testing_tag +else + rm -rf $testing +fi +export testing=$DATA_DIR/code/testing/$testing_tag + +# Prepare testing environment if requested +if [ "$SEPARATE_ENV" == true]; then + cd $testing/RMG-Py + export testing_env="testing_env" + conda remove --name $testing_env --all -y + conda env create -n $testing_env -f environment_${CURRENT_OS}.yml +else + export testing_env=$benchmark_env +fi + +# Compile RMG-Py: +cd $testing/RMG-Py +source activate $testing_env +make +source deactivate + +export RMG_TESTING=$testing/RMG-Py +export RMGDB_TESTING=$testing/RMG-database + +# Go to RMG-tests folder: +cd $DATA_DIR + diff --git a/local/run.sh b/local/run.sh new file mode 100644 index 00000000..b6ded6b1 --- /dev/null +++ b/local/run.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Set RMG-tests base directory +export BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" +echo "Local tests base dir: "$BASE_DIR + +# Set data directory +export DATA_DIR=$BASE_DIR/data_dir + +# Figure out OS +if [[ $MACHTYPE == *"apple"* ]]; then + export CURRENT_OS="mac" +elif [[ $MACHTYPE == *"linux"* ]]; then + export CURRENT_OS="linux" +else + echo "$MACHTYPE not supported. Exiting..." + exit 0 +fi +echo "Current OS: "$CURRENT_OS + +# Print input settings +echo "Benchmark Branches:" +echo " RMG-Py: "$RMGPY_BENCHMARK_BRANCH +echo " RMG-database: "$RMGDB_BENCHMARK_BRANCH +echo "Testing Branches:" +echo " RMG-Py: "$RMGPY_TESTING_BRANCH +echo " RMG-database: "$RMGDB_TESTING_BRANCH +echo "Testing Jobs: "$JOBS +echo "Data Directory: "$DATA_DIR + +. $BASE_DIR/color_define.sh +. $BASE_DIR/local/install_local.sh +. $BASE_DIR/version_summary.sh + +echo "INSTALLATION COMPLETE" + +cd $BASE_DIR/local + +# Run RMG test jobs +if [ $JOBS == "all" ]; then + for i in eg1 eg3 eg5 eg6 eg7 NC solvent_hexane MCH + do + if [ $PARALLEL == "true" ]; then + export SBATCH_JOB_NAME=run_$i + sbatch $BASE_DIR/local/submit_job.sl $i no + else + . $BASE_DIR/local/run_job.sh $i no + fi + done +else + if [ $PARALLEL == "true" ]; then + export SBATCH_JOB_NAME=run_$i + sbatch $BASE_DIR/local/submit_job.sl $JOBS no + else + . $BASE_DIR/local/run_job.sh $JOBS no + fi +fi + +# Run thermo validation jobs +if [ $THERMOVAL == "true" ]; then + for i in hc_cyclics hco_cyclics rmg_internal_cyclics + do + . $BASE_DIR/local/thermo_val.sh $i + done +fi + diff --git a/local/run_job.sh b/local/run_job.sh new file mode 100644 index 00000000..7acb1f67 --- /dev/null +++ b/local/run_job.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +job=$1 +scoop_test=$2 + +set -e + +if [ -z ${RMG_BENCHMARK+x} ]; then + echo "RMG variable is unset. Exiting..." + exit 0 +fi + +export ORIGIN_PYTHONPATH=$PYTHONPATH +echo "Running Job: $1" + +############# +# BENCHMARK # +############# + +# Make folder for models generated by the benchmark version of RMG-Py/RMG-database: +export benchmark_tests=$DATA_DIR/tests/benchmark/$benchmark_tag +mkdir -p $benchmark_tests/rmg_jobs/$job +rm -rf $benchmark_tests/rmg_jobs/$job/* +cp $BASE_DIR/examples/rmg/$job/input.py $benchmark_tests/rmg_jobs/$job/input.py + +source activate ${benchmark_env} + +echo "Benchmark Version of RMG: "$RMG_BENCHMARK +export PYTHONPATH=$RMG_BENCHMARK:$ORIGIN_PYTHONPATH + +python $RMG_BENCHMARK/rmg.py $benchmark_tests/rmg_jobs/$job/input.py > /dev/null + +source deactivate +export PYTHONPATH=$ORIGIN_PYTHONPATH + +########### +# TESTING # +########### + +# Make folder for models generated by the test version of RMG-Py and RMG-database: +export testing_tests=$DATA_DIR/tests/testing/$testing_tag +mkdir -p $testing_tests/rmg_jobs/$job +rm -rf $testing_tests/rmg_jobs/$job/* +cp $BASE_DIR/examples/rmg/$job/input.py $testing_tests/rmg_jobs/$job/input.py + +source activate ${testing_env} + +echo "Test Version of RMG: "$RMG_TESTING +export PYTHONPATH=$RMG_TESTING:$ORIGIN_PYTHONPATH + +python $RMG_TESTING/rmg.py $testing_tests/rmg_jobs/$job/input.py > /dev/null + +export PYTHONPATH=$ORIGIN_PYTHONPATH +source deactivate + +########### +# COMPARE # +########### + +export check_tests=$DATA_DIR/tests/check/$testing_tag +mkdir -p $check_tests/rmg_jobs/$job +rm -rf $check_tests/rmg_jobs/$job/* +cd $check_tests/rmg_jobs/$job + +source activate ${benchmark_env} +export PYTHONPATH=$RMG_BENCHMARK:$ORIGIN_PYTHONPATH + +bash $BASE_DIR/check.sh $job $benchmark_tests/rmg_jobs/$job $testing_tests/rmg_jobs/$job + +export PYTHONPATH=$ORIGIN_PYTHONPATH +source deactivate + +if [ $scoop_test == "yes" ]; then + # Make folder for models generated by the test version of RMG-Py and RMG-database, with scoop enabled: + mkdir -p $testing_tests/rmg_jobs/$job/scoop + rm -rf $testing_tests/rmg_jobs/$job/scoop/* + cp $BASE_DIR/examples/rmg/$job/input.py $testing_tests/rmg_jobs/$job/scoop/input.py + echo "Version of RMG running with SCOOP: $RMG" + source activate ${testing_env} + export PYTHONPATH=$RMG_TESTING:$ORIGIN_PYTHONPATH + + python -m scoop -n 1 $RMG_TESTING/rmg.py $testing_tests/rmg_jobs/$job/scoop/input.py > /dev/null + + export PYTHONPATH=$ORIGIN_PYTHONPATH + source deactivate + + # compare both generated models + mkdir -p $check_tests/rmg_jobs/$job/scoop + cd $check_tests/rmg_jobs/$job/scoop + source activate ${benchmark_env} + export PYTHONPATH=$RMG_BENCHMARK:$ORIGIN_PYTHONPATH + + bash $BASE_DIR/check.sh $job $benchmark_tests/rmg_jobs/$job $testing_tests/rmg_jobs/$job/scoop + + export PYTHONPATH=$ORIGIN_PYTHONPATH + source deactivate +fi + +echo "$job: TEST JOB COMPLETE" + diff --git a/local/submit.sl b/local/submit.sl new file mode 100644 index 00000000..c0e28356 --- /dev/null +++ b/local/submit.sl @@ -0,0 +1,39 @@ +#!/bin/bash +#SBATCH -p debug +#SBATCH -J RMG-test +#SBATCH -n 1 +#SBATCH --nodelist=node03 +#SBATCH --output=main_log.out + +# Usage: sbatch submit.sl + +# Specify testing branches here +RMGPY_TESTING_BRANCH="test_branch" +RMGDB_TESTING_BRANCH="master" + +# Specify benchmark branches here +# These should generally be left as master +RMGPY_BENCHMARK_BRANCH="master" +RMGDB_BENCHMARK_BRANCH="master" + +# Specify jobs to run +# Current jobs available: eg1, eg3, eg5, eg6, eg7, NC, solvent_hexane, MCH, methane +JOBS="all" + +# Specify whether to run thermo validation +THERMOVAL=true + +# Specify whether or not to recreate the Anaconda environment +# This is generally not necessary, and can be left as false +CLEAN_ENV=false + +# Specify whether or not the testing and benchmark jobs should use separate environments +# This is generally not necessary, and can be left as false +SEPARATE_ENV=false + +# Specify whether to run jobs in parallel or serial +PARALLEL=true + +# Start the job +. ./run.sh + diff --git a/local/submit_job.sl b/local/submit_job.sl new file mode 100644 index 00000000..3a27c4e3 --- /dev/null +++ b/local/submit_job.sl @@ -0,0 +1,8 @@ +#!/bin/bash +#SBATCH -p debug +#SBATCH -n 1 + +JOB=$1 +SCOOP=$2 + +. $BASE_DIR/local/run_job.sh $JOB $SCOOP diff --git a/local/thermo_val.sh b/local/thermo_val.sh new file mode 100644 index 00000000..50aebc3a --- /dev/null +++ b/local/thermo_val.sh @@ -0,0 +1,46 @@ +#!/bin/bash +job=$1 + +export ORIGIN_PYTHONPATH=$PYTHONPATH + +############# +# BENCHMARK # +############# + +# Make folder for models generated by the benchmark version of RMG-Py/RMG-database: +export benchmark_tests=$DATA_DIR/tests/benchmark/$benchmark_tag +mkdir -p $benchmark_tests/thermo_val_jobs/$job + +cp $BASE_DIR/examples/thermo_val/$job/dataset.txt $benchmark_tests/thermo_val_jobs/$job/dataset.txt + +echo "Benchmark Version of RMG: "$RMG_BENCHMARK +echo "Running thermo validation on benchmark version..." + +source activate ${benchmark_env} +export PYTHONPATH=$RMG_BENCHMARK:$ORIGIN_PYTHONPATH + +python $BASE_DIR/thermo_val/evaluate.py -d $benchmark_tests/thermo_val_jobs/$job/dataset.txt -pb $RMGPY_BENCHMARK_BRANCH -dbb $RMGDB_BENCHMARK_BRANCH -psha ${benchmark_py_sha} -dbsha ${benchmark_db_sha} + +source deactivate +export PYTHONPATH=$ORIGIN_PYTHONPATH + +########### +# TESTING # +########### + +# Make folder for models generated by the test version of RMG-Py and RMG-database: +export testing_tests=$DATA_DIR/tests/testing/$testing_tag +mkdir -p $testing_tests/thermo_val_jobs/$job + +cp $BASE_DIR/examples/thermo_val/$job/dataset.txt $testing_tests/thermo_val_jobs/$job/dataset.txt + +echo "Testing Version of RMG: "$RMG_TESTING +echo "Running thermo validation on testing version..." + +source activate ${testing_env} +export PYTHONPATH=$RMG_TESTING:$ORIGIN_PYTHONPATH + +python $BASE_DIR/thermo_val/evaluate.py -d $testing_tests/thermo_val_jobs/$job/dataset.txt -pb $RMGPY_TESTING_BRANCH -dbb $RMGDB_TESTING_BRANCH -psha ${testing_py_sha} -dbsha ${testing_db_sha} + +source deactivate +export PYTHONPATH=$ORIGIN_PYTHONPATH