Skip to content

Commit

Permalink
Update fuzzer.py to be less stringent when validating approx. metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Nov 30, 2024
1 parent 11fdabe commit c4c1d73
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions test/scripts/fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,20 @@ def compute_stats(df: pd.DataFrame, keep_nans: bool, keep_infs: bool) -> Dict:


def compare_metric(
worker_id: int, q1: str, q2: str, metric: str, expected, found, keep_nans: bool, keep_infs: bool
worker_id: int,
q1: str,
q2: str,
metric: str,
expected,
found,
keep_nans: bool,
keep_infs: bool,
rtol: float = 1.0e-5,
atol: float = 1.0e-8,
) -> bool:
do_numeric_comparison = expected is not None and found is not None
if do_numeric_comparison:
if not np.isclose(expected, found, equal_nan=True):
if not np.isclose(expected, found, rtol=rtol, atol=atol, equal_nan=True):
logging.warning(
"[%d] %s, %s (%s; keep_nans=%s; keep_infs=%s): FAIL! Expected %.16g, found %.16g",
worker_id,
Expand Down Expand Up @@ -437,8 +446,8 @@ def compare_metric(


def compare_query_stats(worker_id: int, q1: str, q2: str, expected, sel: hictkpy.PixelSelector) -> int:
exact_metrics = ["nnz", "sum", "min", "max", "min", "skewness", "kurtosis"]
approx_metrics = ["variance"]
exact_metrics = ["nnz", "sum", "min", "max", "min"]
approx_metrics = ["variance", "skewness", "kurtosis"]
num_failures = 0
for keep_nans in [True, False]:
for keep_infs in [True, False]:
Expand All @@ -454,7 +463,7 @@ def compare_query_stats(worker_id: int, q1: str, q2: str, expected, sel: hictkpy
for metric in approx_metrics:
n1 = stats_expected[metric]
n2 = stats_found[metric]
if not compare_metric(worker_id, q1, q2, metric, n1, n2, keep_nans, keep_infs):
if not compare_metric(worker_id, q1, q2, metric, n1, n2, keep_nans, keep_infs, 1.0e-4, 1.0e-6):
num_failures += 1

return int(num_failures != 0)
Expand Down

0 comments on commit c4c1d73

Please sign in to comment.