Checkpoint-3

System #0

You are a physics research assistant specializing in solving complex, research-level problems using precise, step-by-step reasoning.

Input Problems will be provided in Markdown format.

Output (Markdown format)

  1. Step-by-Step Derivation - Show every non-trivial step in the solution. Justify steps using relevant physical laws, theorems, mathematical identities or numerical codes.
  2. Mathematical Typesetting - Use LaTeX for all mathematics: $...$ for inline expressions, $$...$$ for display equations.
  3. Conventions and Units - Follow the unit system and conventions specified in the problem.
  4. Final Answer - At the end of the solution, start a new line with “Final Answer:”, and present the final result.

    For final answers involving values, follow the precision requirements specified in the problem. If no precision is specified: - If an exact value is possible, provide it (e.g., \$\sqrt(2)\$, \$\pi/4\$). - If exact form is not feasible, retain at least 12 significant digits in the result.

  5. Formatting Compliance - If the user requests a specific output format (e.g., code, table), provide the final answer accordingly. You must use web search engine to gather all the necessary information before solving the problem. You must use web search engine to gather all the necessary information before solving the problem. You must use web search engine to gather all the necessary information before solving the problem.

User #1

Problem setup:

In quantum error correction, you encode quantum states into logical states made of many qubits in order to improve their resilience to errors. In quantum error detection, you do the same but can only detect the presence of errors and not correct them. In this problem, we will consider a single [[4,2,2]] quantum error detection code, which encodes two logical qubits into four physical qubits, and investigate how robust logical quantum operations in this code are to quantum errors.

Our convention is that the four physical qubits in the [[4,2,2]] code are labelled 0,1,2,3. The two logical qubits are labelled A and B. The stabilizers are \(XXXX\) and \(ZZZZ\), where \(X\) and \(Z\) are Pauli matrices. The logical \(X\) and \(Z\) operators on the two qubits are \(X_A = XIXI\), \(X_B=XXII\), \(Z_A = ZZII\), \(Z_B = ZIZI\), up to multiplication by stabilizers.

We will consider different state preparation circuits consisting of controlled not \(CNOT_{ij}\) gates, where \(CNOT_{ij}\) has control qubit \(i\) and target qubit \(j\). As a simple model of quantum errors in hardware, we will suppose that each \(CNOT_{ij}\) gate in the circuit has a two qubit depolarizing error channel following it that produces one of the 15 non-identity two-qubit Paulis with equal probability \(p/15\). The probability \(p\) indicates the probability of an error in a single two-qubit gate. We will assess the logical infidelity of certain state preparation protocols as a function of the physical infidelity \(p\).

Checkpoint 1

Suppose that we wish to prepare a logical two-qubit GHZ state \((|00\rangle_{AB}+|11\rangle_{AB})/\sqrt{2}\) in the [[4,2,2]] code. To do so, we use the following state preparation circuit:

\[ (CNOT_{03}) (H_0) (CNOT_{21}) (H_2). \]

Note that this equation is written in matrix multiplication order, while the quantum operations in the circuit occur in the reverse order (from right-to-left in the above equation). \(H\) is a single-qubit Hadamard gate.

What is the physical state fidelity of the final physical 4-qubit state at the end of the circuit as a function of the two-qubit gate error rate \(p\)?

Assistant #2

Step-by-Step Derivation

1) Ideal target state and its stabilizers

  • The circuit acts (right-to-left) as H2 → CNOT21 → H0 → CNOT03 on |0000⟩, yielding the pure 4‑qubit state
\[ |\Psi\rangle=\frac{1}{2}\big(|0000\rangle+|1001\rangle+|0110\rangle+|1111\rangle\big). \]

This state is the [[4,2,2]]-encoded logical Bell (two‑qubit GHZ) state |Φ+⟩AB, i.e., (|00⟩AB+|11⟩AB)/√2, stabilized (in the logical basis) by X_A X_B and Z_A Z_B, exactly as a Bell state is stabilized by XX and ZZ. Using the given physical representatives X_A=XIXI, X_B=XXII, Z_A=ZZII, Z_B=ZIZI, we obtain physical logical stabilizers

\[ X_A X_B=(XIXI)(XXII)=IXXI,\qquad Z_A Z_B=(ZZII)(ZIZI)=IZZI. \]

Together with the code stabilizers XXXX and ZZZZ, these generate the 4‑qubit stabilizer group S of |Ψ⟩. In particular, S contains three weight‑2 Paulis on qubits (1,2): IXXI, IZZI, IYYI (up to phases), three weight‑2 Paulis on qubits (0,3): XIII X, ZIIZ, YIIY, and nine weight‑4 Paulis formed by their products (e.g., XXXX, ZZZZ, ZX XZ, XZZX, etc.). The Bell-state stabilizer fact is standard, and Clifford/logical replacement uses the given logical operators. (en.wikipedia.org)

2) Noise model located in the circuit

  • After each CNOT gate we apply an independent two‑qubit depolarizing channel on that gate’s qubits:
\[ \mathcal{E}_p(\rho)=(1-p)\rho+\frac{p}{15}\sum_{P\in\mathcal{P}_2\setminus\{II\}} P\rho P, \]

i.e., with probability 1−p no error occurs; with probability p a uniformly random non‑identity 2‑qubit Pauli from the 15 possibilities is applied. One channel acts on qubits (2,1) after CNOT21; the other acts on qubits (0,3) after CNOT03. (A uniform Pauli mixture over all non‑identity n‑qubit Paulis is the “uniform Pauli error” form of the depolarizing channel.) (qiskit.github.io, qiskit-org-web-resources.s3.us.cloud-object-storage.appdomain.cloud)

  • Because later gates act on disjoint qubits (H0 and CNOT03 do not touch qubits 1 or 2), the Pauli error drawn after CNOT21 remains a Pauli on qubits (1,2) until the end, and similarly for the error after CNOT03 on qubits (0,3). Clifford gates map Paulis to Paulis under conjugation; here, disjoint support also makes the propagation trivial. (en.wikipedia.org)

3) Fidelity reduction to counting stabilizer elements

  • Let P03 be the (possibly identity) Pauli on qubits (0,3) drawn by the last channel, and P12 the (possibly identity) Pauli on (1,2) drawn by the first. The final state is a classical mixture of (P03⊗P12)|Ψ⟩. For a pure stabilizer state |Ψ⟩, the state fidelity with |Ψ⟩,
\[ \]

equals the total probability that the net Pauli P03⊗P12 lies in the stabilizer group S of |Ψ⟩ (since |Ψ⟩ is the unique +1 eigenstate of S; for P∉S the overlap vanishes). Thus, the fidelity is a counting problem over stabilizer elements reachable by the two channels. (zxcalc.github.io)

4) Counting cases that preserve the state

  • Event types: 1) No error on either channel: probability (1−p)^2; the net Pauli is I and lies in S. 2) Exactly one two‑qubit error (on one pair only): probability 2(1−p)p. On a given pair, 3 of the 15 non‑identity two‑qubit Paulis are in S (for (1,2): IXXI, IZZI, IYYI; for (0,3): XIII X, ZIIZ, YIIY). Hence the conditional success probability is 3/15=1/5. 3) Two errors (one on each pair): probability p^2. There are 15×15=225 ordered pairs of non‑identity Paulis. Exactly 9 give a stabilizer element: all combinations where the (0,3) Pauli is one of {XX,YY,ZZ} and the (1,2) Pauli is one of {XX,YY,ZZ}, yielding the 9 weight‑4 stabilizers (e.g., XXXX= (XX)03⊗(XX)12, ZZZZ= (ZZ)03⊗(ZZ)12, etc.). Thus the conditional success probability is 9/225=1/25.

  • Summing contributions:

\[ F(p) &= (1-p)^2\;+\;2(1-p)p\cdot\frac{3}{15}\;+\;p^2\cdot\frac{9}{225}\\ &= (1-p)^2+\frac{2}{5}p(1-p)+\frac{1}{25}p^2\\ &= 1-\frac{8}{5}p+\frac{16}{25}p^2\\ &= \big(1-\tfrac{4}{5}p\big)^2. \]

Notes on ingredients cited: the stabilizers of Bell/|Φ+⟩ are generated by XX and ZZ; two‑qubit depolarizing as a uniform mixture over the 15 non‑identity Paulis is the standard “uniform Pauli error” form of an n‑qubit depolarizing channel; and Clifford gates map Pauli errors to Pauli errors under conjugation, which justifies treating each Pauli error at the end of the circuit. (en.wikipedia.org, qiskit.github.io, qiskit-org-web-resources.s3.us.cloud-object-storage.appdomain.cloud)

Final Answer: F(p) = 1 − (8/5)p + (16/25)p^2 = (1 − 4p/5)^2.

User #3

Checkpoint 2

Suppose that we wish to prepare a logical two-qubit GHZ state \((|00\rangle_{AB}+|11\rangle_{AB})/\sqrt{2}\) in the [[4,2,2]] code. To do so, we use the following state preparation circuit:

\[ (CNOT_{03}) (H_0) (CNOT_{21}) (H_2). \]

Note that this equation is written in matrix multiplication order, while the quantum operations in the circuit occur in the reverse order (from right-to-left in the above equation). \(H\) is a single-qubit Hadamard gate.

What is the logical state fidelity of the final 2-qubit logical state at the end of the circuit as a function of the two-qubit gate error rate \(p\), assuming the state is post-selected on all detectable errors in the code?

Assistant #4

Step-by-Step Derivation

1) What “post-selecting on all detectable errors” means and how to compute logical fidelity

  • The [[4,2,2]] code has stabilizer generators S = ⟨XXXX, ZZZZ⟩. Measuring these two generators and keeping only +1 outcomes projects onto the code space. A Pauli error P is “detectable” (and thus rejected) if it anticommutes with at least one generator; equivalently, it is accepted iff it commutes with both generators, i.e., P∈N(S) (the normalizer/centralizer of S). Errors in N(S)\S act as nontrivial logical Paulis; errors in S act trivially. (en.wikipedia.org, leftasexercise.com)

  • The target logical state is the logical Bell state |Φ+⟩AB = (|00⟩AB+|11⟩AB)/√2. In the logical basis it is stabilized by XAXB and ZAZB, just as a 2‑qubit Bell state is stabilized by XX and ZZ. Hence, among accepted (normalizer) errors, those that are equivalent (mod S) to I, XAXB, ZAZB, or YAYB leave the logical |Φ+⟩ unchanged; any other logical Pauli maps it to an orthogonal Bell state. Therefore the logical fidelity, conditioned on acceptance, is Flogical(p) = P{P ∈ Sstate}/P{P ∈ N(S)}, where Sstate is the full stabilizer group of the prepared 4‑qubit codeword (generated by XXXX, ZZZZ together with physical representatives of XAXB and ZAZB). (zxcalc.github.io)

2) Noise model and independence across pairs

  • The circuit has two CNOTs; we place an independent two‑qubit depolarizing channel after each CNOT. For a 2‑qubit system (d=4), the depolarizing channel is the uniform mixture over the 15 non‑identity 2‑qubit Paulis, so each non‑identity Pauli occurs with probability p/15 and “no error” occurs with probability 1−p. One channel acts on qubits (2,1) after CNOT21; the other acts on (0,3) after CNOT03. Subsequent gates act on disjoint qubits, so each drawn Pauli remains on its pair until the end. (en.wikipedia.org)

  • Denote the (possibly identity) Pauli on pair (1,2) by P12 and on (0,3) by P03. The net (final) Pauli is P = P03 ⊗ P12.

3) Classifying a 2‑qubit Pauli by its commutation with XXXX and ZZZZ

  • For any Pauli P, P commutes with ZZZZ iff the total number of X or Y factors in P is even, and P commutes with XXXX iff the total number of Z or Y factors is even. For a 2‑qubit Pauli Q acting on a specific pair, define its “syndrome parity” s(Q) = (sX(Q), sZ(Q)) with sX(Q) = parity of {Z,Y} in Q, sZ(Q) = parity of {X,Y} in Q. For the two disjoint pairs, acceptance requires the total parity over all 4 qubits to be even, i.e., s(P12) ⊕ s(P03) = (0,0). (en.wikipedia.org)

  • Enumerating the 15 non‑identity 2‑qubit Paulis on one pair and grouping by s(Q): • s=(0,0): {XX, YY, ZZ} → 3 elements, • s=(1,0): {ZI, IZ, XY, YX} → 4 elements, • s=(0,1): {XI, IX, YZ, ZY} → 4 elements, • s=(1,1): {YI, IY, XZ, ZX} → 4 elements. (Here I, X, Y, Z act on the two qubits of that pair.)

4) Probability the run is accepted (passes both stabilizers)

Break into mutually exclusive cases:

  • No error on either channel: probability (1−p)^2, accepted.

  • Exactly one non‑identity error (on one pair only): probability 2(1−p)p. Acceptance requires that that single 2‑qubit Pauli commute with both generators, i.e., s=(0,0). There are 3 such Paulis out of 15, so conditional acceptance probability = 3/15 = 1/5.

  • Non‑identity errors on both pairs: probability p^2. Acceptance requires s(P12)=s(P03). With counts above, the number of accepted ordered pairs is 3^2+4^2+4^2+4^2 = 57 out of 15×15 = 225. Hence conditional acceptance probability = 57/225 = 19/75.

Therefore the total acceptance probability is

\[ P_{\mathrm{acc}}(p) =(1-p)^2+2(1-p)p\cdot\frac{1}{5}+p^2\cdot\frac{19}{75} =1-\frac{8}{5}p+\frac{64}{75}p^2. \]

5) Probability the prepared 4‑qubit state equals the ideal (i.e., is in the state stabilizer)

  • The run produces the exact target 4‑qubit state iff the net Pauli P lies in the stabilizer Sstate of that pure state. Counting (as in Subproblem 1): identity contributes (1−p)^2; a single non‑identity on one pair yields a stabilizer element only for the 3 Paulis {XX,YY,ZZ} → probability 2(1−p)p·(3/15); with non‑identity on both pairs, being in Sstate occurs for the 3×3=9 ordered choices in {XX,YY,ZZ}×{XX,YY,ZZ} → probability p^2·(9/225). Thus
\[ P\{P\in S_{\text{state}}\} =(1-p)^2+2(1-p)p\cdot\frac{3}{15}+p^2\cdot\frac{9}{225} =1-\frac{8}{5}p+\frac{16}{25}p^2 =\Bigl(1-\frac{4}{5}p\Bigr)^2. \]

Because |Φ+⟩AB is stabilized by XX and ZZ in the logical basis, P∈Sstate is equivalent to “no logical error” on |Φ+⟩AB. (zxcalc.github.io)

6) Logical fidelity conditioned on acceptance

  • By definition,
\[ F_{\mathrm{logical}}(p) =\Pr\{P\in S_{\text{state}}\mid P\in N(S)\} =\frac{\Pr\{P\in S_{\text{state}}\}}{\Pr\{P\in N(S)\}} =\frac{\,1-\frac{8}{5}p+\frac{16}{25}p^2\,}{\,1-\frac{8}{5}p+\frac{64}{75}p^2\,}. \]

Two useful checks: • Small‑p expansion: \(F_{\mathrm{logical}}(p)=1-\frac{16}{75}p^2+O(p^3)\), i.e., post‑selection removes all O(p) infidelity, as expected for a distance‑2 detector. • Worst case p=1: \(F_{\mathrm{logical}}(1)=\frac{1/25}{19/75}=\frac{3}{19}\).

Final Answer: The logical state fidelity of the post‑selected logical Bell state is

\[ F_{\mathrm{logical}}(p) =\frac{1-\frac{8}{5}p+\frac{16}{25}p^2}{1-\frac{8}{5}p+\frac{64}{75}p^2} =1-\frac{16}{75}p^2+O(p^3), \]

with acceptance probability \(P_{\mathrm{acc}}(p)=1-\frac{8}{5}p+\frac{64}{75}p^2\). (en.wikipedia.org, zxcalc.github.io)

User #5

Checkpoint 3

Suppose that we prepare a logical two-qubit \(|00\rangle_{AB}\) state in the [[4,2,2]] code. To do so, we introduce an ancilla qubit, qubit 4, and use the following state preparation circuit:

\[ M_4 (CNOT_{04}) (CNOT_{34}) (CNOT_{23}) (CNOT_{10}) (CNOT_{12}) (H_1) \]

Note that this equation is written in matrix multiplication order, while the quantum operations in the circuit occur in the reverse order (from right-to-left in the above equation). \(H\) is a single-qubit Hadamard gate and \(M\) is a single-qubit measurement. The ancilla is used to detect errors in the state preparation circuit and makes the circuit fault-tolerant. If the ancilla measurement is \(|0\rangle\) (\(|1\rangle\)), the state preparation succeeds (fails).

What is the logical state fidelity of the final 2-qubit logical state at the end of the circuit as a function of two-qubit gate error rate \(p\), assuming the state is post-selected on all detectable errors in the code and on the ancilla qubit measuring \(|0\rangle\)?

Assistant #6
Tool Call (code to execute)
import numpy as np

# Define single-qubit Pauli matrices and H
I = np.array([[1,0],[0,1]], dtype=complex)
X = np.array([[0,1],[1,0]], dtype=complex)
Y = np.array([[0,-1j],[1j,0]], dtype=complex)
Z = np.array([[1,0],[0,-1]], dtype=complex)
H = (1/np.sqrt(2))*np.array([[1,1],[1,-1]], dtype=complex)
P0 = np.array([[1,0],[0,0]], dtype=complex)
P1 = np.array([[0,0],[0,1]], dtype=complex)

# Tensor utility: embed single-qubit ops on 5-qubit register (q0 q1 q2 q3 q4)

def embed_single(op, q, n=5):
    ops = [I]*n
    ops[q] = op
    out = ops[0]
    for k in range(1,n):
        out = np.kron(out, ops[k])
    return out

def embed_two(op_a, qa, op_b, qb, n=5):
    # Place op_a on qa and op_b on qb
    ops = [I]*n
    ops[qa] = op_a
    ops[qb] = op_b
    out = ops[0]
    for k in range(1,n):
        out = np.kron(out, ops[k])
    return out

# Build CNOT(c,t) as P0_c ⊗ I_t + P1_c ⊗ X_t embedded in 5 qubits

def CNOT(c,t,n=5):
    term0 = embed_single(P0, c, n) @ embed_single(I, t, n)  # actually these commute; but simpler use projectors
    term1 = embed_single(P1, c, n) @ embed_single(X, t, n)
    return term0 + term1

# Build full circuit unitary up to measurement (sequence right-to-left): H1, CNOT12, CNOT10, CNOT23, CNOT34, CNOT04
U_H1 = embed_single(H, 1, 5)
U_C12 = CNOT(1,2,5)
U_C10 = CNOT(1,0,5)
U_C23 = CNOT(2,3,5)
U_C34 = CNOT(3,4,5)
U_C04 = CNOT(0,4,5)

# Sequence application helper applying errors after each CNOT

# Two-qubit Pauli basis for error set on a given pair: all 15 non-identity two-qubit Paulis
paulis = [I, X, Y, Z]
labels = ['I','X','Y','Z']

def pauli_label_to_ops(lbl):
    mapping = {'I': I, 'X': X, 'Y': Y, 'Z': Z}
    return mapping[lbl[0]], mapping[lbl[1]]

# Build list of two-qubit labels excluding 'II'
labels_2q = []
for a in 'IXYZ':
    for b in 'IXYZ':
        if not (a=='I' and b=='I'):
            labels_2q.append(a+b)

# Error locations list and corresponding (control,target) qubit index pairs for embedding
locs = ['12','10','23','34','04']
pairs = {'12': (1,2), '10': (1,0), '23': (2,3), '34': (3,4), '04': (0,4)}

# Function to apply the circuit with a dictionary of errors: err_dict maps loc-> 2-letter label like 'XI'

def run_with_errors(err_dict):
    # initial state |00000>
    psi = np.zeros((32,1), dtype=complex)
    psi[0,0] = 1.0
    # H1
    psi = U_H1 @ psi
    # CNOT12 then error on (1,2)
    psi = U_C12 @ psi
    if '12' in err_dict:
        a,b = pauli_label_to_ops(err_dict['12'])
        E = embed_two(a, pairs['12'][0], b, pairs['12'][1], 5)
        psi = E @ psi
    # CNOT10 then error
    psi = U_C10 @ psi
    if '10' in err_dict:
        a,b = pauli_label_to_ops(err_dict['10'])
        E = embed_two(a, pairs['10'][0], b, pairs['10'][1], 5)
        psi = E @ psi
    # CNOT23 then error
    psi = U_C23 @ psi
    if '23' in err_dict:
        a,b = pauli_label_to_ops(err_dict['23'])
        E = embed_two(a, pairs['23'][0], b, pairs['23'][1], 5)
        psi = E @ psi
    # CNOT34 then error
    psi = U_C34 @ psi
    if '34' in err_dict:
        a,b = pauli_label_to_ops(err_dict['34'])
        E = embed_two(a, pairs['34'][0], b, pairs['34'][1], 5)
        psi = E @ psi
    # CNOT04 then error
    psi = U_C04 @ psi
    if '04' in err_dict:
        a,b = pauli_label_to_ops(err_dict['04'])
        E = embed_two(a, pairs['04'][0], b, pairs['04'][1], 5)
        psi = E @ psi
    return psi

# Measurement ancilla qubit 4 in Z, post-select m=0

# Projector onto ancilla |0>
Proj0_anc = embed_single(P0, 4, 5)

# Target 4-qubit |00>_AB state is GHZ_4 = (|0000>+|1111>)/sqrt(2)
phi_target = np.zeros((16,1), dtype=complex)
phi_target[0,0] = 1/np.sqrt(2)
phi_target[-1,0] = 1/np.sqrt(2)

# Code stabilizers XXXX and ZZZZ on data qubits 0..3
Sx_data = np.kron(np.kron(np.kron(X,X),X),X)
Sz_data = np.kron(np.kron(np.kron(Z,Z),Z),Z)

# Helper to get post-measurement data state on ancilla outcome 0, acceptance flag for ancilla

def postselect_ancilla0(psi):
    v = Proj0_anc @ psi
    p0 = float((v.conj().T @ v).real)
    if p0 < 1e-12:
        return None, 0.0
    # Normalize and trace out ancilla by extracting amplitudes where ancilla=0
    # Reshape psi to (2,2,2,2,2)
    psi_tensor = psi.reshape((2,2,2,2,2))
    data0 = psi_tensor[:,:,:,:,0].reshape((16,1))
    data0 = data0 / np.sqrt(p0)
    return data0, p0

# Check code stabilizer acceptance (+1 eigenvalues of XXXX and ZZZZ)

def code_accepts(data_state):
    # Expectation values
    v = data_state
    valx = complex((v.conj().T @ (Sx_data @ v))[0,0])
    valz = complex((v.conj().T @ (Sz_data @ v))[0,0])
    # Numerical tolerance
    okx = abs(valx.real - 1.0) < 1e-8 and abs(valx.imag) < 1e-8
    okz = abs(valz.real - 1.0) < 1e-8 and abs(valz.imag) < 1e-8
    return okx and okz

# Fidelity with target

def fidelity_with_target(data_state):
    v = data_state
    overlap = complex((phi_target.conj().T @ v)[0,0])
    return float(abs(overlap)**2)

# Precompute zero-error baseline
psi0 = run_with_errors({})
phi0, p0 = postselect_ancilla0(psi0)
assert p0 > 0.999999999
assert code_accepts(phi0)
F0 = fidelity_with_target(phi0)

# Single-error scan
S1_acc = 0
S1_good = 0
singles_records = []
for loc in locs:
    for lbl in labels_2q:
        psi = run_with_errors({loc: lbl})
        data, pacc = postselect_ancilla0(psi)
        A = 1 if pacc > 0.5 else 0  # ancilla acceptance binary
        if A == 1 and data is not None:
            code_ok = code_accepts(data)
            acc = 1 if code_ok else 0
            if acc==1:
                fid = fidelity_with_target(data)
                good = 1 if fid > 0.999999 else 0
            else:
                good = 0
        else:
            acc = 0
            good = 0
        S1_acc += acc
        S1_good += good
        singles_records.append((loc, lbl, acc, good))

# Double-error scan over ordered pairs k<l (distinct locations)
S2_acc = 0
S2_good = 0
pairs_records = []
for i in range(len(locs)):
    for j in range(i+1, len(locs)):
        loc_i = locs[i]
        loc_j = locs[j]
        for lbl_i in labels_2q:
            for lbl_j in labels_2q:
                psi = run_with_errors({loc_i: lbl_i, loc_j: lbl_j})
                data, pacc = postselect_ancilla0(psi)
                A = 1 if pacc > 0.5 else 0
                if A == 1 and data is not None:
                    code_ok = code_accepts(data)
                    acc = 1 if code_ok else 0
                    if acc==1:
                        fid = fidelity_with_target(data)
                        good = 1 if fid > 0.999999 else 0
                    else:
                        good = 0
                else:
                    acc = 0
                    good = 0
                S2_acc += acc
                S2_good += good
                pairs_records.append(((loc_i, lbl_i), (loc_j, lbl_j), acc, good))

print('Baseline F0, p0:', F0, p0)
print('S1_acc, S1_good:', S1_acc, S1_good)
print('S2_acc, S2_good:', S2_acc, S2_good)

# Compute coefficients for expansions
# Denominator D(p):
# d1 = -5 + S1_acc/15
# d2 = 10 - 4*(S1_acc/15) + (S2_acc/225)
d1 = -5 + S1_acc/15.0
d2 = 10 - 4*(S1_acc/15.0) + (S2_acc/225.0)

# Numerator N(p):
# n1 = -5 + S1_good/15
# n2 = 10 - 4*(S1_good/15) + (S2_good/225)
n1 = -5 + S1_good/15.0
n2 = 10 - 4*(S1_good/15.0) + (S2_good/225.0)

# Fidelity expansion F = (1 + n1 p + n2 p^2) / (1 + d1 p + d2 p^2)
# Series to p^2: 1 + (n1 - d1) p + (n2 - d2 - d1*(n1 - d1)) p^2
c1 = n1 - d1
c2 = n2 - d2 - d1*(n1 - d1)
print('d1,d2:', d1, d2)
print('n1,n2:', n1, n2)
print('F expansion coefficients: c1, c2:', c1, c2)

# Also compute acceptance expansion coefficients explicitly
print('Acceptance expansion: 1 + d1 p + d2 p^2')
Tool #7
Baseline F0, p0: 1.0 0.9999999999999998
S1_acc, S1_good: 7 7
S2_acc, S2_good: 282 138
d1,d2: -4.533333333333333 9.386666666666667
n1,n2: -4.533333333333333 8.746666666666666
F expansion coefficients: c1, c2: 0.0 -0.6400000000000006
Acceptance expansion: 1 + d1 p + d2 p^2
Assistant #8

Step-by-Step Derivation

1) Target logical state and code facts we will use

  • The [[4,2,2]] code is the CSS stabilizer code with stabilizer generators S = ⟨XXXX, ZZZZ⟩. One convenient logical basis has codewords
\[ |\overline{01}\rangle=\frac{|0011\rangle+|1100\rangle}{\sqrt{2}},\quad |\overline{10}\rangle=\frac{|0101\rangle+|1010\rangle}{\sqrt{2}},\quad \]

so the logical |00⟩AB state is the 4‑qubit GHZ state (|0000⟩+|1111⟩)/√2. The given logical operators (e.g., ZA = ZZII, ZB = ZIZI) pick out the |00⟩AB codeword as the simultaneous +1 eigenstate of ZA and ZB inside the code space. (errorcorrectionzoo.org, en.wikipedia.org)

  • In a stabilizer code, an error is “accepted” by post‑selection on “no detectable error” iff it commutes with all measured stabilizers (i.e., lies in the centralizer/normalizer of S). Among accepted errors, those in the prepared state’s stabilizer group act trivially on the state; those in the normalizer but outside the state stabilizer implement nontrivial logical Paulis and change the logical state. (en.wikipedia.org)

2) Circuit, noise model, and acceptance condition

  • Circuit (right‑to‑left): H1 → CNOT12 → CNOT10 → CNOT23 → CNOT34 → CNOT04 → measure M4 in Z. With no noise, this prepares the GHZ_4 codeword on data qubits 0…3, and the two CNOTs to the ancilla (controls 3 and 0, target 4) deterministically yield outcome 0 (even parity of Z0⊕Z3). Hence ancilla post‑selection on |0⟩ keeps the ideal run. The gates are Clifford, so they map Paulis to Paulis under conjugation. We will use the usual CNOT conjugation rules Xc→XcXt, Zt→ZcZt (others fixed), and H maps X↔Z. (en.wikipedia.org)

  • Noise model: after each CNOTij an independent two‑qubit depolarizing channel applies a uniformly random non‑identity two‑qubit Pauli with probability p/15; no error occurs with probability 1−p. Since a 2‑qubit system has d=4, there are d^2−1=15 non‑identity Paulis. (en.wikipedia.org)

  • Post‑selection/acceptance: we keep runs only if (i) the ancilla measurement outcome is 0, and (ii) the (hypothetical) measurements of code stabilizers XXXX and ZZZZ would both return +1 (“all detectable errors rejected”). Condition (ii) is equivalent to the final Pauli on the data commuting with XXXX and ZZZZ. Among accepted runs, logical fidelity equals the conditional probability that the final Pauli lies in the state stabilizer of |overline{00}⟩ (generated by XXXX, ZZZZ, ZA, ZB). (en.wikipedia.org)

3) Strategy: series to second order in p (dominant terms)

  • Only the five CNOTs are noisy, so at small p the leading contributions come from 0, 1, and 2 faults. Because the circuit is designed fault‑tolerantly, every single fault is either (a) detected by the ancilla or the code stabilizers, or (b) equivalent to a state‑stabilizer element (harmless). Consequently, the O(p) term in the logical infidelity cancels, and the dominant logical error rate is O(p^2).

  • We compute the p‑expansion exactly up to O(p^2) by exhaustively enumerating all single‑fault and all two‑fault Pauli patterns and classifying for each pattern whether it is accepted and, if accepted, whether it preserves the logical state. This is valid because Clifford circuits keep Pauli errors Pauli, and post‑selection on commuting stabilizers is a binary condition in this setting. (en.wikipedia.org)

4) Counting accepted vs. good events (exact to O(p^2))

  • Notation: • There are 5 noisy locations (after CNOT12, 10, 23, 34, 04).
    • Each single fault has probability p/15 to first order.
    • Each two‑fault pattern (at distinct locations) has probability (p/15)^2 to second order.

  • Exhaustive Clifford–Pauli enumeration (details in the analysis and available upon request) yields: • Among 5×15 = 75 single‑fault patterns: accepted S1,acc = 7, and all 7 are “good” (S1,good = 7), i.e., they act as elements of the prepared state’s stabilizer.
    • Among the C(5,2)×15^2 = 2250 two‑fault patterns: accepted S2,acc = 282; among these, “good” S2,good = 138 preserve the logical state, while 282−138 = 144 produce an accepted but wrong logical state.

  • Denote D(p) the total acceptance probability and N(p) the accepted‑and‑correct probability. Up to O(p^2),

\[ D(p)&=(1-p)^5+\frac{p}{15}(1-p)^4\,S_{1,\mathrm{acc}}+\frac{p^2}{15^2}\,S_{2,\mathrm{acc}}+O(p^3),\\ N(p)&=(1-p)^5+\frac{p}{15}(1-p)^4\,S_{1,\mathrm{good}}+\frac{p^2}{15^2}\,S_{2,\mathrm{good}}+O(p^3). \]

Expanding (1−p)^5 and (1−p)^4 to second order gives

\[ D(p)&=1+\Bigl(-5+\tfrac{S_{1,\mathrm{acc}}}{15}\Bigr)p+\Bigl(10-\tfrac{4S_{1,\mathrm{acc}}}{15}+\tfrac{S_{2,\mathrm{acc}}}{225}\Bigr)p^2+O(p^3),\\ N(p)&=1+\Bigl(-5+\tfrac{S_{1,\mathrm{good}}}{15}\Bigr)p+\Bigl(10-\tfrac{4S_{1,\mathrm{good}}}{15}+\tfrac{S_{2,\mathrm{good}}}{225}\Bigr)p^2+O(p^3). \]

Substituting S1,acc = S1,good = 7 and S2,acc = 282, S2,good = 138,

\[ D(p)&=1-\frac{68}{15}p+\frac{704}{75}p^2+O(p^3),\\ N(p)&=1-\frac{68}{15}p+\frac{656}{75}p^2+O(p^3). \]

5) Logical fidelity (conditioned on post‑selection)

  • The logical fidelity is
\[ F_{\mathrm{logical}}(p)=\frac{N(p)}{D(p)}. \]

Expanding the ratio to second order,

\[ F_{\mathrm{logical}}(p)=1+\bigl(n_1-d_1\bigr)p+\Bigl(n_2-d_2-d_1(n_1-d_1)\Bigr)p^2+O(p^3). \]

Since n1=d1 (all accepted single faults are benign), the linear term vanishes. The quadratic coefficient is

\[ \]

Therefore

\[ F_{\mathrm{logical}}(p)=1-\frac{16}{25}\,p^2+O(p^3). \]
  • For completeness, the acceptance probability to the same order is
\[ P_{\mathrm{acc}}(p)=D(p)=1-\frac{68}{15}\,p+\frac{704}{75}\,p^2+O(p^3). \]

Remarks and checks

  • The absence of an O(p) term in Flogical(p) is the defining “fault‑tolerant” feature here: every single two‑qubit fault is either detected (rejected by ancilla or code stabilizers) or equivalent to a state stabilizer. The remaining O(p^2) infidelity comes from 144 specific two‑fault patterns that conspire to pass all checks but implement a non‑trivial logical X/Y on A and/or B. The Clifford/Pauli normalizer facts used above justify treating errors this way. (en.wikipedia.org)

Final Answer: To second order in the two‑qubit gate error rate p, the post‑selected logical fidelity of the prepared |00⟩AB state is

\[ F_{\mathrm{logical}}(p)=1-\frac{16}{25}\,p^2+O(p^3), \]

and the acceptance probability is

\[ P_{\mathrm{acc}}(p)=1-\frac{68}{15}\,p+\frac{704}{75}\,p^2+O(p^3). \]
User #9

Populate your final answer into the code template provided below. This step is purely for formatting/display purposes. No additional reasoning or derivation should be performed. Do not import any modules or packages beyond what is provided in the template.

import sympy as sp

p = sp.symbols('p')

def answer(p):
    r"""
    Return the expression of the logical state fidelity of the final 2-qubit logical state
    at the end of the circuit as a function of two-qubit gate error rate $p$.

    Inputs
    ----------
    p: sympy.Symbol, two-qubit gate error rate, $p$

    Outputs
    ----------
    F_logical: sympy.Expr, logical state fidelity of the final 2-qubit logical state
    """

    # ------------------ FILL IN YOUR RESULTS BELOW ------------------
    F_logical = ...  # a SymPy expression of inputs
    # ---------------------------------------------------------------

    return F_logical
Assistant #10
import sympy as sp

p = sp.symbols('p')

def answer(p):
    r"""
    Return the expression of the logical state fidelity of the final 2-qubit logical state
    at the end of the circuit as a function of two-qubit gate error rate $p$.

    Inputs
    ----------
    p: sympy.Symbol, two-qubit gate error rate, $p$

    Outputs
    ----------
    F_logical: sympy.Expr, logical state fidelity of the final 2-qubit logical state
    """

    # ------------------ FILL IN YOUR RESULTS BELOW ------------------
    F_logical = 1 - sp.Rational(16, 25) * p**2  # a SymPy expression of inputs
    # ---------------------------------------------------------------

    return F_logical