Skip to content

Commit 5b34e0c

Browse files
authored
Merge pull request #188 from ACCESS-NRI/om3-pm-zeros
Allow for differences in sign of zeros when checking OM3 restart repro
2 parents b1bedc5 + b881d91 commit 5b34e0c

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

src/model_config_tests/models/accessom3.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,40 @@ def extract_full_checksums(self, output_directory: Path = None) -> dict[str, Any
131131
schema_version=SCHEMA_VERSION_1_0_0,
132132
)["output"]
133133

134+
def check_checksums_over_restarts(
135+
self, long_run_checksum, short_run_checksum_0, short_run_checksum_1
136+
) -> bool:
137+
"""Compare a checksums from a long run (e.g. 2 days) against
138+
checksums from 2 short runs (e.g. 1 day)"""
139+
short_run_checksums = short_run_checksum_0["output"]
140+
for field, checksums in short_run_checksum_1["output"].items():
141+
if field not in short_run_checksums:
142+
short_run_checksums[field] = checksums
143+
else:
144+
short_run_checksums[field].extend(checksums)
145+
146+
matching_checksums = True
147+
for field, checksums in long_run_checksum["output"].items():
148+
for checksum in checksums:
149+
if field not in short_run_checksums:
150+
print(
151+
f"Checksum field for {field} found in long run but not in short runs"
152+
)
153+
matching_checksums = False
154+
else:
155+
if checksum not in short_run_checksums[field]:
156+
# Allow for checksums to differ by 8 in the first hex digit to allow
157+
# for differences in the sign of zero between restart arrays
158+
# See https://github.com/ACCESS-NRI/access-om3-configs/issues/823
159+
first_digit = int(checksum[0], 16)
160+
pmzeros_digit = (first_digit + 8) % 16
161+
pmzeros_checksum = f"{pmzeros_digit:X}" + checksum[1:]
162+
if pmzeros_checksum not in short_run_checksums[field]:
163+
print(f"Unequal checksum: {field}: {checksum}")
164+
matching_checksums = False
165+
166+
return matching_checksums
167+
134168
@staticmethod
135169
def _collect_restart_tiles(restart: Path) -> list[Path]:
136170
"""

tests/__init__.py

Whitespace-only changes.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import pytest
2+
3+
from model_config_tests.models import index as model_index
4+
5+
6+
@pytest.mark.parametrize("model_name", ["access-om2", "access-om3"])
7+
def test_check_checksums_over_restarts(model_name, capsys):
8+
model = model_index[model_name]
9+
10+
checksum_1 = {
11+
"schema_version": "1.0.0",
12+
"output": {
13+
"field1": ["12345678"],
14+
},
15+
}
16+
17+
checksum_2 = {
18+
"schema_version": "1.0.0",
19+
"output": {
20+
"field1": ["87654321"],
21+
},
22+
}
23+
24+
matching_checksums = model.check_checksums_over_restarts(
25+
model,
26+
checksum_1,
27+
checksum_1,
28+
checksum_1,
29+
)
30+
31+
assert matching_checksums is True
32+
33+
matching_checksums = model.check_checksums_over_restarts(
34+
model,
35+
checksum_2,
36+
checksum_1,
37+
checksum_1,
38+
)
39+
captured = capsys.readouterr()
40+
41+
assert matching_checksums is False
42+
assert captured.out == "Unequal checksum: field1: 87654321\n"
43+
44+
45+
def test_check_checksums_over_restarts_om3_pmzeros():
46+
# Test that OM3 checksums differing by 8 in the first hex digit are considered equal
47+
model = model_index["access-om3"]
48+
49+
checksum_1 = {
50+
"schema_version": "1.0.0",
51+
"output": {
52+
"field1": ["C92469973FB18B96"],
53+
},
54+
}
55+
56+
checksum_2 = {
57+
"schema_version": "1.0.0",
58+
"output": {
59+
"field1": ["492469973FB18B96"],
60+
},
61+
}
62+
63+
matching_checksums = model.check_checksums_over_restarts(
64+
model,
65+
checksum_1,
66+
checksum_2,
67+
checksum_2,
68+
)
69+
70+
assert matching_checksums is True
71+
72+
matching_checksums = model.check_checksums_over_restarts(
73+
model,
74+
checksum_2,
75+
checksum_1,
76+
checksum_1,
77+
)
78+
79+
assert matching_checksums is True

0 commit comments

Comments
 (0)