From de82cd166a40684261e97d7fb3064447caefdbdd Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Keck <Jean-Baptiste.Keck@imag.fr>
Date: Sun, 26 Jul 2020 02:20:19 +0200
Subject: [PATCH] test for checkpointing

---
 hysop/core/tests/test_checkpoint.sh | 158 ++++++++++++++++++++++++++++
 1 file changed, 158 insertions(+)
 create mode 100755 hysop/core/tests/test_checkpoint.sh

diff --git a/hysop/core/tests/test_checkpoint.sh b/hysop/core/tests/test_checkpoint.sh
new file mode 100755
index 000000000..e885b9c6e
--- /dev/null
+++ b/hysop/core/tests/test_checkpoint.sh
@@ -0,0 +1,158 @@
+#!/usr/bin/env bash
+set -feu -o pipefail
+PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE:-python2.7}
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+EXAMPLE_DIR="$(realpath ${SCRIPT_DIR}/../../../hysop_examples/examples)"
+
+
+function compare_files {
+    if [[ ! -f "$1" ]]; then
+        echo "File '${1}' does not exist."
+        exit 1
+    fi
+    if [[ ! -f "$2" ]]; then
+        echo "File '${2}' does not exist."
+        exit 1
+    fi
+    
+    # see https://stackoverflow.com/questions/3679296/only-get-hash-value-using-md5sum-without-filename
+    # for the bash array assignment trick (solution proposed by Peter O.)
+    A=($(sha1sum "${1}"))
+    B=($(sha1sum "${2}"))
+    if [[ "${A}" != "${B}" ]]; then
+        echo "Could not match checksums between ${1} and ${2}."
+        exit 1
+    fi
+}
+
+#
+# Basic test with 2D diffusion (serial)
+#
+#EXAMPLE_FILE="${EXAMPLE_DIR}/scalar_diffusion/scalar_diffusion.py"
+#TEST_DIR='/tmp/hysop_tests/checkpoints/scalar_diffusion'
+#COMMON_OPTIONS="-NC -impl opencl -cp fp32 -d64 --debug-dump-target dump -nu 0.02 -niter 20 -te 0.1 --dump-tstart 0.05 --dump-freq 1 "
+
+#echo
+#echo
+#echo "TEST SCALAR DIFFUSION CHECKPOINT (SERIAL)"
+#if [[ ! -f "${EXAMPLE_FILE}" ]]; then
+    #echo "Cannot find example file '${EXAMPLE_FILE}'."
+    #exit 1
+#fi
+
+#echo ' Running simulations...'
+#"${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -S "${TEST_DIR}/checkpoint0.tar" --dump-dir "${TEST_DIR}/run0" --checkpoint-dump-time 0.05 --checkpoint-dump-freq 0
+#"${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -S "${TEST_DIR}/checkpoint1.tar" --dump-dir "${TEST_DIR}/run1" --checkpoint-dump-time 0.05 --checkpoint-dump-freq 0
+
+#echo ' Comparing solutions...'
+#echo "  >debug dumps match"
+#compare_files "${TEST_DIR}/run0/dump/run.txt" "${TEST_DIR}/run1/dump/run.txt"
+#for f0 in $(find "${TEST_DIR}/run0" -name '*.h5'); do
+    #f1=$(echo "${f0}" | sed 's/run0/run1/')
+    #compare_files "${f0}" "${f1}"
+    #echo "  >$(basename ${f0}) match"
+#done
+
+#echo
+#echo ' Running simulations from checkpoints...'
+#"${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -L "${TEST_DIR}/checkpoint0.tar" --dump-dir "${TEST_DIR}/run2"
+#"${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -L "${TEST_DIR}/checkpoint1.tar" --dump-dir "${TEST_DIR}/run3"
+
+#echo ' Comparing solutions...'
+#compare_files "${TEST_DIR}/run2/dump/run.txt" "${TEST_DIR}/run3/dump/run.txt"
+#echo "  >debug dumps match"
+#for f0 in $(find "${TEST_DIR}/run2" -name '*.h5' | sort -n); do
+    #f1=$(echo "${f0}" | sed 's/run2/run3/')
+    #f2=$(echo "${f0}" | sed 's/run2/run0/')
+    #f3=$(echo "${f0}" | sed 's/run2/run1/')
+    #compare_files "${f0}" "${f1}"
+    #compare_files "${f0}" "${f2}"
+    #compare_files "${f0}" "${f3}"
+    #echo "  >$(basename ${f0}) match"
+#done
+
+
+
+#Basic test with 2D diffusion (mpi)
+
+#EXAMPLE_FILE="${EXAMPLE_DIR}/scalar_diffusion/scalar_diffusion.py"
+#TEST_DIR='/tmp/hysop_tests/checkpoints/scalar_diffusion_mpi'
+#COMMON_OPTIONS="-NC -impl opencl -cp fp32 -d64 --debug-dump-target dump -nu 0.02 -niter 20 -te 0.1 --dump-tstart 0.05 --dump-freq 1 "
+
+#echo
+#echo
+#echo "TEST SCALAR DIFFUSION CHECKPOINT (MPI)"
+#if [[ ! -f "${EXAMPLE_FILE}" ]]; then
+    #echo "Cannot find example file '${EXAMPLE_FILE}'."
+    #exit 1
+#fi
+
+#echo ' Running simulations...'
+#mpirun -np 4 "${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -S "${TEST_DIR}/checkpoint0.tar" --dump-dir "${TEST_DIR}/run0" --checkpoint-dump-time 0.05 --checkpoint-dump-freq 0
+#mpirun -np 4 "${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -S "${TEST_DIR}/checkpoint1.tar" --dump-dir "${TEST_DIR}/run1" --checkpoint-dump-time 0.05 --checkpoint-dump-freq 0
+
+#echo ' Comparing solutions...'
+#echo "  >debug dumps match"
+#compare_files "${TEST_DIR}/run0/dump/run.txt" "${TEST_DIR}/run1/dump/run.txt"
+#for f0 in $(find "${TEST_DIR}/run0" -name '*.h5'); do
+    #f1=$(echo "${f0}" | sed 's/run0/run1/')
+    #compare_files "${f0}" "${f1}"
+    #echo "  >$(basename ${f0}) match"
+#done
+
+#echo
+#echo ' Running simulations from checkpoints...'
+#mpirun -np 4 "${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -L "${TEST_DIR}/checkpoint0.tar" --dump-dir "${TEST_DIR}/run2"
+#mpirun -np 4 "${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -L "${TEST_DIR}/checkpoint1.tar" --dump-dir "${TEST_DIR}/run3"
+
+#echo ' Comparing solutions...'
+#compare_files "${TEST_DIR}/run2/dump/run.txt" "${TEST_DIR}/run3/dump/run.txt"
+#echo "  >debug dumps match"
+#for f0 in $(find "${TEST_DIR}/run2" -name '*.h5' | sort -n); do
+    #f1=$(echo "${f0}" | sed 's/run2/run3/')
+    #f2=$(echo "${f0}" | sed 's/run2/run0/')
+    #f3=$(echo "${f0}" | sed 's/run2/run1/')
+    #compare_files "${f0}" "${f1}"
+    #compare_files "${f0}" "${f2}"
+    #compare_files "${f0}" "${f3}"
+    #echo "  >$(basename ${f0}) match"
+#done
+
+
+#
+# Test 3D with taylor green (Fortran MPI backend)
+#
+EXAMPLE_FILE="${EXAMPLE_DIR}/taylor_green/taylor_green.py"
+TEST_DIR='/tmp/hysop_tests/checkpoints/taylor_green'
+COMMON_OPTIONS="-NC -impl fortran -cp fp64 -d32 -te 0.5 --dump-tstart 0.25 --dump-freq 1 --hdf5-disable-slicing --hdf5-disable-compression"
+
+echo
+echo
+echo "TEST TAYLOR-GREEN CHECKPOINT (Fortran-MPI)"
+if [[ ! -f "${EXAMPLE_FILE}" ]]; then
+    echo "Cannot find example file '${EXAMPLE_FILE}'."
+    exit 1
+fi
+
+#mpirun -np 2 "${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -S "${TEST_DIR}/checkpoint0.tar" --dump-dir "${TEST_DIR}/run0" --checkpoint-dump-time 0.25 --checkpoint-dump-freq 0
+mpirun -np 4 "${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -S "${TEST_DIR}/checkpoint1.tar" --dump-dir "${TEST_DIR}/run1" --checkpoint-dump-time 0.25 --checkpoint-dump-freq 0
+exit 0
+
+compare_files "${TEST_DIR}/run0/parameters.txt" "${TEST_DIR}/run1/parameters.txt"
+for f0 in $(find "${TEST_DIR}/run0" -name '*.h5'); do
+    f1=$(echo "${f0}" | sed 's/run0/run1/')
+    compare_files "${f0}" "${f1}"
+done
+
+"${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -L "${TEST_DIR}/A.tar" -te 0.5 --dump-tstart 0.25 --dump-freq 1 --dump-dir "${TEST_DIR}/run2"
+"${PYTHON_EXECUTABLE}" "${EXAMPLE_FILE}" ${COMMON_OPTIONS} -L "${TEST_DIR}/B.tar" -te 0.5 --dump-tstart 0.25 --dump-freq 1 --dump-dir "${TEST_DIR}/run3"
+compare_files "${TEST_DIR}/run2/parameters.txt" "${TEST_DIR}/run3/parameters.txt"
+for f0 in $(find "${TEST_DIR}/run2" -name '*.h5'); do
+    f1=$(echo "${f0}" | sed 's/run2/run3/')
+    f2=$(echo "${f0}" | sed 's/run2/run0/')
+    f3=$(echo "${f0}" | sed 's/run2/run1/')
+    compare_files "${f0}" "${f1}"
+    compare_files "${f0}" "${f2}"
+    compare_files "${f0}" "${f3}"
+done
-- 
GitLab