partitioning for ppsfp

This commit is contained in:
stefan committed 2026-07-06 22:31:44 +09:00
1 parent 2928b5129c
commit d30ad50b3c
6 files changed
+110 -58

No files matched your search

+26 -14
View File
@@ -13,6 +13,7 @@ The three simulators are exercised side-by-side and must agree exactly:
"""
import itertools
from collections import defaultdict
import numpy as np
import pytest
@@ -41,9 +42,8 @@ def make_patterns(*specs):
return pat if pat.ndim == 2 else pat.reshape(-1, 1)
def classify(alg, circuit, faults, patterns):
# PPSFP requires the batch size to match the pattern count (as main.py does).
sim = alg(circuit, patterns.shape[1])
def classify(alg, circuit, faults, patterns, partitioning = None):
sim = alg(circuit, batch_size=patterns.shape[1], partitioning=partitioning)
return sim.classify_faults(list(faults), patterns)
@@ -167,24 +167,36 @@ def test_s27_exact_simulators_agree(s27_bench, s27_resolved):
assert len(faults) == 32 # collapsed fault count, see test_fault_set.test_s27
simple = classify(SAFSimSimple, s27_resolved, faults, pat)
incr = classify(SAFSimIncremental, s27_resolved, faults, pat)
# The two exact simulators must classify every fault identically.
assert simple['DS'] == incr['DS']
assert simple['NO'] == incr['NO']
# This deterministic pattern set leaves exactly 6 faults unobserved.
assert len(simple['DS']) == 26
assert len(simple['NO']) == 6
def test_s27_ppsfp_matches_exact(s27_bench, s27_resolved):
faults, pat = _s27_setup(s27_bench, s27_resolved)
exact = classify(SAFSimSimple, s27_resolved, faults, pat)
incr = classify(SAFSimIncremental, s27_resolved, faults, pat)
ppsfp = classify(SAFSimPPSFP, s27_resolved, faults, pat)
# With exact FFR-stem observability, PPSFP classifies identically to the
# brute-force simulator -- no longer an over-approximation.
assert simple['DS'] == incr['DS']
assert simple['NO'] == incr['NO']
assert simple['DS'] == ppsfp['DS']
assert simple['NO'] == ppsfp['NO']
def test_s27_ppsfp_partitioning(s27_bench, s27_resolved):
faults, pat = _s27_setup(s27_bench, s27_resolved)
stems = [stem.index for stem, _ in s27_resolved.fanout_free_regions(KYUPY)]
k = 4
rng = np.random.default_rng(1)
parts = rng.integers(0, k, size=len(stems))
partitioning = defaultdict(set)
for part, stem in zip(parts, stems):
partitioning[int(part)].add(stem)
print(partitioning)
exact = classify(SAFSimSimple, s27_resolved, faults, pat)
ppsfp = classify(SAFSimPPSFP, s27_resolved, faults, pat, partitioning)
assert ppsfp['DS'] == exact['DS']
assert ppsfp['NO'] == exact['NO']