FA-90946 / Quantum circuit simulation / Open access
Pauli expectation ignores the state norm · case 01
For 3|0> + 4|1>, <Z> is reported as -7 instead of -0.28.
ROOT CAUSE
The raw quadratic form <psi|P|psi> is returned without dividing by <psi|psi>.
VERIFIED REPAIR
Divide by the squared norm of the state.
Unsuccessful approach: The attempted repair divides by the norm (square root), leaving a residual scale factor.
Case contract
Input [n, amps, pauli]; pauli is an n-character string over I,X,Y,Z whose rightmost character acts on qubit 0 (LSB). Return the real expectation <psi|P|psi>/<psi|psi> rounded to 6 decimals. Errors: "length-mismatch", "bad-pauli" (any character outside uppercase IXYZ).
Why this case matters
Pauli expectation values are the observable layer of variational algorithms; string-order or phase slips bias every energy estimate.
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, pauli = x
if len(pauli) != n:
return 'length-mismatch'
if any(c not in 'IXYZ' for c in pauli):
return 'bad-pauli'
psi = [complex(a, b) for a, b in amps]
acc = 0j
for i, v in enumerate(psi):
j = i
phase = 1 + 0j
for k, c in enumerate(pauli):
q = n - 1 - k
bit = (i >> q) & 1
if c in 'XY':
j ^= 1 << q
if c == 'Z' and bit:
phase = -phase
elif c == 'Y':
phase *= 1j if bit == 0 else -1j
acc += psi[j].conjugate() * phase * v
norm = sum(abs(v) ** 2 for v in psi)
return round(acc.real, 6) + 0.0
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0], ['regression: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0], ['regression: unnormalized Z', [1, [[3, 0], [0, 4]], 'Z'], -0.28], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch']], [['regression: random expectation 0', [1, [[0.071, 0.727], [-1.619, -1.464]], 'I'], 1.0], ['regression: random expectation 2', [1, [[0.489, 0.112], [-0.446, 0.868]], 'X'], -0.200793], ['regression: random expectation 3', [1, [[-0.119, -0.141], [0.0, 0.0]], 'Z'], 1.0], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch']], [['regression: random expectation 4', [1, [[-0.408, 0.461], [-0.359, 0.326]], 'Y'], 0.105809], ['regression: random expectation 5', [3, [[0.616, -0.07], [-0.126, -0.492], [-0.385, 0.046], [-0.714, -0.852], [0.968, -0.035], [-0.129, -0.794], [-0.299, 0.172], [0.772, -0.916]], 'YYZ'], -0.229604], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: random expectation 1', [1, [[0.0, 0.0], [1.97, 0.65]], 'X'], 0.0], ['control: random expectation 45', [1, [[0.0, 0.0], [-0.122, 1.228]], 'Y'], 0.0], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0]], [['regression: random expectation 7', [1, [[-1.206, 1.877], [0.69, -0.341]], 'I'], 1.0], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch'], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch']], [['regression: random expectation 10', [3, [[0.0, 0.0], [1.545, 0.342], [0.0, 0.0], [-1.862, -1.433], [0.0, 0.0], [-0.66, -1.507], [0.913, -1.017], [-1.982, -0.009]], 'IZX'], 0.21787], ['regression: random expectation 11', [1, [[-0.422, -1.932], [-1.435, 1.833]], 'Z'], -0.161676], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli']]]
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: Y on |+i> | 1.000001 | 1.0 | Failed |
| regression: X on |+> | 1.000001 | 1.0 | Failed |
| regression: unnormalized Z | -7.0 | -0.28 | Failed |
| control: ZI on |01> | 1.0 | 1.0 | Passed |
| control: IZ on |01> | -1.0 | -1.0 | Passed |
| control: short string | length-mismatch | length-mismatch | Passed |
| control: long string | length-mismatch | length-mismatch | Passed |
SHA-256 / c614b9866a65d284bc8a309a429fc5aefed8f3336171a58081a424ef682a800d
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, pauli = x
if len(pauli) != n:
return 'length-mismatch'
if any(c not in 'IXYZ' for c in pauli):
return 'bad-pauli'
psi = [complex(a, b) for a, b in amps]
acc = 0j
for i, v in enumerate(psi):
j = i
phase = 1 + 0j
for k, c in enumerate(pauli):
q = n - 1 - k
bit = (i >> q) & 1
if c in 'XY':
j ^= 1 << q
if c == 'Z' and bit:
phase = -phase
elif c == 'Y':
phase *= 1j if bit == 0 else -1j
acc += psi[j].conjugate() * phase * v
norm = sum(abs(v) ** 2 for v in psi)
return round((acc / math.sqrt(norm)).real, 6) + 0.0
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0], ['regression: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0], ['regression: unnormalized Z', [1, [[3, 0], [0, 4]], 'Z'], -0.28], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch']], [['regression: random expectation 0', [1, [[0.071, 0.727], [-1.619, -1.464]], 'I'], 1.0], ['regression: random expectation 2', [1, [[0.489, 0.112], [-0.446, 0.868]], 'X'], -0.200793], ['regression: random expectation 3', [1, [[-0.119, -0.141], [0.0, 0.0]], 'Z'], 1.0], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch']], [['regression: random expectation 4', [1, [[-0.408, 0.461], [-0.359, 0.326]], 'Y'], 0.105809], ['regression: random expectation 5', [3, [[0.616, -0.07], [-0.126, -0.492], [-0.385, 0.046], [-0.714, -0.852], [0.968, -0.035], [-0.129, -0.794], [-0.299, 0.172], [0.772, -0.916]], 'YYZ'], -0.229604], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: random expectation 1', [1, [[0.0, 0.0], [1.97, 0.65]], 'X'], 0.0], ['control: random expectation 45', [1, [[0.0, 0.0], [-0.122, 1.228]], 'Y'], 0.0], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0]], [['regression: random expectation 7', [1, [[-1.206, 1.877], [0.69, -0.341]], 'I'], 1.0], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch'], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch']], [['regression: random expectation 10', [3, [[0.0, 0.0], [1.545, 0.342], [0.0, 0.0], [-1.862, -1.433], [0.0, 0.0], [-0.66, -1.507], [0.913, -1.017], [-1.982, -0.009]], 'IZX'], 0.21787], ['regression: random expectation 11', [1, [[-0.422, -1.932], [-1.435, 1.833]], 'Z'], -0.161676], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli']]]
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: Y on |+i> | 1.0 | 1.0 | Passed |
| regression: X on |+> | 1.0 | 1.0 | Passed |
| regression: unnormalized Z | -1.4 | -0.28 | Failed |
| control: ZI on |01> | 1.0 | 1.0 | Passed |
| control: IZ on |01> | -1.0 | -1.0 | Passed |
| control: short string | length-mismatch | length-mismatch | Passed |
| control: long string | length-mismatch | length-mismatch | Passed |
SHA-256 / 0f034a95e29e1a1da7a43099bcb75d2c236719f4aaa135e633289db530a973ae
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, pauli = x
if len(pauli) != n:
return 'length-mismatch'
if any(c not in 'IXYZ' for c in pauli):
return 'bad-pauli'
psi = [complex(a, b) for a, b in amps]
acc = 0j
for i, v in enumerate(psi):
j = i
phase = 1 + 0j
for k, c in enumerate(pauli):
q = n - 1 - k
bit = (i >> q) & 1
if c in 'XY':
j ^= 1 << q
if c == 'Z' and bit:
phase = -phase
elif c == 'Y':
phase *= 1j if bit == 0 else -1j
acc += psi[j].conjugate() * phase * v
norm = sum(abs(v) ** 2 for v in psi)
return round((acc / norm).real, 6) + 0.0
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0], ['regression: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0], ['regression: unnormalized Z', [1, [[3, 0], [0, 4]], 'Z'], -0.28], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch']], [['regression: random expectation 0', [1, [[0.071, 0.727], [-1.619, -1.464]], 'I'], 1.0], ['regression: random expectation 2', [1, [[0.489, 0.112], [-0.446, 0.868]], 'X'], -0.200793], ['regression: random expectation 3', [1, [[-0.119, -0.141], [0.0, 0.0]], 'Z'], 1.0], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch']], [['regression: random expectation 4', [1, [[-0.408, 0.461], [-0.359, 0.326]], 'Y'], 0.105809], ['regression: random expectation 5', [3, [[0.616, -0.07], [-0.126, -0.492], [-0.385, 0.046], [-0.714, -0.852], [0.968, -0.035], [-0.129, -0.794], [-0.299, 0.172], [0.772, -0.916]], 'YYZ'], -0.229604], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: random expectation 1', [1, [[0.0, 0.0], [1.97, 0.65]], 'X'], 0.0], ['control: random expectation 45', [1, [[0.0, 0.0], [-0.122, 1.228]], 'Y'], 0.0], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0]], [['regression: random expectation 7', [1, [[-1.206, 1.877], [0.69, -0.341]], 'I'], 1.0], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch'], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch']], [['regression: random expectation 10', [3, [[0.0, 0.0], [1.545, 0.342], [0.0, 0.0], [-1.862, -1.433], [0.0, 0.0], [-0.66, -1.507], [0.913, -1.017], [-1.982, -0.009]], 'IZX'], 0.21787], ['regression: random expectation 11', [1, [[-0.422, -1.932], [-1.435, 1.833]], 'Z'], -0.161676], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli']]]
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: Y on |+i> | 1.0 | 1.0 | Passed |
| regression: X on |+> | 1.0 | 1.0 | Passed |
| regression: unnormalized Z | -0.28 | -0.28 | Passed |
| control: ZI on |01> | 1.0 | 1.0 | Passed |
| control: IZ on |01> | -1.0 | -1.0 | Passed |
| control: short string | length-mismatch | length-mismatch | Passed |
| control: long string | length-mismatch | length-mismatch | Passed |
SHA-256 / da7a4cfd0565aefc0021f0689964d12f029e14ee080bf91dbe296cf28043489d
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:31.534136+00:00.
Case digest / e032da0d61e6c940603b89dbd1d3ade3f86886012743d66209a02d892f32e00e