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

1) Step-by-Step Derivation

Goal and noise model - We prepare the 4-qubit physical state using the circuit CNOT03 · H0 · CNOT21 · H2 where H gates are ideal and each CNOTij is followed by an independent 2-qubit depolarizing channel that, with probability p, applies one of the 15 non-identity 2-qubit Paulis uniformly (probability p/15 each), and with probability 1−p applies the identity. This is the standard “uniform Pauli” form of an n=2 depolarizing channel (4^2−1=15), used widely in simulators; see, e.g., Qiskit’s depolarizing_error construction and discussion of uniform Pauli channels. (qiskit-org-web-resources.s3.us.cloud-object-storage.appdomain.cloud, en.wikipedia.org)

  • The ideal target state is the encoded logical Bell (GHZ of two logical qubits) state |Φ+⟩AB = (|00⟩AB + |11⟩AB)/√2 inside the [[4,2,2]] code whose stabilizers are XXXX and ZZZZ. (errorcorrectionzoo.org)

Identify the stabilizer of the prepared state - The logical-Bell state is stabilized by the logical operators XAXB and ZAZB. With the given logicals, ZAZB = (ZZII)(ZIZI) = IZZI, XAXB = (XIXI)(XXII) = IXXI. - Together with the code stabilizers XXXX and ZZZZ, a convenient generating set for the stabilizer of the final ideal 4-qubit state is g1 = XXXX, g2 = ZZZZ, g3 = IXXI, g4 = IZZI. Hence the (pure) ideal state |ψ⟩ is the unique +1 eigenstate of the Abelian group Sψ = ⟨g1, g2, g3, g4⟩ with |Sψ| = 16.

Useful fact about stabilizer states - For any stabilizer state |ψ⟩ and any Pauli P, ⟨ψ|P|ψ⟩ = 0 unless P ∈ ±Sψ; if P ∈ ±Sψ, then P|ψ⟩ = ±|ψ⟩, so the density matrix is unchanged by conjugation with P. Consequently, when a classical mixture of Pauli errors is applied, the state fidelity with |ψ⟩ equals the total probability weight of those Pauli errors that lie in ±Sψ. (arxiv.org)

Where the two error channels act and why they commute with later gates - The error after CNOT21 acts only on qubits {2,1}; no later gate touches these qubits, since H0 acts on 0 and CNOT03 acts on {0,3}. The error after CNOT03 acts only on {0,3} and is last in the circuit. Therefore the total error at the end is a tensor product E = P21 ⊗ Q03, with P21 ∈ {two-qubit Paulis on (2,1)} and Q03 ∈ {two-qubit Paulis on (0,3)}, chosen independently with the probabilities specified above.

Classify which Pauli errors stabilize the ideal state - We need all elements of Sψ that factor as operators supported on (1,2) and/or (0,3). Using the generators: • Elements supported only on (1,2): {I, X1X2, Y1Y2, Z1Z2} = {I, g3, g3g4, g4}. • Elements supported only on (0,3): {I, X0X3, Y0Y3, Z0Z3} = {I, g1g3, g1g2g3g4, g2g4}. • The remaining 9 elements of Sψ act nontrivially on both pairs (0,3) and (1,2).

Compute the fidelity as a probability sum Let p be the error rate per two-qubit gate.

  • Case A: No error on either gate (identity on both pairs). Probability: (1−p)^2. This yields E = I ∈ Sψ, so contributes (1−p)^2.

  • Case B: Exactly one gate has a non-identity error. Suppose (2,1) has the error and (0,3) is identity. Then E ∈ Sψ iff P21 ∈ {X1X2, Y1Y2, Z1Z2}, i.e., 3 of the 15 non-identity two-qubit Paulis. Probability contribution: (1−p) × p × (3/15). The same holds if only (0,3) errs, giving an identical contribution. Total for Case B: 2 × (1−p) × p × (3/15).

  • Case C: Both gates have non-identity errors. Then E ∈ Sψ iff P21 ⊗ Q03 equals one of the 9 stabilizers that act nontrivially on both pairs. There are 9 favorable pairs out of 15×15 total. Probability contribution: 9 × (p/15)^2.

Sum all three cases:

\[ \begin{aligned} F(p) &= (1-p)^2 \;+\; 2(1-p)\,p\left(\frac{3}{15}\right) \;+\; 9\left(\frac{p}{15}\right)^2 \\ &= (1-p)^2 \;+\; \frac{2p(1-p)}{5} \;+\; \frac{p^2}{25}. \end{aligned} \]

Simplify:

\[ F(p) = 1 - \frac{8}{5}\,p + \frac{16}{25}\,p^2. \]

Checks - Small p: F(p) ≈ 1 − (8/5)p, meaning a linear coefficient reduced from 2 (two gates) because a 3/15 fraction of single-gate Pauli errors stabilize the target state. - p = 1: F(1) = 1/25 = 9/225, matching the fraction of 2-gate error pairs that land in Sψ (9 of 225).

2) Mathematical Typesetting

All equations are presented above in LaTeX.

3) Conventions and Units

We use the standard Pauli group conventions and the stabilizer formalism; the two-qubit depolarizing channel is the uniform Pauli channel over 15 non-identity two-qubit Paulis. (qiskit-org-web-resources.s3.us.cloud-object-storage.appdomain.cloud)

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

References: - [[4,2,2]] code stabilizers XXXX and ZZZZ; codeword structure. Error Correction Zoo, “[[4,2,2]] Four-qubit code.” (errorcorrectionzoo.org) - Bell state stabilizers are +XX and +ZZ (illustrated in Qiskit StabilizerState docs). (docs.quantum.ibm.com) - Two-qubit depolarizing = uniform Pauli over 4^n−1 non-identity Paulis. Qiskit Aer standard_errors; Wikipedia depolarizing channel background. (qiskit-org-web-resources.s3.us.cloud-object-storage.appdomain.cloud, en.wikipedia.org) - Expectation of Pauli on a stabilizer state is zero unless the Pauli is (±) in the stabilizer group. (arxiv.org)

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

1) Step-by-Step Derivation

Setup and noise model - We run the 4‑qubit circuit (right-to-left) (CNOT03)(H0)(CNOT21)(H2), with ideal single-qubit H’s. Each CNOT is followed by an independent 2‑qubit depolarizing channel: with probability 1−p nothing happens and with probability p one of the 4^2−1=15 non-identity two‑qubit Pauli operators is applied uniformly (p/15 each). This is the standard n‑qubit depolarizing channel. [Cirq documentation spells this out; identical definition is used widely.] (quantumai.google)

  • The code is the [[4,2,2]] code with stabilizer generators S=⟨XXXX, ZZZZ⟩. Its codespace is the simultaneous +1 eigenspace of these two operators. (errorcorrectionzoo.org)

  • The target logical state is the logical Bell state |Φ+〉AB=(|00〉AB+|11〉AB)/√2, which (at the logical level) is stabilized by XAXB and ZAZB; equivalently the physical state prepared by the circuit is a 4‑qubit stabilizer state whose stabilizer contains {XXXX, ZZZZ} together with logical-Bell stabilizers mapped into the code. For the 2‑qubit Bell state itself, the (phase-free) stabilizer set is {II, XX, ZZ} (with −YY also in the full Pauli stabilizer group), so XX and ZZ generate it. (quantumcomputing.stackexchange.com)

Where the errors land - No gate after CNOT21 touches qubits 2 or 1, and CNOT03 is last and only touches qubits 0 and 3. Hence the total Pauli error at the end factors as E = P21 ⊗ Q03, with P21 acting on qubits {2,1} and Q03 on {0,3}, independently drawn per the depolarizing model above.

Post-selection rule (detect-then-keep) - “Post-select on all detectable errors” means we discard any run whose final stabilizer measurements report a nontrivial syndrome. For Pauli errors, an error is undetected exactly when it commutes with every stabilizer generator; i.e., E lies in the centralizer/normalizer N(S) of S in the 4‑qubit Pauli group. If E∉N(S), at least one generator anticommutes with E and yields a −1 outcome, so we reject the run. (en.wikipedia.org)

Commutation constraints in parity form - Represent a Pauli string by binary “X- and Z-parity” indicators: for each qubit j, let xj=1 if the local Pauli is X or Y and zj=1 if it is Z or Y (else 0). A Pauli E commutes with XXXX iff the total parity of {Z,Y} across all four qubits is even, i.e., ∑j zj≡0 (mod 2). It commutes with ZZZZ iff ∑j xj≡0 (mod 2). This is the standard symplectic-commutation rule in the stabilizer formalism. (en.wikipedia.org)

Classify two-qubit Paulis on a given pair - For any fixed pair, say (2,1), group the 16 Paulis (including II) by the two parities (a,b)≡(∑xj mod 2, ∑zj mod 2) on that pair: • Class 00: {II, XX, YY, ZZ} (size 4; among these, the 3 non-identity are XX, YY, ZZ) • Class 10: {XI, IX, YZ, ZY} (size 4) • Class 01: {ZI, IZ, XY, YX} (size 4) • Class 11: {XZ, ZX, IY, YI} (size 4)

Acceptance (probability that the run is kept) - No error: accepted with probability (1−p)^2 (E=I∈N(S)). - Exactly one gate errs (say on (2,1)): E lies in N(S) iff that pair error has even x-parity and even z-parity, i.e., it is in class 00 and non-identity ⇒ exactly 3 acceptable Paulis out of 15. The same holds if only (0,3) errs. Contribution: 2(1−p)p(3/15). - Both gates err: E=P21⊗Q03 commutes with XXXX and ZZZZ iff the pairwise parities match between the two pairs (a,b)21=(a,b)03 (both constraints). Counting acceptable pairs among 15×15=225 possibilities: class 00: 3×3=9 class 10: 4×4=16 class 01: 4×4=16 class 11: 4×4=16 Total 57. Contribution: p^2·(57/225)=p^2·(19/75).

Therefore the post-selection acceptance probability is

\[ P_{\rm acc}(p) =(1-p)^2+2(1-p)p\frac{3}{15}+p^2\frac{57}{225} =1-\frac{8}{5}p+\frac{64}{75}p^2. \]

“Good” (logically correct) undetected errors - Among accepted runs (E∈N(S)), the logical two-qubit state equals the intended |Φ+〉AB iff E acts on the codespace as an element of the logical-Bell stabilizer subgroup generated by XAXB and ZAZB (global phases ignored), i.e., E is in the state’s stabilizer. For our circuit this occurs exactly when: • No error, or • A single-pair error is one of {XX,YY,ZZ} on that pair, or • Both pairs have errors from {XX,YY,ZZ} on each pair (9 combinations). This is precisely the same counting that gave the physical 4‑qubit state fidelity in Subproblem 1:

\[ P_{\rm good}(p)=(1-p)^2+2(1-p)p\frac{3}{15}+9\left(\frac{p}{15}\right)^2 =1-\frac{8}{5}p+\frac{16}{25}p^2, \]

since {XX,YY,ZZ} stabilize the Bell state up to phase. (quantumcomputing.stackexchange.com)

Logical fidelity conditioned on passing detection - The desired quantity is the conditional fidelity of the logical 2‑qubit state given acceptance (syndrome +1), i.e.,

\[ F_{\rm logical}(p)=\frac{P_{\rm good}(p)}{P_{\rm acc}(p)} =\frac{1-\frac{8}{5}p+\frac{16}{25}p^2}{1-\frac{8}{5}p+\frac{64}{75}p^2} =\frac{75-120p+48p^2}{75-120p+64p^2}. \]

Sanity checks - Small‑p expansion: using (1+αp+βp^2)/(1+γp+δp^2)=1+(α−γ)p+[β−δ−γ(α−γ)]p^2+… and noting the linear terms cancel, we get

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

showing first‑order errors are removed by post‑selection, as expected for a distance‑2 detection code. (en.wikipedia.org) - At p=1: Flogical(1)=(1/25)/(19/75)=3/19≈0.1579.

2) Mathematical Typesetting

All key steps above are written in LaTeX.

3) Conventions and Units

4) Final Answer: Flogical(p) = (75 − 120 p + 48 p^2) / (75 − 120 p + 64 p^2) = [1 − (8/5)p + (16/25)p^2] / [1 − (8/5)p + (64/75)p^2].

Equivalently, for small p: Flogical(p) = 1 − (16/75)p^2 + O(p^3).

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)
# We'll enumerate all Pauli error combinations for the 5 two-qubit gates in the circuit
# Gates (from earliest to latest):
# 1) CNOT_{12} (control 1, target 2)
# 2) CNOT_{10} (control 1, target 0)
# 3) CNOT_{23} (control 2, target 3)
# 4) CNOT_{34} (control 3, target 4)
# 5) CNOT_{04} (control 0, target 4)
# After each gate, a 2-qubit depolarizing error may occur on that gate's qubits.
# We will propagate each inserted two-qubit Pauli forward through the remaining CNOTs,
# accumulate the total Pauli on 5 qubits (0..4), and then check acceptance conditions.

from itertools import product

# Pauli multiplication table ignoring global phase: maps (P,Q) -> (R, phase)
# We'll carry the phase but ultimately ignore for acceptance checks.
paulis = ['I','X','Y','Z']
# multiplication table with phase factors (1, -1, 1j, -1j)
mult = {
    ('I','I'):('I',1), ('I','X'):('X',1), ('I','Y'):('Y',1), ('I','Z'):('Z',1),
    ('X','I'):('X',1), ('X','X'):('I',1), ('X','Y'):('Z',1j), ('X','Z'):('Y',-1j),
    ('Y','I'):('Y',1), ('Y','X'):('Z',-1j), ('Y','Y'):('I',1), ('Y','Z'):('X',1j),
    ('Z','I'):('Z',1), ('Z','X'):('Y',1j), ('Z','Y'):('X',-1j), ('Z','Z'):('I',1),
}

# Conjugation of single-qubit Pauli by CNOT(c,t)
# We implement conjugation on a full 5-qubit Pauli string P (list of length 5)

def cnot_conj(P, c, t):
    P = list(P)
    # Copy to avoid in-place mis-order
    Pc, Pt = P[c], P[t]
    # Apply the standard conjugation rules
    # X on control -> X on control and X on target
    # Z on target -> Z on control and Z on target
    # Y handled by compositions
    # We'll update by multiplying appropriate factors
    # Initialize to identity and compose corrections
    # Do it via explicit cases on (Pc, Pt)

    # Map using operator identities:
    # Conjugation acts linearly on the Pauli group; we can implement via table mapping of basis elements
    # We'll just apply rules per component:

    # Start with identity on both positions, then multiply mapped contributions
    # But easier: use known mapping on generators X_c, Z_c, X_t, Z_t and reconstruct Y via X*Z up to phase

    # We'll decompose Pc and Pt into X/Z bits to apply mapping. Simpler: handle 16 cases directly using rules:
    def map_single(Pc, Pt):
        # returns new (Pc', Pt') up to a phase. We'll also return the phase.
        phase = 1
        # Start from identity; later multiply in effect of Pc and Pt one by one
        # Conjugation is homomorphism: U (A B) U† = (U A U†)(U B U†)
        # So treat Pc at c position and Pt at t position separately, then multiply results on those two qubits
        # We'll build arrays for 5-qubit string but only care about c and t positions.
        # First: effect of Pc at control
        P_c_map = {'I':('I',1), 'X':('X',1), 'Y':('Y',1), 'Z':('Z',1)}
        P_t_map = {'I':('I',1), 'X':('X',1), 'Y':('Y',1), 'Z':('Z',1)}
        # Apply known rules by replacing c and t operators:
        # For control:
        if Pc == 'I':
            Pc1, phase1 = 'I', 1
            Pt1, phase1b = 'I', 1
        elif Pc == 'X':
            # X_c -> X_c X_t
            Pc1, Pt1, phase1, phase1b = 'X', 'X', 1, 1
        elif Pc == 'Z':
            # Z_c -> Z_c
            Pc1, Pt1, phase1, phase1b = 'Z', 'I', 1, 1
        elif Pc == 'Y':
            # Y_c -> Y_c X_t
            Pc1, Pt1, phase1, phase1b = 'Y', 'X', 1, 1
        # For target:
        if Pt == 'I':
            Pc2, phase2 = 'I', 1
            Pt2, phase2b = 'I', 1
        elif Pt == 'X':
            # X_t -> X_t
            Pc2, Pt2, phase2, phase2b = 'I', 'X', 1, 1
        elif Pt == 'Z':
            # Z_t -> Z_c Z_t
            Pc2, Pt2, phase2, phase2b = 'Z', 'Z', 1, 1
        elif Pt == 'Y':
            # Y_t -> Z_c Y_t
            Pc2, Pt2, phase2, phase2b = 'Z', 'Y', 1, 1
        # Now multiply contributions on c and t qubits: (Pc1 on c) * (Pc2 on c) and (Pt1 on t) * (Pt2 on t)
        Pc_new, phc = mult[(Pc1, Pc2)]
        Pt_new, pht = mult[(Pt1, Pt2)]
        phase = phase1 * phase1b * phase2 * phase2b * phc * pht
        return Pc_new, Pt_new, phase


    Pc_new, Pt_new, ph = map_single(Pc, Pt)
    P[c], P[t] = Pc_new, Pt_new
    # Other positions unchanged
    return ''.join(P), ph

# Multiply two 5-qubit Pauli strings (ignoring global phase aside from detection). Return product string and phase.
def pauli_mult(P, Q):
    phase = 1
    out = []
    for a,b in zip(P,Q):
        r, ph = mult[(a,b)]
        out.append(r)
        phase *= ph
    return ''.join(out), phase

# Generate all 2-qubit non-identity Pauli errors on a given pair (i,j)
# Represent errors as 5-qubit strings with I elsewhere

def two_qubit_paulis(i,j):
    out = []
    for a in paulis:
        for b in paulis:
            if a=='I' and b=='I':
                continue
            s = ['I']*5
            s[i] = a
            s[j] = b
            out.append(''.join(s))
    return out

# Precompute error sets for each gate pair in order of insertion (right-to-left mapping):
# But note: we listed them earliest->latest above; we'll use that order for later conjugations
pairs = [(1,2),(1,0),(2,3),(3,4),(0,4)]
errs_per_gate = [two_qubit_paulis(i,j) for (i,j) in pairs]

# Precompute conjugation of any 5-qubit Pauli by each of the subsequent CNOTs
# For speed, we can apply cnot_conj sequentially as needed.

# We need to compute, for a given set of per-gate choices (identity or a specific 2q Pauli), the final total Pauli just before measurement.
# We'll implement enumeration over all combinations but group by k (number of non-identity gates).

from collections import defaultdict

N_acc = [0]*6
N_good = [0]*6
N_total_by_k = [0]*6

# Build the target state's stabilizer group on data qubits (0..3)
# Generators: XXXX, ZZZZ, ZZII, ZIZI

def data_pauli_str(s4):
    # s4 is 4-char for data; return 5-char with ancilla I
    return s4 + 'I'

def make_full5_from_data(s4):
    s = list('I'*5)
    for q,ch in enumerate(s4):
        s[q] = ch
    return ''.join(s)

# Helper to build generators
G_data = []
G_data.append('XXXX')
G_data.append('ZZZZ')
G_data.append('ZZII')
G_data.append('ZIZI')

# Build full 5-qubit versions (with I on ancilla)
G5 = [make_full5_from_data(g) for g in G_data]

# Build the 4-qubit stabilizer group S_target (set of 4-char strings) ignoring phases
S_target = set()
# generate 2^4 combinations
for m0 in [0,1]:
    for m1 in [0,1]:
        for m2 in [0,1]:
            for m3 in [0,1]:
                s = 'IIII'
                if m0:
                    s, _ = pauli_mult(s+'I', G5[0]+'I')  # We'll just use 5-qubit mult and slice
                    s = s[:4]
                if m1:
                    s5, _ = pauli_mult(s+'I', G5[1])
                    s = s5[:4]
                if m2:
                    s5, _ = pauli_mult(s+'I', G5[2])
                    s = s5[:4]
                if m3:
                    s5, _ = pauli_mult(s+'I', G5[3])
                    s = s5[:4]
                S_target.add(s)

# Alternatively, rebuild more cleanly using 4-qubit multiplication
# We'll create a 4-qubit multiplication that ignores phase.

def pauli_mult4(P,Q):
    phase = 1
    out = []
    for a,b in zip(P,Q):
        r, ph = mult[(a,b)]
        out.append(r)
        phase *= ph
    return ''.join(out), phase

# Rebuild S_target cleanly
S_target = set(['IIII'])
for g in ['XXXX','ZZZZ','ZZII','ZIZI']:
    # expand by multiplying existing elements by g
    S_target = S_target.union({pauli_mult4(s,g)[0] for s in list(S_target)})
# Actually that only adds one generator; we need to generate the whole group by combining; do iterative closure
changed = True
while changed:
    changed = False
    newS = set(S_target)
    for a in S_target:
        for b in ['XXXX','ZZZZ','ZZII','ZIZI']:
            ab, _ = pauli_mult4(a,b)
            if ab not in newS:
                newS.add(ab)
                changed = True
    S_target = newS

# Build the normalizer condition with respect to S_code={XXXX, ZZZZ}: commute iff even X/Y count and even Z/Y count on data

def commutes_with_stabilizers(data4):
    # even parity of X/Y across all four: sum x_j mod 2 = 0
    # even parity of Z/Y across all four: sum z_j mod 2 = 0
    x_par = 0
    z_par = 0
    for ch in data4:
        if ch in ('X','Y'):
            x_par ^= 1
        if ch in ('Z','Y'):
            z_par ^= 1
    return (x_par==0) and (z_par==0)

# Ancilla acceptance: ancilla char must be not X or Y (i.e., I or Z)

def ancilla_accept(anc_ch):
    return anc_ch in ('I','Z')

# Now enumerate all combinations. For each gate, include 'I' option besides the 15 two-qubit errors.
# We'll prepare a list of per-gate options as [ ['I'], [list of 15 two-qubit strings] ]

errs_with_I = []
for gate_errs in errs_per_gate:
    errs_with_I.append(['I'] + gate_errs)

# Precompute subsequent conjugation sequences for performance: For an error inserted after gate g (0-based),
# it must be conjugated by gates g+1..4 (the later ones). We'll implement cnot_conj accordingly.

# define CNOT list for conjugations in order (later gates)
cnot_list = [(1,2),(1,0),(2,3),(3,4),(0,4)]

# Conjugate a 5-qubit Pauli P by the sequence of later CNOTs starting after index g

def conj_after_gate(P, g):
    for idx in range(g+1, 5):
        c,t = cnot_list[idx]
        P, _ = cnot_conj(P, c, t)
    return P

# For performance, precompute the image of each possible non-identity error for each gate under later conjugations
pre_images = []
for g, gate_errs in enumerate(errs_per_gate):
    imap = {}
    for s in gate_errs:
        imap[s] = conj_after_gate(s, g)
    pre_images.append(imap)

# Function to multiply 5-qubit Paulis (ignore phase)

def mult5(P,Q):
    return pauli_mult(P,Q)[0]

# Iterate all combinations; count by k (number of non-identity selections)

from math import comb

N_acc = [0]*6
N_good = [0]*6
N_total_by_k = [0]*6

# We'll iterate more efficiently: for each gate choose index in 0..15 where 0 means identity, 1..15 picks from gate_errs

for idxs in product(*[range(16) for _ in range(5)]):
    k = sum(1 for i in idxs if i!=0)
    N_total_by_k[k] += 1
    # Build total Pauli by multiplying the propagated errors from each non-identity gate
    total = 'I'*5
    for g,i in enumerate(idxs):
        if i==0:
            continue
        # select the (i-1)th error from errs_per_gate[g]
        s = errs_per_gate[g][i-1]
        # propagate to end
        s_prop = pre_images[g][s]
        # multiply into total
        total = mult5(total, s_prop)
    # Acceptance conditions
    data4 = total[:4]
    anc = total[4]
    if ancilla_accept(anc) and commutes_with_stabilizers(data4):
        N_acc[k] += 1
        # Good if data4 is in S_target
        if data4 in S_target:
            N_good[k] += 1

# Report counts
print('N_total_by_k:', N_total_by_k)
print('N_acc:', N_acc)
print('N_good:', N_good)

# Sanity: N_total_by_k should be [1, 5*15, comb(5,2)*15**2, comb(5,3)*15**3, comb(5,4)*15**4, 15**5]
expected = [1, 5*15, comb(5,2)*15**2, comb(5,3)*15**3, comb(5,4)*15**4, 15**5]
print('Expected totals by k:', expected)
Tool #7
N_total_by_k: [1, 75, 2250, 33750, 253125, 759375]
N_acc: [1, 7, 282, 4222, 31637, 94923]
N_good: [1, 7, 138, 1198, 7397, 24027]
Expected totals by k: [1, 75, 2250, 33750, 253125, 759375]
Assistant #8
Tool Call (code to execute)
from fractions import Fraction
from math import comb

N_acc = [1, 7, 282, 4222, 31637, 94923]
N_good = [1, 7, 138, 1198, 7397, 24027]

# Build polynomials for P_acc and P_good: coefficients for p^k (1-p)^(5-k)/15^k
# We'll expand (1-p)^(5-k) = sum_{j=0}^{5-k} comb(5-k, j) (-p)^j
# So total power is p^{k+j} with coefficient N[k] * comb(5-k, j) * (-1)^j / 15^k

# We'll compute coefficients up to degree 5 for numerator polynomials directly as Fractions.

def expand_poly(N):
    coeff = [Fraction(0,1) for _ in range(6)]
    for k in range(6):
        for j in range(6-k):
            power = k + j
            c = Fraction(N[k] * comb(5-k, j) * ((-1)**j), 15**k)
            coeff[power] += c
    return coeff

coeff_acc = expand_poly(N_acc)
coeff_good = expand_poly(N_good)

print('P_acc coefficients (for p^0..p^5):')
print([str(c) for c in coeff_acc])
print('P_good coefficients (for p^0..p^5):')
print([str(c) for c in coeff_good])

# For readability, present as decimals too
print('P_acc coeff decimals:', [float(c) for c in coeff_acc])
print('P_good coeff decimals:', [float(c) for c in coeff_good])

# Small-p series for F = P_good / P_acc up to p^3 (using series division)
import math

a = [float(c) for c in coeff_acc]
b = [float(c) for c in coeff_good]

# Series division: F = (b0 + b1 p + b2 p^2 + ... ) / (a0 + a1 p + a2 p^2 + ...)
# We'll compute up to order p^3

b0,b1,b2,b3 = b[:4]
a0,a1,a2,a3 = a[:4]

# Compute coefficients f0..f3 s.t. (a0 + a1 p + a2 p^2 + a3 p^3) (f0 + f1 p + f2 p^2 + f3 p^3) = (b0 + b1 p + b2 p^2 + b3 p^3) up to p^3

f0 = b0/a0
f1 = (b1 - a1*f0)/a0
f2 = (b2 - a1*f1 - a2*f0)/a0
f3 = (b3 - a1*f2 - a2*f1 - a3*f0)/a0

print('Series F(p) = f0 + f1 p + f2 p^2 + f3 p^3 + ...')
print(f0, f1, f2, f3)

# Also produce exact rational polynomials for P_acc and P_good as common denominator 15^5
from math import gcd
from functools import reduce

# Convert to common denom 15^5 by multiplying
D = 15**5
num_acc = [int(c*D) for c in coeff_acc]
num_good = [int(c*D) for c in coeff_good]

print('P_acc numerator with denom 15^5:', num_acc)
print('P_good numerator with denom 15^5:', num_good)

# Optionally simplify by gcd

def poly_gcd_ints(coefs):
    g = 0
    for v in coefs:
        g = gcd(g, abs(v))
    return g

g_acc = poly_gcd_ints(num_acc)
g_good = poly_gcd_ints(num_good)
print('gcds:', g_acc, g_good)

# We can present P_acc(p) = (A0 + A1 p + ... + A5 p^5) / 15^5, same for P_good
# But better to present as exact rational coefficients simplified fractions.
Tool #9
P_acc coefficients (for p^0..p^5):
['1', '-68/15', '704/75', '-32768/3375', '253952/50625', '-262144/253125']
P_good coefficients (for p^0..p^5):
['1', '-68/15', '656/75', '-29312/3375', '223232/50625', '-229376/253125']
P_acc coeff decimals: [1.0, -4.533333333333333, 9.386666666666667, -9.709037037037037, 5.016335802469136, -1.0356306172839507]
P_good coeff decimals: [1.0, -4.533333333333333, 8.746666666666666, -8.685037037037038, 4.409520987654321, -0.9061767901234568]
Series F(p) = f0 + f1 p + f2 p^2 + f3 p^3 + ...

1.0 0.0 -0.6400000000000006 -1.8773333333333362
P_acc numerator with denom 15^5: [759375, -3442500, 7128000, -7372800, 3809280, -786432]
P_good numerator with denom 15^5: [759375, -3442500, 6642000, -6595200, 3348480, -688128]
gcds: 3 3
Assistant #10
Tool Call (code to execute)
from fractions import Fraction

a = [Fraction(s) for s in ['1','-68/15','704/75','-32768/3375','253952/50625','-262144/253125']]
b = [Fraction(s) for s in ['1','-68/15','656/75','-29312/3375','223232/50625','-229376/253125']]

b0,b1,b2,b3 = b[:4]
a0,a1,a2,a3 = a[:4]

f0 = b0/a0
f1 = (b1 - a1*f0)/a0
f2 = (b2 - a1*f1 - a2*f0)/a0
f3 = (b3 - a1*f2 - a2*f1 - a3*f0)/a0

print('Exact series coefficients f0..f3:', f0, f1, f2, f3)

# Let's also present F(p) as a rational function with integer-coefficient polynomials by clearing denominators using 15^5
D = 15**5
num_acc = [int(a[i]*D) for i in range(6)]
num_good = [int(b[i]*D) for i in range(6)]
print('Num_acc with denom 15^5:', num_acc)
print('Num_good with denom 15^5:', num_good)
Tool #11
Exact series coefficients f0..f3: 1 0 -16/25 -704/375
Num_acc with denom 15^5: [759375, -3442500, 7128000, -7372800, 3809280, -786432]
Num_good with denom 15^5: [759375, -3442500, 6642000, -6595200, 3348480, -688128]
Assistant #12
Tool Call (code to execute)
from fractions import Fraction
P_acc = [Fraction(1,1), Fraction(-68,15), Fraction(704,75), Fraction(-32768,3375), Fraction(253952,50625), Fraction(-262144,253125)]
P_good = [Fraction(1,1), Fraction(-68,15), Fraction(656,75), Fraction(-29312,3375), Fraction(223232,50625), Fraction(-229376,253125)]

from functools import reduce

def eval_poly(coeffs, p):
    s = Fraction(0,1)
    powp = Fraction(1,1)
    for i, c in enumerate(coeffs):
        s += c * (Fraction(p,1)**i)
    return s

print('P_acc(1) =', eval_poly(P_acc, 1), float(eval_poly(P_acc,1)))
print('P_good(1) =', eval_poly(P_good, 1), float(eval_poly(P_good,1)))
print('F(1) =', float(eval_poly(P_good,1)/eval_poly(P_acc,1)))
Tool #13
P_acc(1) = 10547/84375 0.1250014814814815
P_good(1) = 8009/253125 0.03164049382716049
F(1) = 0.25312095066527607
Assistant #14

1) Step-by-Step Derivation

Goal, circuit, and noise model - We prepare the logical two‑qubit state |00〉AB of the [[4,2,2]] code using, right‑to‑left, the circuit H1 → CNOT12 → CNOT10 → CNOT23 → CNOT34 → CNOT04 → measure Z on ancilla 4. Only the two‑qubit CNOT gates are faulty; each is followed by an independent two‑qubit depolarizing channel that applies one of the 15 non‑identity two‑qubit Paulis with probability p/15 and the identity with probability 1−p. This is the standard n‑qubit depolarizing channel, uniform over the 4^n−1 non‑identity Paulis. (quantumai.google, en.wikipedia.org, qiskit.github.io)

  • The [[4,2,2]] code has stabilizers S=⟨XXXX, ZZZZ⟩. A convenient logical basis is |00̄〉=(|0000〉+|1111〉)/√2, |01̄〉=(|0011〉+|1100〉)/√2, |10̄〉=(|0101〉+|1010〉)/√2, |11̄〉=(|0110〉+|1001〉)/√2. Thus the target is |00̄〉, stabilized by {XXXX, ZZZZ, ZZII, ZIZI}. (errorcorrectionzoo.org, ar5iv.labs.arxiv.org)

  • The last two CNOTs map the Z‑parity of qubits 0 and 3 onto ancilla 4 (control→target), so ideally the ancilla reads |0〉 because in |00̄〉 we have Z0Z3=+1 (bits 0 and 3 are equal in both |0000〉 and |1111〉). More generally, two control→ancilla CNOTs perform a ZZ parity measurement on the controls. (en.wikipedia.org)

Pauli‑frame method (move all errors to the end) - Insert, after each CNOT, a two‑qubit Pauli error E(g) supported on that gate’s qubits: E(12), E(10), E(23), E(34), E(04). Push each forward to the end by conjugating through the subsequent CNOTs using the standard rules (U P U†): Xc → XcXt, Zt → ZcZt, Xt → Xt, Zc → Zc, and similarly Y via Y=iXZ. (rainij.github.io, en.wikipedia.org) - The total error just before measuring qubit 4 is the product Efinal = E′(12) E′(10) E′(23) E′(34) E′(04), where each E′(⋅) is the propagated image.

Acceptance (post‑selection) conditions - Ancilla pass: Z‑basis measurement outcome flips iff the pre‑measurement Pauli on qubit 4 has an X or Y component; I or Z leaves the outcome unchanged. This follows because for any state a|0〉+b|1〉, measuring Z after an X (or Y) swaps the probabilities of 0 and 1, i.e., flips the classical result; Z only adds phase. Therefore accept the run iff the ancilla factor of Efinal is I or Z. - Code‑syndrome pass: a Pauli on data qubits 0–3 commutes with XXXX iff the total number of Z/Y on the four data qubits is even, and commutes with ZZZZ iff the total number of X/Y is even (symplectic commutation). Equivalently, accept iff both parities are even so that Efinal lies in the normalizer of S. (en.wikipedia.org)

Logical correctness among accepted runs - Let Starget = ⟨XXXX, ZZZZ, ZZII, ZIZI⟩ be the 16‑element stabilizer of |00̄〉 on data qubits. If the data part of Efinal lies in Starget (phase ignored), the physical state equals the target; if it lies in the normalizer but not in Starget, the logical two‑qubit state is wrong though undetected by the code syndrome. (errorcorrectionzoo.org)

Exact counting by exhaustive Pauli enumeration (fault‑path analysis) - Each of the five CNOTs is followed by either I (prob. 1−p) or one of 15 Paulis (prob. p/15). We enumerated all (1+15)^5=1,048,576 error patterns. For each pattern we: 1) propagated the Pauli to the end using the CNOT conjugation rules, 2) tested ancilla pass (qubit 4 ∈ {I,Z}), 3) tested code pass (even X/Y and even Z/Y on data), and 4) tested “good” (data Pauli ∈ Starget). - Grouping by k, the number of faulty two‑qubit gates (k=0…5), yields the counts: Nacc(k) = [1, 7, 282, 4222, 31637, 94923], Ngood(k) = [1, 7, 138, 1198, 7397, 24027]. These are exact integers from exhaustive enumeration (numerical code available upon request).

From counts to probabilities - Let Pacc(p) = Σk Nacc(k) (p^k (1−p)^{5−k} / 15^k), Pgood(p) = Σk Ngood(k) (p^k (1−p)^{5−k} / 15^k). Expanding, $ \begin{aligned} P_{\rm acc}(p) &= 1 - \tfrac{68}{15}p + \tfrac{704}{75}p^2 - \tfrac{32768}{3375}p^3 + \tfrac{253952}{50625}p^4 - \tfrac{262144}{253125}p^5,\ P_{\rm good}(p) &= 1 - \tfrac{68}{15}p + \tfrac{656}{75}p^2 - \tfrac{29312}{3375}p^3 + \tfrac{223232}{50625}p^4 - \tfrac{229376}{253125}p^5. \end{aligned} $

Logical state fidelity conditioned on post‑selection - The desired logical fidelity is the conditional probability that the accepted run is logically correct: $ F_{\rm logical}(p)=\frac{P_{\rm good}(p)}{P_{\rm acc}(p)}. $ In closed form, $ F_{\rm logical}(p)= \frac{1 - \frac{68}{15}p + \frac{656}{75}p^2 - \frac{29312}{3375}p^3 + \frac{223232}{50625}p^4 - \frac{229376}{253125}p^5} {1 - \frac{68}{15}p + \frac{704}{75}p^2 - \frac{32768}{3375}p^3 + \frac{253952}{50625}p^4 - \frac{262144}{253125}p^5}. $

Series check and sanity tests - Small‑p expansion (series division): $ F_{\rm logical}(p)=1-\frac{16}{25}\,p^2 - \frac{704}{375}\,p^3 + O(p^4), $ showing first‑order faults are removed by post‑selection (as expected for a distance‑2 detection code), while second‑order faults dominate. (en.wikipedia.org) - At p=0: Flogical=1. At p=1: Flogical ≈ 0.2531. The linear term vanishes, consistent with “single‑fault‑tolerant” state preparation with verification. The acceptance probability itself is Pacc(p)=1−(68/15)p+O(p^2), reflecting that most single‑gate faults are rejected by either the ancilla parity check or the code stabilizers.

Why the ancilla measurement criterion above is correct - The two control→ancilla CNOTs implement a ZZ parity measurement onto qubit 4 prepared in |0〉; measuring Z on qubit 4 returns the parity bit. A pre‑measurement X (or Y=iXZ) on the measured qubit interchanges |0〉 and |1〉 probabilities, flipping the classical result, whereas Z changes only phase and leaves the distribution invariant. Hence “accept ⇔ ancilla Pauli ∈ {I,Z}”. (en.wikipedia.org)

References used - Two‑qubit depolarizing (uniform Pauli) channel. (quantumai.google, en.wikipedia.org, qiskit.github.io) - [[4,2,2]] code, stabilizers, and codewords; |00̄〉=(|0000〉+|1111〉)/√2. (errorcorrectionzoo.org, ar5iv.labs.arxiv.org) - Conjugation (propagation) of Pauli errors through CNOT. (rainij.github.io, en.wikipedia.org) - Stabilizer formalism and symplectic (parity) commutation test for acceptance. (en.wikipedia.org) - Parity‑measurement with ancilla via cascaded CNOTs. (en.wikipedia.org)

2) Mathematical Typesetting

All equations above are given in LaTeX.

3) Conventions and Units

  • Phase factors of Paulis are irrelevant for acceptance and fidelity; we work in the phase‑free Pauli group.
  • Qubit order: data (0,1,2,3), ancilla (4). CNOTij means control i, target j.

4) Final Answer: Flogical(p) = [1 − (68/15)p + (656/75)p^2 − (29312/3375)p^3 + (223232/50625)p^4 − (229376/253125)p^5] / [1 − (68/15)p + (704/75)p^2 − (32768/3375)p^3 + (253952/50625)p^4 − (262144/253125)p^5].

Equivalently, for small p, Flogical(p) = 1 − (16/25)p^2 − (704/375)p^3 + O(p^4).

User #15

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 #16
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 ------------------
    num = (
        1
        - sp.Rational(68, 15)*p
        + sp.Rational(656, 75)*p**2
        - sp.Rational(29312, 3375)*p**3
        + sp.Rational(223232, 50625)*p**4
        - sp.Rational(229376, 253125)*p**5
    )
    den = (
        1
        - sp.Rational(68, 15)*p
        + sp.Rational(704, 75)*p**2
        - sp.Rational(32768, 3375)*p**3
        + sp.Rational(253952, 50625)*p**4
        - sp.Rational(262144, 253125)*p**5
    )
    F_logical = num / den  # a SymPy expression of inputs
    # ---------------------------------------------------------------

    return F_logical