All checks were successful
Build and Deploy Documentation / build-and-deploy (push) Successful in 28s
Add a Python-based test script that runs musrfit -c on each example msr-file, extracts the maxLH or chisq value, and checks it against a reference value with a relative tolerance of 1e-4. Covers all 13 example msr-files (single histogram and asymmetry fits). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Runs musrfit -c on a given msr-file, extracts the maxLH (or chisq)
|
|
value from stdout, and compares it against an expected reference value.
|
|
Returns exit code 1 if the relative deviation exceeds the tolerance.
|
|
|
|
Usage:
|
|
maxLH_check.py <musrfit> <msr-file> <expected_value> [tolerance]
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
import re
|
|
|
|
def main():
|
|
if len(sys.argv) < 4 or len(sys.argv) > 5:
|
|
print(f"usage: {sys.argv[0]} <musrfit> <msr-file> <expected> [tolerance]")
|
|
return 1
|
|
|
|
musrfit = sys.argv[1]
|
|
msr_file = sys.argv[2]
|
|
expected = float(sys.argv[3])
|
|
tol = float(sys.argv[4]) if len(sys.argv) == 5 else 1e-4
|
|
|
|
# run musrfit -c
|
|
result = subprocess.run([musrfit, "-c", msr_file],
|
|
capture_output=True, text=True)
|
|
if result.returncode != 0:
|
|
print(f"**ERROR** musrfit returned exit code {result.returncode}")
|
|
print(result.stdout + result.stderr)
|
|
return 1
|
|
|
|
# extract maxLH or chisq from stdout
|
|
match = re.search(r">>\s+(maxLH|chisq)\s*=\s*([0-9.eE+-]+)", result.stdout)
|
|
if not match:
|
|
print("**ERROR** could not extract maxLH or chisq from output:")
|
|
print(result.stdout)
|
|
return 1
|
|
|
|
label = match.group(1)
|
|
value = float(match.group(2))
|
|
rel_dev = abs((value - expected) / expected)
|
|
|
|
if rel_dev > tol:
|
|
print(f"FAIL: {label} = {value}, expected = {expected}, "
|
|
f"rel. deviation = {rel_dev:.6e} > {tol:.6e}")
|
|
return 1
|
|
|
|
print(f"PASS: {label} = {value}, expected = {expected}, "
|
|
f"rel. deviation = {rel_dev:.6e} <= {tol:.6e}")
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|