Skip to content

Commit

Permalink
Update validation test (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
awvwgk authored Dec 1, 2024
1 parent 3890394 commit 1f03744
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ jobs:

- name: Upload coverage report
if: ${{ matrix.build-type == 'coverage' }}
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5


python:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@
# Directories
/build*/
/_*/

# Outputs
.EDISP
.CPC
13 changes: 11 additions & 2 deletions test/validation/16-db-d3-bj.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"version": "0.4.2",
"energy": -7.5851998023687944E-02
"version": "1.2.1",
"energy": -7.5474602132487828E-02,
"damping parameters": {
"damping": "rational",
"s6": 1.0000000000000000E+00,
"s8": 2.1166999999999998E+00,
"s9": 1.0000000000000000E+00,
"a1": 1.9860000000000000E-01,
"a2": 5.3875000000000002E+00,
"alp": 1.4000000000000000E+01
}
}
13 changes: 11 additions & 2 deletions test/validation/18-db-d3-bjm.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"version": "0.4.2",
"energy": -7.0590046232372944E-02
"version": "1.2.1",
"energy": -7.0407406164846739E-02,
"damping parameters": {
"damping": "rational",
"s6": 1.0000000000000000E+00,
"s8": 1.8750070000000001E+00,
"s9": 1.0000000000000000E+00,
"a1": 4.4848600000000000E-01,
"a2": 3.6106790000000002E+00,
"alp": 1.4000000000000000E+01
}
}
14 changes: 12 additions & 2 deletions test/validation/19-db-d3-zerom.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"version": "0.4.2",
"energy": -1.8797304944424987E-02
"version": "1.2.1",
"energy": -1.8667013017417262E-02,
"damping parameters": {
"damping": "mzero",
"s6": 6.4000000000000001E-01,
"s8": 7.1754300000000004E-01,
"s9": 1.0000000000000000E+00,
"rs6": 1.3131340000000000E+00,
"rs8": 1.0000000000000000E+00,
"alp": 1.4000000000000000E+01,
"bet": 1.6035000000000001E-02
}
}
14 changes: 12 additions & 2 deletions test/validation/20-db-d3-op.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"version": "0.4.2",
"energy": -1.5747159263772851E-02
"version": "1.2.1",
"energy": -1.5521531426306081E-02,
"damping parameters": {
"damping": "optimizedpower",
"s6": 1.0000000000000000E+00,
"s8": 9.0742999999999996E-01,
"s9": 1.0000000000000000E+00,
"a1": 6.9999999999999996E-01,
"a2": 4.0000000000000000E+00,
"alp": 1.4000000000000000E+01,
"bet": 2.0000000000000000E+00
}
}
46 changes: 40 additions & 6 deletions test/validation/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,51 @@
"""

try:
import subprocess, sys, json, os, pytest
import subprocess, sys, json, os
except ImportError:
exit(77)

if len(sys.argv) < 4:
raise RuntimeError("Requires at least four arguments")

thr = 1.0e-9

class approx:
def __init__(self, value, abs):
self.value = value
self.abs = abs
self.log = []

def __eq__(self, other):
def compare(a, b, ctx):
if isinstance(a, list) and isinstance(b, list):
return all(compare(x, y, f"{ctx}[{idx}]") for idx, (x, y) in enumerate(zip(a, b)))

if isinstance(a, dict) and isinstance(b, dict):
try:
return all(compare(a[k], b[k], f"{ctx}[{k}]") for k in a.keys())
except KeyError as e:
self.log.append(f"{ctx}: Missing key {e} in dictionary")
return False

if isinstance(a, (int, float)) and isinstance(b, (int, float)):
stat = abs(a - b) < self.abs
if not stat:
self.log.append(f"{ctx}: {a} != {b} (diff: {abs(a - b)})")
return stat

stat = a == b
if not stat:
self.log.append(f"{ctx}: {a} != {b}")
return stat

stat = compare(self.value, other, "")
if not stat:
print("\n".join(self.log))

return stat


thr = 1.0e-6
prog = sys.argv[1]
outp = sys.argv[2]
with open(sys.argv[3]) as fd:
Expand All @@ -38,7 +75,4 @@
with open(os.path.basename(outp)) as f:
res = json.load(f)

for key in ref:
if key not in res:
raise RuntimeError("Missing '" + key + "' entry in results")
assert pytest.approx(res[key], abs=thr) == ref[key]
assert approx(ref, abs=thr) == res

0 comments on commit 1f03744

Please sign in to comment.