FA-90881 / Quantum circuit simulation / Open access
Marginal probability uses amplitude magnitude not its square · case 01
An unequal superposition such as 0.6|0> + 0.8i|1> is reported as 3/7 and 4/7 instead of 0.36 and 0.64.
ROOT CAUSE
The per-amplitude weight is computed as the modulus hypot(a, b) rather than the squared modulus.
VERIFIED REPAIR
Weight each basis state by a*a + b*b (the Born rule).
Unsuccessful approach: The attempted repair uses a*a - b*b, the real part of the squared amplitude, which is wrong for any imaginary component.
Case contract
Input [n, amps, qubits]; amps are 2**n [re, im] pairs (qubit 0 = LSB), possibly unnormalized. Return the marginal outcome distribution over the listed qubits as {bitstring: probability} where the first listed qubit is the rightmost character, probabilities are normalized by the total squared norm, rounded to 6 decimals after summation, and zero entries are omitted. Errors: "bad-length", "duplicate-qubit", "bad-qubit", "zero-state" (total squared norm <= 1e-12).
Why this case matters
Marginal readout distributions are what users compare against hardware counts; ordering or normalization slips mislabel every histogram.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
n, amps, qubits = x
if len(amps) != 1 << n:
return 'bad-length'
if len(set(qubits)) != len(qubits):
return 'duplicate-qubit'
if any(q < 0 or q >= n for q in qubits):
return 'bad-qubit'
total = sum(re * re + im * im for re, im in amps)
if total <= 1e-12:
return 'zero-state'
acc = {}
for idx, (a, b) in enumerate(amps):
p = math.hypot(a, b)
if p == 0:
continue
key = ''.join('1' if idx >> q & 1 else '0' for q in reversed(qubits))
acc[key] = acc.get(key, 0.0) + p
out = {}
for key in sorted(acc):
v = round(acc[key] / total, 6)
if v > 0:
out[key] = v
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: bell state on both qubits', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], [0, 1]], {'00': 0.5, '11': 0.5}], ['regression: tiny but valid state', [1, [[0.0001, 0], [0, 0.0002]], [0]], {'0': 0.2, '1': 0.8}], ['regression: unnormalized pair', [1, [[3, 0], [0, 4]], [0]], {'0': 0.36, '1': 0.64}], ['control: reversed qubit list', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1, 0]], {'10': 1.0}], ['control: single qubit marginal of |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1]], {'0': 1.0}], ['control: out of range qubit equals n', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [2]], 'bad-qubit'], ['control: negative qubit index', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [-1]], 'bad-qubit']], [['regression: random state 0', [2, [[0.0, 0.0], [0.282, -0.043], [-0.278, 0.017], [0.0, 0.0]], [0, 1]], {'01': 0.511954, '10': 0.488046}], ['regression: random state 1', [2, [[0.129, 0.125], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]], [1, 0]], {'00': 1.0}], ['regression: random state 2', [1, [[0.541, -0.923], [-0.479, -0.646]], [0]], {'0': 0.638959, '1': 0.361041}], ['control: duplicate qubits', [2, [[0.6, 0], [0, 0.8], [0, 0], [0, 0]], [0, 0]], 'duplicate-qubit'], ['control: wrong amplitude count', [2, [[1, 0], [0, 0]], [0]], 'bad-length'], ['control: all-zero state', [1, [[0, 0], [0, 0]], [0]], 'zero-state'], ['control: near zero state', [1, [[1e-08, 0], [0, 1e-08]], [0]], 'zero-state']], [['regression: random state 3', [2, [[0.379, 0.308], [-0.129, -0.524], [0.79, -0.299], [-0.403, -0.327]], [0, 1]], {'00': 0.157683, '01': 0.192532, '10': 0.471717, '11': 0.178068}], ['regression: random state 4', [1, [[-0.217, 0.525], [-0.308, -0.181]], [0]], {'0': 0.716602, '1': 0.283398}], ['regression: random state 2', [1, [[0.541, -0.923], [-0.479, -0.646]], [0]], {'0': 0.638959, '1': 0.361041}], ['control: reversed qubit list', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1, 0]], {'10': 1.0}], ['control: single qubit marginal of |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1]], {'0': 1.0}], ['control: out of range qubit equals n', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [2]], 'bad-qubit'], ['control: negative qubit index', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [-1]], 'bad-qubit']], [['regression: random state 6', [3, [[-0.119, 0.092], [0.264, -0.223], [-0.189, 0.034], [-0.22, -0.267], [-0.291, -0.092], [0.09, -0.02], [0.062, -0.284], [-0.239, 0.039]], [2]], {'0': 0.54953, '1': 0.45047}], ['regression: random state 7', [1, [[0.725, -0.825], [-0.233, -0.266]], [0]], {'0': 0.906073, '1': 0.093927}], ['regression: random state 4', [1, [[-0.217, 0.525], [-0.308, -0.181]], [0]], {'0': 0.716602, '1': 0.283398}], ['control: duplicate qubits', [2, [[0.6, 0], [0, 0.8], [0, 0], [0, 0]], [0, 0]], 'duplicate-qubit'], ['control: wrong amplitude count', [2, [[1, 0], [0, 0]], [0]], 'bad-length'], ['control: all-zero state', [1, [[0, 0], [0, 0]], [0]], 'zero-state'], ['control: near zero state', [1, [[1e-08, 0], [0, 1e-08]], [0]], 'zero-state']], [['regression: random state 9', [1, [[-0.25, -0.175], [0.0, 0.0]], [0]], {'0': 1.0}], ['regression: random state 10', [3, [[-0.064, 0.212], [0.264, -0.114], [-0.15, -0.24], [0.031, 0.141], [0.037, -0.002], [0.023, -0.229], [0.193, -0.153], [0.251, 0.097]], [0, 1, 2]], {'000': 0.116738, '001': 0.196846, '010': 0.190676, '011': 0.049614, '100': 0.003268, '101': 0.126094, '110': 0.144395, '111': 0.17237}], ['regression: random state 6', [3, [[-0.119, 0.092], [0.264, -0.223], [-0.189, 0.034], [-0.22, -0.267], [-0.291, -0.092], [0.09, -0.02], [0.062, -0.284], [-0.239, 0.039]], [2]], {'0': 0.54953, '1': 0.45047}], ['control: reversed qubit list', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1, 0]], {'10': 1.0}], ['control: single qubit marginal of |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1]], {'0': 1.0}], ['control: out of range qubit equals n', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [2]], 'bad-qubit'], ['control: negative qubit index', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [-1]], 'bad-qubit']]]
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: bell state on both qubits | {'00': 0.707107, '11': 0.707107} | {'00': 0.5, '11': 0.5} | Failed |
| regression: tiny but valid state | {'0': 2000.0, '1': 4000.0} | {'0': 0.2, '1': 0.8} | Failed |
| regression: unnormalized pair | {'0': 0.12, '1': 0.16} | {'0': 0.36, '1': 0.64} | Failed |
| control: reversed qubit list | {'10': 1.0} | {'10': 1.0} | Passed |
| control: single qubit marginal of |01> | {'0': 1.0} | {'0': 1.0} | Passed |
| control: out of range qubit equals n | bad-qubit | bad-qubit | Passed |
| control: negative qubit index | bad-qubit | bad-qubit | Passed |
SHA-256 / 622861963937b0451091d41d7dd338c1223c9e6e7454e4b767d1efb148c60383
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
n, amps, qubits = x
if len(amps) != 1 << n:
return 'bad-length'
if len(set(qubits)) != len(qubits):
return 'duplicate-qubit'
if any(q < 0 or q >= n for q in qubits):
return 'bad-qubit'
total = sum(re * re + im * im for re, im in amps)
if total <= 1e-12:
return 'zero-state'
acc = {}
for idx, (a, b) in enumerate(amps):
p = a * a - b * b
if p == 0:
continue
key = ''.join('1' if idx >> q & 1 else '0' for q in reversed(qubits))
acc[key] = acc.get(key, 0.0) + p
out = {}
for key in sorted(acc):
v = round(acc[key] / total, 6)
if v > 0:
out[key] = v
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: bell state on both qubits', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], [0, 1]], {'00': 0.5, '11': 0.5}], ['regression: tiny but valid state', [1, [[0.0001, 0], [0, 0.0002]], [0]], {'0': 0.2, '1': 0.8}], ['regression: unnormalized pair', [1, [[3, 0], [0, 4]], [0]], {'0': 0.36, '1': 0.64}], ['control: reversed qubit list', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1, 0]], {'10': 1.0}], ['control: single qubit marginal of |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1]], {'0': 1.0}], ['control: out of range qubit equals n', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [2]], 'bad-qubit'], ['control: negative qubit index', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [-1]], 'bad-qubit']], [['regression: random state 0', [2, [[0.0, 0.0], [0.282, -0.043], [-0.278, 0.017], [0.0, 0.0]], [0, 1]], {'01': 0.511954, '10': 0.488046}], ['regression: random state 1', [2, [[0.129, 0.125], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]], [1, 0]], {'00': 1.0}], ['regression: random state 2', [1, [[0.541, -0.923], [-0.479, -0.646]], [0]], {'0': 0.638959, '1': 0.361041}], ['control: duplicate qubits', [2, [[0.6, 0], [0, 0.8], [0, 0], [0, 0]], [0, 0]], 'duplicate-qubit'], ['control: wrong amplitude count', [2, [[1, 0], [0, 0]], [0]], 'bad-length'], ['control: all-zero state', [1, [[0, 0], [0, 0]], [0]], 'zero-state'], ['control: near zero state', [1, [[1e-08, 0], [0, 1e-08]], [0]], 'zero-state']], [['regression: random state 3', [2, [[0.379, 0.308], [-0.129, -0.524], [0.79, -0.299], [-0.403, -0.327]], [0, 1]], {'00': 0.157683, '01': 0.192532, '10': 0.471717, '11': 0.178068}], ['regression: random state 4', [1, [[-0.217, 0.525], [-0.308, -0.181]], [0]], {'0': 0.716602, '1': 0.283398}], ['regression: random state 2', [1, [[0.541, -0.923], [-0.479, -0.646]], [0]], {'0': 0.638959, '1': 0.361041}], ['control: reversed qubit list', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1, 0]], {'10': 1.0}], ['control: single qubit marginal of |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1]], {'0': 1.0}], ['control: out of range qubit equals n', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [2]], 'bad-qubit'], ['control: negative qubit index', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [-1]], 'bad-qubit']], [['regression: random state 6', [3, [[-0.119, 0.092], [0.264, -0.223], [-0.189, 0.034], [-0.22, -0.267], [-0.291, -0.092], [0.09, -0.02], [0.062, -0.284], [-0.239, 0.039]], [2]], {'0': 0.54953, '1': 0.45047}], ['regression: random state 7', [1, [[0.725, -0.825], [-0.233, -0.266]], [0]], {'0': 0.906073, '1': 0.093927}], ['regression: random state 4', [1, [[-0.217, 0.525], [-0.308, -0.181]], [0]], {'0': 0.716602, '1': 0.283398}], ['control: duplicate qubits', [2, [[0.6, 0], [0, 0.8], [0, 0], [0, 0]], [0, 0]], 'duplicate-qubit'], ['control: wrong amplitude count', [2, [[1, 0], [0, 0]], [0]], 'bad-length'], ['control: all-zero state', [1, [[0, 0], [0, 0]], [0]], 'zero-state'], ['control: near zero state', [1, [[1e-08, 0], [0, 1e-08]], [0]], 'zero-state']], [['regression: random state 9', [1, [[-0.25, -0.175], [0.0, 0.0]], [0]], {'0': 1.0}], ['regression: random state 10', [3, [[-0.064, 0.212], [0.264, -0.114], [-0.15, -0.24], [0.031, 0.141], [0.037, -0.002], [0.023, -0.229], [0.193, -0.153], [0.251, 0.097]], [0, 1, 2]], {'000': 0.116738, '001': 0.196846, '010': 0.190676, '011': 0.049614, '100': 0.003268, '101': 0.126094, '110': 0.144395, '111': 0.17237}], ['regression: random state 6', [3, [[-0.119, 0.092], [0.264, -0.223], [-0.189, 0.034], [-0.22, -0.267], [-0.291, -0.092], [0.09, -0.02], [0.062, -0.284], [-0.239, 0.039]], [2]], {'0': 0.54953, '1': 0.45047}], ['control: reversed qubit list', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1, 0]], {'10': 1.0}], ['control: single qubit marginal of |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1]], {'0': 1.0}], ['control: out of range qubit equals n', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [2]], 'bad-qubit'], ['control: negative qubit index', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [-1]], 'bad-qubit']]]
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: bell state on both qubits | {'00': 0.5, '11': 0.5} | {'00': 0.5, '11': 0.5} | Passed |
| regression: tiny but valid state | {'0': 0.2} | {'0': 0.2, '1': 0.8} | Failed |
| regression: unnormalized pair | {'0': 0.36} | {'0': 0.36, '1': 0.64} | Failed |
| control: reversed qubit list | {'10': 1.0} | {'10': 1.0} | Passed |
| control: single qubit marginal of |01> | {'0': 1.0} | {'0': 1.0} | Passed |
| control: out of range qubit equals n | bad-qubit | bad-qubit | Passed |
| control: negative qubit index | bad-qubit | bad-qubit | Passed |
SHA-256 / b9cfd617a9c812d380997aa082851a87d7ede561cefa29e1f7713e143342f061
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
n, amps, qubits = x
if len(amps) != 1 << n:
return 'bad-length'
if len(set(qubits)) != len(qubits):
return 'duplicate-qubit'
if any(q < 0 or q >= n for q in qubits):
return 'bad-qubit'
total = sum(re * re + im * im for re, im in amps)
if total <= 1e-12:
return 'zero-state'
acc = {}
for idx, (a, b) in enumerate(amps):
p = a * a + b * b
if p == 0:
continue
key = ''.join('1' if idx >> q & 1 else '0' for q in reversed(qubits))
acc[key] = acc.get(key, 0.0) + p
out = {}
for key in sorted(acc):
v = round(acc[key] / total, 6)
if v > 0:
out[key] = v
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: bell state on both qubits', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], [0, 1]], {'00': 0.5, '11': 0.5}], ['regression: tiny but valid state', [1, [[0.0001, 0], [0, 0.0002]], [0]], {'0': 0.2, '1': 0.8}], ['regression: unnormalized pair', [1, [[3, 0], [0, 4]], [0]], {'0': 0.36, '1': 0.64}], ['control: reversed qubit list', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1, 0]], {'10': 1.0}], ['control: single qubit marginal of |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1]], {'0': 1.0}], ['control: out of range qubit equals n', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [2]], 'bad-qubit'], ['control: negative qubit index', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [-1]], 'bad-qubit']], [['regression: random state 0', [2, [[0.0, 0.0], [0.282, -0.043], [-0.278, 0.017], [0.0, 0.0]], [0, 1]], {'01': 0.511954, '10': 0.488046}], ['regression: random state 1', [2, [[0.129, 0.125], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]], [1, 0]], {'00': 1.0}], ['regression: random state 2', [1, [[0.541, -0.923], [-0.479, -0.646]], [0]], {'0': 0.638959, '1': 0.361041}], ['control: duplicate qubits', [2, [[0.6, 0], [0, 0.8], [0, 0], [0, 0]], [0, 0]], 'duplicate-qubit'], ['control: wrong amplitude count', [2, [[1, 0], [0, 0]], [0]], 'bad-length'], ['control: all-zero state', [1, [[0, 0], [0, 0]], [0]], 'zero-state'], ['control: near zero state', [1, [[1e-08, 0], [0, 1e-08]], [0]], 'zero-state']], [['regression: random state 3', [2, [[0.379, 0.308], [-0.129, -0.524], [0.79, -0.299], [-0.403, -0.327]], [0, 1]], {'00': 0.157683, '01': 0.192532, '10': 0.471717, '11': 0.178068}], ['regression: random state 4', [1, [[-0.217, 0.525], [-0.308, -0.181]], [0]], {'0': 0.716602, '1': 0.283398}], ['regression: random state 2', [1, [[0.541, -0.923], [-0.479, -0.646]], [0]], {'0': 0.638959, '1': 0.361041}], ['control: reversed qubit list', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1, 0]], {'10': 1.0}], ['control: single qubit marginal of |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1]], {'0': 1.0}], ['control: out of range qubit equals n', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [2]], 'bad-qubit'], ['control: negative qubit index', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [-1]], 'bad-qubit']], [['regression: random state 6', [3, [[-0.119, 0.092], [0.264, -0.223], [-0.189, 0.034], [-0.22, -0.267], [-0.291, -0.092], [0.09, -0.02], [0.062, -0.284], [-0.239, 0.039]], [2]], {'0': 0.54953, '1': 0.45047}], ['regression: random state 7', [1, [[0.725, -0.825], [-0.233, -0.266]], [0]], {'0': 0.906073, '1': 0.093927}], ['regression: random state 4', [1, [[-0.217, 0.525], [-0.308, -0.181]], [0]], {'0': 0.716602, '1': 0.283398}], ['control: duplicate qubits', [2, [[0.6, 0], [0, 0.8], [0, 0], [0, 0]], [0, 0]], 'duplicate-qubit'], ['control: wrong amplitude count', [2, [[1, 0], [0, 0]], [0]], 'bad-length'], ['control: all-zero state', [1, [[0, 0], [0, 0]], [0]], 'zero-state'], ['control: near zero state', [1, [[1e-08, 0], [0, 1e-08]], [0]], 'zero-state']], [['regression: random state 9', [1, [[-0.25, -0.175], [0.0, 0.0]], [0]], {'0': 1.0}], ['regression: random state 10', [3, [[-0.064, 0.212], [0.264, -0.114], [-0.15, -0.24], [0.031, 0.141], [0.037, -0.002], [0.023, -0.229], [0.193, -0.153], [0.251, 0.097]], [0, 1, 2]], {'000': 0.116738, '001': 0.196846, '010': 0.190676, '011': 0.049614, '100': 0.003268, '101': 0.126094, '110': 0.144395, '111': 0.17237}], ['regression: random state 6', [3, [[-0.119, 0.092], [0.264, -0.223], [-0.189, 0.034], [-0.22, -0.267], [-0.291, -0.092], [0.09, -0.02], [0.062, -0.284], [-0.239, 0.039]], [2]], {'0': 0.54953, '1': 0.45047}], ['control: reversed qubit list', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1, 0]], {'10': 1.0}], ['control: single qubit marginal of |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], [1]], {'0': 1.0}], ['control: out of range qubit equals n', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [2]], 'bad-qubit'], ['control: negative qubit index', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], [-1]], 'bad-qubit']]]
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: bell state on both qubits | {'00': 0.5, '11': 0.5} | {'00': 0.5, '11': 0.5} | Passed |
| regression: tiny but valid state | {'0': 0.2, '1': 0.8} | {'0': 0.2, '1': 0.8} | Passed |
| regression: unnormalized pair | {'0': 0.36, '1': 0.64} | {'0': 0.36, '1': 0.64} | Passed |
| control: reversed qubit list | {'10': 1.0} | {'10': 1.0} | Passed |
| control: single qubit marginal of |01> | {'0': 1.0} | {'0': 1.0} | Passed |
| control: out of range qubit equals n | bad-qubit | bad-qubit | Passed |
| control: negative qubit index | bad-qubit | bad-qubit | Passed |
SHA-256 / e1ee3c6d21de2145173a646e58b28ead24e54ee8702890205629ee0931622da9
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:30.913204+00:00.
Case digest / 1c724af9f9700aa27ad67567146f277a70c8b053215c36deaa3b44cbac1e27aa