Skip to content

Commit fa18b6f

Browse files
refactor(fp-stability): extract _empty_result helper
The identical 13-key result dict was duplicated in _run_case() (line 970) and the exception handler in _run_stability_checks() (line 1322). Extract a single _empty_result(name, threshold) helper and use it from both call sites. Fixes part (a) of #1512.
1 parent 4a73bf3 commit fa18b6f

1 file changed

Lines changed: 20 additions & 28 deletions

File tree

toolchain/mfc/fp_stability.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@
9898
)
9999

100100

101+
def _empty_result(name: str, threshold: float) -> dict:
102+
"""Build a default empty result dict with all fields initialised."""
103+
return {
104+
"name": name,
105+
"passed": False,
106+
"max_dev": float("inf"),
107+
"threshold": threshold,
108+
"float_proxy": None,
109+
"vprec": [],
110+
"dd_sym_syms": [],
111+
"dd_line_locs": [],
112+
"cancellation_locs": [],
113+
"mca_dev": None,
114+
"mca_sigbits": None,
115+
"float_max_locs": [],
116+
}
117+
118+
101119
def _read_source_line(fname: str, lineno: int) -> str:
102120
"""Return the raw source line at lineno (1-based), or '' if unavailable."""
103121
if os.path.isabs(fname) and os.path.isfile(fname):
@@ -967,20 +985,7 @@ def _run_case(
967985
cons.print(f" threshold: {threshold:.0e}")
968986

969987
work_dir = tempfile.mkdtemp(prefix=f"mfc-fps-{name}-")
970-
result = {
971-
"name": name,
972-
"passed": False,
973-
"max_dev": float("inf"),
974-
"threshold": threshold,
975-
"float_proxy": None,
976-
"vprec": [],
977-
"dd_sym_syms": [],
978-
"dd_line_locs": [],
979-
"cancellation_locs": [],
980-
"mca_dev": None,
981-
"mca_sigbits": None,
982-
"float_max_locs": [],
983-
}
988+
result = _empty_result(name, threshold)
984989
try:
985990
cons.print(" [dim]running pre_process...[/dim]")
986991
_write_inp(case["sim"], "simulation", work_dir)
@@ -1319,20 +1324,7 @@ def fp_stability():
13191324
)
13201325
except MFCException as exc:
13211326
cons.print(f" [bold red]ERROR[/bold red]: {exc}")
1322-
r = {
1323-
"name": case["name"],
1324-
"passed": False,
1325-
"max_dev": float("inf"),
1326-
"threshold": case["threshold"],
1327-
"float_proxy": None,
1328-
"vprec": [],
1329-
"dd_sym_syms": [],
1330-
"dd_line_locs": [],
1331-
"cancellation_locs": [],
1332-
"mca_dev": None,
1333-
"mca_sigbits": None,
1334-
"float_max_locs": [],
1335-
}
1327+
r = _empty_result(case["name"], case["threshold"])
13361328
results.append(r)
13371329

13381330
elapsed = time.time() - start

0 commit comments

Comments
 (0)