FA-91121 / Quantum circuit simulation / Open access
Shot sampler assigns boundary uniforms to the earlier outcome · case 01
u = 0 selects an outcome with zero weight, and u exactly on a cumulative edge lands in the lower bucket.
ROOT CAUSE
The inverse-CDF search uses target <= cumulative instead of a strict comparison.
VERIFIED REPAIR
Select the first index with target < cumulative weight.
Unsuccessful approach: The attempted repair keeps <= but skips zero-weight outcomes, which fixes u = 0 but still misplaces uniforms on interior edges.
Case contract
Input [n, weights, uniforms]; weights are nonnegative integers for basis indices 0..2**n-1 and uniforms are exact decimal or fraction strings in [0, 1). Each uniform u selects the first index i with u * total < cumulative weight through i. Return counts {bitstring: count} with qubit n-1 leftmost. Errors: "bad-length", "negative-weight", "no-support", ["bad-uniform", position].
Why this case matters
Deterministic replay of sampled shots makes simulator results reproducible; CDF boundary slips bias counts toward impossible outcomes.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
n, weights, us = x
if len(weights) != 1 << n:
return 'bad-length'
if any(w < 0 for w in weights):
return 'negative-weight'
total = sum(weights)
if total == 0:
return 'no-support'
counts = {}
for idx, s in enumerate(us):
u = Fraction(s)
if u < 0 or u >= 1:
return ['bad-uniform', idx]
target = u * total
cum = 0
for i, w in enumerate(weights):
cum += w
if target <= cum:
break
key = format(i, '0%db' % n)
counts[key] = counts.get(key, 0) + 1
return counts
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['regression: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['regression: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}]], [['regression: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['regression: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['regression: random shots 14', [3, [0, 1, 2, 0, 0, 3, 1, 0], ['0.559', '6/7', '2/7', '0.29', '0.711', '5/7']], {'101': 3, '110': 1, '010': 2}], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}]], [['regression: random shots 15', [1, [0, 1], ['0/1', '0.769', '0.573', '0.347', '0.401', '0/1']], {'1': 6}], ['regression: random shots 16', [1, [0, 1], ['0.929', '0.975', '0.277', '0/1', '0.216']], {'1': 5}], ['regression: random shots 21', [1, [1, 3], ['1/4', '0.282', '0.17']], {'1': 2, '0': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: random shots 13', [1, [3, 0], ['0.586', '1/3']], {'0': 2}], ['control: random shots 17', [1, [2, 1], ['0.153', '0.906', '0/3', '0.007', '1/3']], {'0': 4, '1': 1}], ['control: random shots 18', [1, [5, 3], ['4/8', '4/8', '0.129', '0.153', '1/8', '0.326']], {'0': 6}]], [['regression: random shots 30', [3, [0, 1, 3, 3, 0, 2, 0, 0], ['0/9', '0.411', '7/9', '0.796', '0.678', '0/9']], {'001': 2, '010': 1, '101': 2, '011': 1}], ['regression: random shots 35', [2, [2, 1, 0, 0], ['1/3', '0.652', '0.988', '2/3', '0.769', '1/3']], {'00': 3, '01': 3}], ['regression: random shots 39', [1, [3, 5], ['0.57', '5/8', '0.242', '0.174', '3/8']], {'1': 3, '0': 2}], ['control: random shots 19', [1, [3, 2], ['0.826', '0.88']], {'1': 2}], ['control: random shots 20', [1, [5, 1], ['0.272', '0/6', '0.203', '0/6']], {'0': 4}], ['control: random shots 22', [1, [0, 5], ['0.608', '1/5', '2/5']], {'1': 3}], ['control: random shots 23', [1, [2, 0], ['1/2', '0.071', '0/2', '0/2', '0.086', '0.733']], {'0': 6}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: boundary uniform on cumulative edge | {'0': 1} | {'1': 1} | Failed |
| regression: zero weight first outcome | {'00': 1, '01': 1} | {'01': 1, '10': 1} | Failed |
| regression: random shots 3 | {'0': 1, '1': 2} | {'1': 3} | Failed |
| control: uniform exactly one | ['bad-uniform', 0] | ['bad-uniform', 0] | Passed |
| control: negative uniform | ['bad-uniform', 0] | ['bad-uniform', 0] | Passed |
| control: negative weight | negative-weight | negative-weight | Passed |
| control: all zero weights | no-support | no-support | Passed |
SHA-256 / d23c9755d162128728aba67dfe539a2c30a2f8bdc07bb4e20f4b9056be2e4c46
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
n, weights, us = x
if len(weights) != 1 << n:
return 'bad-length'
if any(w < 0 for w in weights):
return 'negative-weight'
total = sum(weights)
if total == 0:
return 'no-support'
counts = {}
for idx, s in enumerate(us):
u = Fraction(s)
if u < 0 or u >= 1:
return ['bad-uniform', idx]
target = u * total
cum = 0
for i, w in enumerate(weights):
cum += w
if target <= cum and w > 0:
break
key = format(i, '0%db' % n)
counts[key] = counts.get(key, 0) + 1
return counts
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['regression: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['regression: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}]], [['regression: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['regression: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['regression: random shots 14', [3, [0, 1, 2, 0, 0, 3, 1, 0], ['0.559', '6/7', '2/7', '0.29', '0.711', '5/7']], {'101': 3, '110': 1, '010': 2}], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}]], [['regression: random shots 15', [1, [0, 1], ['0/1', '0.769', '0.573', '0.347', '0.401', '0/1']], {'1': 6}], ['regression: random shots 16', [1, [0, 1], ['0.929', '0.975', '0.277', '0/1', '0.216']], {'1': 5}], ['regression: random shots 21', [1, [1, 3], ['1/4', '0.282', '0.17']], {'1': 2, '0': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: random shots 13', [1, [3, 0], ['0.586', '1/3']], {'0': 2}], ['control: random shots 17', [1, [2, 1], ['0.153', '0.906', '0/3', '0.007', '1/3']], {'0': 4, '1': 1}], ['control: random shots 18', [1, [5, 3], ['4/8', '4/8', '0.129', '0.153', '1/8', '0.326']], {'0': 6}]], [['regression: random shots 30', [3, [0, 1, 3, 3, 0, 2, 0, 0], ['0/9', '0.411', '7/9', '0.796', '0.678', '0/9']], {'001': 2, '010': 1, '101': 2, '011': 1}], ['regression: random shots 35', [2, [2, 1, 0, 0], ['1/3', '0.652', '0.988', '2/3', '0.769', '1/3']], {'00': 3, '01': 3}], ['regression: random shots 39', [1, [3, 5], ['0.57', '5/8', '0.242', '0.174', '3/8']], {'1': 3, '0': 2}], ['control: random shots 19', [1, [3, 2], ['0.826', '0.88']], {'1': 2}], ['control: random shots 20', [1, [5, 1], ['0.272', '0/6', '0.203', '0/6']], {'0': 4}], ['control: random shots 22', [1, [0, 5], ['0.608', '1/5', '2/5']], {'1': 3}], ['control: random shots 23', [1, [2, 0], ['1/2', '0.071', '0/2', '0/2', '0.086', '0.733']], {'0': 6}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: boundary uniform on cumulative edge | {'0': 1} | {'1': 1} | Failed |
| regression: zero weight first outcome | {'01': 2} | {'01': 1, '10': 1} | Failed |
| regression: random shots 3 | {'0': 1, '1': 2} | {'1': 3} | Failed |
| control: uniform exactly one | ['bad-uniform', 0] | ['bad-uniform', 0] | Passed |
| control: negative uniform | ['bad-uniform', 0] | ['bad-uniform', 0] | Passed |
| control: negative weight | negative-weight | negative-weight | Passed |
| control: all zero weights | no-support | no-support | Passed |
SHA-256 / 044a0df6e623e02a9a16f8f117bb8c64c330e849996f6d98a0775837e49949be
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
n, weights, us = x
if len(weights) != 1 << n:
return 'bad-length'
if any(w < 0 for w in weights):
return 'negative-weight'
total = sum(weights)
if total == 0:
return 'no-support'
counts = {}
for idx, s in enumerate(us):
u = Fraction(s)
if u < 0 or u >= 1:
return ['bad-uniform', idx]
target = u * total
cum = 0
for i, w in enumerate(weights):
cum += w
if target < cum:
break
key = format(i, '0%db' % n)
counts[key] = counts.get(key, 0) + 1
return counts
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['regression: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['regression: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}]], [['regression: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['regression: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['regression: random shots 14', [3, [0, 1, 2, 0, 0, 3, 1, 0], ['0.559', '6/7', '2/7', '0.29', '0.711', '5/7']], {'101': 3, '110': 1, '010': 2}], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}]], [['regression: random shots 15', [1, [0, 1], ['0/1', '0.769', '0.573', '0.347', '0.401', '0/1']], {'1': 6}], ['regression: random shots 16', [1, [0, 1], ['0.929', '0.975', '0.277', '0/1', '0.216']], {'1': 5}], ['regression: random shots 21', [1, [1, 3], ['1/4', '0.282', '0.17']], {'1': 2, '0': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: random shots 13', [1, [3, 0], ['0.586', '1/3']], {'0': 2}], ['control: random shots 17', [1, [2, 1], ['0.153', '0.906', '0/3', '0.007', '1/3']], {'0': 4, '1': 1}], ['control: random shots 18', [1, [5, 3], ['4/8', '4/8', '0.129', '0.153', '1/8', '0.326']], {'0': 6}]], [['regression: random shots 30', [3, [0, 1, 3, 3, 0, 2, 0, 0], ['0/9', '0.411', '7/9', '0.796', '0.678', '0/9']], {'001': 2, '010': 1, '101': 2, '011': 1}], ['regression: random shots 35', [2, [2, 1, 0, 0], ['1/3', '0.652', '0.988', '2/3', '0.769', '1/3']], {'00': 3, '01': 3}], ['regression: random shots 39', [1, [3, 5], ['0.57', '5/8', '0.242', '0.174', '3/8']], {'1': 3, '0': 2}], ['control: random shots 19', [1, [3, 2], ['0.826', '0.88']], {'1': 2}], ['control: random shots 20', [1, [5, 1], ['0.272', '0/6', '0.203', '0/6']], {'0': 4}], ['control: random shots 22', [1, [0, 5], ['0.608', '1/5', '2/5']], {'1': 3}], ['control: random shots 23', [1, [2, 0], ['1/2', '0.071', '0/2', '0/2', '0.086', '0.733']], {'0': 6}]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: boundary uniform on cumulative edge | {'1': 1} | {'1': 1} | Passed |
| regression: zero weight first outcome | {'01': 1, '10': 1} | {'01': 1, '10': 1} | Passed |
| regression: random shots 3 | {'1': 3} | {'1': 3} | Passed |
| control: uniform exactly one | ['bad-uniform', 0] | ['bad-uniform', 0] | Passed |
| control: negative uniform | ['bad-uniform', 0] | ['bad-uniform', 0] | Passed |
| control: negative weight | negative-weight | negative-weight | Passed |
| control: all zero weights | no-support | no-support | Passed |
SHA-256 / 68c8f71a4271f68460572666ac1a7584e3cc84d1742cfa2dcefc67a53ed4c344
Verification & scope
A deterministic bounded teaching model with a stipulated toy contract; amplitudes are rounded to fixed decimals for strict JSON output. It is not a production quantum SDK and claims no standards conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:51:32.993056+00:00.
Case digest / 56417e7d72000178cf90f58706a0c5f7de7ee216e1d68209ea76c36f1820aec5