-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrunall
More file actions
executable file
·158 lines (135 loc) · 4.33 KB
/
runall
File metadata and controls
executable file
·158 lines (135 loc) · 4.33 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env bash
set -eu
set -o pipefail
ABS_TOL=${ABS_TOL:-1e-10}
REL_TOL=${REL_TOL:-1e-8}
update_kgo=0
while getopts ":u" opt; do
case "${opt}" in
u) update_kgo=1 ;;
*)
echo "Usage: $0 [-u] [clean|clobber]" >&2
exit 2
;;
esac
done
shift $((OPTIND - 1))
if [[ "${1:-""}" == "clean" || "${1:-""}" == "clobber" ]] ; then
make -C python/calcs "$1"
make -C fortran/src "$1"
make -C fortran/calcs "$1"
make -C docs "$1"
exit 0
fi
make -C python/calcs -j 4 all &
make -C fortran/src -j 1 imc.exe
make -C fortran/calcs -j 4 all &
make -C docs -j 4 html &
wait
if [[ "${update_kgo}" == "1" ]] ; then
for FILE in ./*/calcs/calc*_output.dat ; do
cp "${FILE}" "${FILE}.kgo"
done
fi
diff_fortran_tolerant() {
local kgo_file="$1"
local out_file="$2"
python3 - "$kgo_file" "$out_file" "$ABS_TOL" "$REL_TOL" <<'PY'
import re
import sys
from itertools import zip_longest
kgo_path = sys.argv[1]
out_path = sys.argv[2]
abs_tol = float(sys.argv[3])
rel_tol = float(sys.argv[4])
float_re = re.compile(r"[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?")
with open(kgo_path, "r", encoding="utf-8") as kgo, open(out_path, "r", encoding="utf-8") as out:
for lineno, (l1, l2) in enumerate(zip_longest(kgo, out), 1):
if l1 is None or l2 is None:
sys.stderr.write(f"{out_path}:{lineno}: file length differs\n")
sys.exit(1)
if l1 == l2:
continue
nums1 = [float(x) for x in float_re.findall(l1)]
nums2 = [float(x) for x in float_re.findall(l2)]
if not nums1 and not nums2:
sys.stderr.write(f"{out_path}:{lineno}: non-numeric line differs\n")
sys.exit(1)
if len(nums1) != len(nums2):
sys.stderr.write(f"{out_path}:{lineno}: numeric field count differs\n")
sys.exit(1)
for idx, (a, b) in enumerate(zip(nums1, nums2), 1):
diff = abs(a - b)
tol = max(abs_tol, rel_tol * max(abs(a), abs(b)))
if diff > tol:
sys.stderr.write(
f"{out_path}:{lineno}:{idx}: {a} != {b} (diff {diff}, tol {tol})\n"
)
sys.exit(1)
PY
}
diff_python_pickle() {
local kgo_file="$1"
local out_file="$2"
python3 - "$kgo_file" "$out_file" "$ABS_TOL" "$REL_TOL" <<'PY'
import pickle
import sys
import numpy as np
kgo_path = sys.argv[1]
out_path = sys.argv[2]
abs_tol = float(sys.argv[3])
rel_tol = float(sys.argv[4])
def read_entries(path):
entries = []
with open(path, "rb") as handle:
while True:
line = handle.readline()
if not line:
break
if not line.startswith(b"Time ="):
raise ValueError(f"{path}: unexpected line: {line[:40]!r}")
_, value = line.split(b"=", 1)
time_val = float(value.strip())
cellpos = pickle.load(handle)
temp = pickle.load(handle)
entries.append((time_val, np.asarray(cellpos), np.asarray(temp)))
return entries
def close_enough(a, b):
diff = abs(a - b)
tol = max(abs_tol, rel_tol * max(abs(a), abs(b)))
return diff <= tol, diff, tol
kgo_entries = read_entries(kgo_path)
out_entries = read_entries(out_path)
if len(kgo_entries) != len(out_entries):
sys.stderr.write(
f"{out_path}: entry count differs ({len(kgo_entries)} != {len(out_entries)})\n"
)
sys.exit(1)
for idx, ((t1, x1, y1), (t2, x2, y2)) in enumerate(
zip(kgo_entries, out_entries), 1
):
ok, diff, tol = close_enough(t1, t2)
if not ok:
sys.stderr.write(
f"{out_path}: time[{idx}] {t1} != {t2} (diff {diff}, tol {tol})\n"
)
sys.exit(1)
if not np.allclose(x1, x2, rtol=rel_tol, atol=abs_tol):
sys.stderr.write(f"{out_path}: cellpos[{idx}] differs\n")
sys.exit(1)
if not np.allclose(y1, y2, rtol=rel_tol, atol=abs_tol):
sys.stderr.write(f"{out_path}: temp[{idx}] differs\n")
sys.exit(1)
PY
}
for FILE in ./*/calcs/calc*_output.dat ; do
echo "${FILE}"
if [[ "${FILE}" == ./fortran/calcs/* ]] ; then
diff_fortran_tolerant "${FILE}.kgo" "${FILE}"
elif [[ "${FILE}" == ./python/calcs/* ]] ; then
diff_python_pickle "${FILE}.kgo" "${FILE}"
else
diff "${FILE}" "${FILE}.kgo"
fi
done
exit 0