FAILURE MAP
← Case archive

FA-91131 / Quantum circuit simulation / Open access

Shot sampler accepts u = 1 · case 01

A uniform of exactly 1 is silently mapped to the last index, even when its weight is zero, instead of being rejected.

Verified by executionVariant 1 · 6 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The range check rejects u > 1 only.

VERIFIED REPAIR

Reject u >= 1 and u < 0 with ["bad-uniform", position].

Unsuccessful approach: The attempted repair wraps uniforms modulo 1 instead of rejecting them, so 1 becomes 0 and -0.25 becomes 0.75.

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: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['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 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['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}], ['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}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['control: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['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}], ['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}]]]
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 fixtureActualExpectedOutcome
regression: uniform exactly one{'1': 1}['bad-uniform', 0]Failed
repair check: negative uniform['bad-uniform', 0]['bad-uniform', 0]Passed
control: boundary uniform on cumulative edge{'1': 1}{'1': 1}Passed
control: zero weight first outcome{'01': 1, '10': 1}{'01': 1, '10': 1}Passed
control: negative weightnegative-weightnegative-weightPassed
control: all zero weightsno-supportno-supportPassed

SHA-256 / 9c54ec7cd5f877245dcbca4d465c4a8924e7b08f049bfef3d2e972caf3af5595

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)
        u = u % 1
        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: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['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 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['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}], ['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}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['control: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['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}], ['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}]]]
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 fixtureActualExpectedOutcome
regression: uniform exactly one{'0': 1}['bad-uniform', 0]Failed
repair check: negative uniform{'1': 1}['bad-uniform', 0]Failed
control: boundary uniform on cumulative edge{'1': 1}{'1': 1}Passed
control: zero weight first outcome{'01': 1, '10': 1}{'01': 1, '10': 1}Passed
control: negative weightnegative-weightnegative-weightPassed
control: all zero weightsno-supportno-supportPassed

SHA-256 / d40509335dd9c0d584f2c2ee3d1fb930c273b7d36040cce8cd379291c6308655

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: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['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 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['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}], ['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}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['control: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['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}], ['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}]]]
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 fixtureActualExpectedOutcome
regression: uniform exactly one['bad-uniform', 0]['bad-uniform', 0]Passed
repair check: negative uniform['bad-uniform', 0]['bad-uniform', 0]Passed
control: boundary uniform on cumulative edge{'1': 1}{'1': 1}Passed
control: zero weight first outcome{'01': 1, '10': 1}{'01': 1, '10': 1}Passed
control: negative weightnegative-weightnegative-weightPassed
control: all zero weightsno-supportno-supportPassed

SHA-256 / 8e5579a231ac32a353d85de359ad92c40f97c3af8085f0a3e6114d6eb6ece346

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:33.036621+00:00.

Case digest / c7b56bae6363c7600e9d6521e076e300797c28b878cc3f46c127fac192ab6c1b