Checkpoint-2

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.

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\).

Checkpoints

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
Tool Call (code to execute)
import numpy as np

# Pauli matrices
I = np.eye(2)
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)

# Tensor product utility
from functools import reduce

def kron(*ops):
    return reduce(np.kron, ops)

# 4-qubit basis: qubits ordered (0,1,2,3)

# Build CNOT_ij unitary on 4 qubits

def CNOT_ij(i,j):
    # Build projector form: |0><0|_i ⊗ I + |1><1|_i ⊗ X_j
    P0 = np.array([[1,0],[0,0]], dtype=complex)
    P1 = np.array([[0,0],[0,1]], dtype=complex)
    ops0 = [I,I,I,I]
    ops1 = [I,I,I,I]
    ops0[i] = P0
    ops1[i] = P1
    # X on j for second term
    ops1[j] = X
    return kron(*ops0) + kron(*ops1)

# Hadamard on qubit q (others identity)

def H_q(q):
    ops = [I,I,I,I]
    ops[q] = H
    return kron(*ops)

# Two-qubit Pauli labels and matrices
Psingle = [I, X, Y, Z]
Pnames = ['I','X','Y','Z']

# Build two-qubit Pauli on a specified pair (a,b) with order qubit index 0..3

def two_qubit_pauli_on_pair(a,b, pa, pb):
    ops = [I,I,I,I]
    ops[a] = Psingle[pa]
    ops[b] = Psingle[pb]
    return kron(*ops)

# Circuit unitaries (ideal): U = CNOT_03 * H0 * CNOT_21 * H2
U = CNOT_ij(0,3) @ H_q(0) @ CNOT_ij(2,1) @ H_q(2)

# Initial |0000>
zero = np.array([[1],[0]], dtype=complex)
psi0 = kron(zero, zero, zero, zero)
psi_ideal = U @ psi0
rho_ideal = psi_ideal @ psi_ideal.conj().T

# Build the noisy rho(p) symbolically as sum over errors with weights
# But we'll just compute the coefficient of fidelity as a function of p by summing contributions

# Enumerate two-qubit paulis on pair (2,1) and (0,3)
non_id_pairs = []
for a in range(4):
    for b in range(4):
        name = Pnames[a]+Pnames[b]
        non_id_pairs.append((a,b,name))

# Build the list of 16 two-qubit paulies and classify which are identity
pairs = non_id_pairs

# Let's compute the probability weight that maps to fidelity 1: we check for each pair of errors whether
# E03 * U * E21 * ... acting on |0000> equals psi_ideal up to global phase. We can test overlap squared ~1.

# Build E for pair (2,1) and (0,3)

import math

def fidelity_weight():
    # We'll compute count of (pauli on 03, on 21) that leave the state invariant up to phase.
    survivors = []
    for a03 in range(4):
        for b03 in range(4):
            E03 = two_qubit_pauli_on_pair(0,3, a03, b03)
            for a21 in range(4):
                for b21 in range(4):
                    E21 = two_qubit_pauli_on_pair(2,1, a21, b21)
                    # Build final state with this error model: errors applied after CNOTs
                    # That is: first H2, then CNOT21, then error E21, then H0, then CNOT03, then error E03
                    psi = E03 @ CNOT_ij(0,3) @ H_q(0) @ E21 @ CNOT_ij(2,1) @ H_q(2) @ psi0
                    # Overlap magnitude
                    overlap = (psi_ideal.conj().T @ psi)[0,0]
                    if np.allclose(abs(overlap), 1.0, atol=1e-12):
                        survivors.append(((a03,b03),(a21,b21)))
    return survivors

survivors = fidelity_weight()
len_survivors, survivors[:10]
Tool #3
Traceback (most recent call last):
  File "<stdin>", line 99, in <module>
NameError: name 'len_survivors' is not defined. Did you mean: 'survivors'?
Assistant #4
len(survivors), survivors[:20]
Tool #5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'survivors' is not defined
Assistant #6
# Re-run the computation quickly
import numpy as np
I = np.eye(2); X = np.array([[0,1],[1,0]], complex)
Y = np.array([[0,-1j],[1j,0]], complex)
Z = np.array([[1,0],[0,-1]], complex)
H = (1/np.sqrt(2))*np.array([[1,1],[1,-1]], complex)
from functools import reduce

def kron(*ops):
    return reduce(np.kron, ops)

def CNOT_ij(i,j):
    P0 = np.array([[1,0],[0,0]], complex)
    P1 = np.array([[0,0],[0,1]], complex)
    ops0 = [I,I,I,I]
    ops1 = [I,I,I,I]
    ops0[i] = P0
    ops1[i] = P1
    ops1[j] = X
    return kron(*ops0) + kron(*ops1)

def H_q(q):
    ops = [I,I,I,I]
    ops[q] = H
    return kron(*ops)

Psingle = [I,X,Y,Z]

U = CNOT_ij(0,3) @ H_q(0) @ CNOT_ij(2,1) @ H_q(2)
zero = np.array([[1],[0]], complex)
psi0 = kron(zero,zero,zero,zero)
psi_ideal = U @ psi0

survivors = []
for a03 in range(4):
    for b03 in range(4):
        E03 = kron(Psingle[a03], I, I, Psingle[b03])
        for a21 in range(4):
            for b21 in range(4):
                E21 = kron(I, Psingle[b21], Psingle[a21], I)  # careful: pair (2,1)
                psi = E03 @ CNOT_ij(0,3) @ H_q(0) @ E21 @ CNOT_ij(2,1) @ H_q(2) @ psi0
                overlap = (psi_ideal.conj().T @ psi)[0,0]
                if np.allclose(abs(overlap), 1.0, atol=1e-10):
                    survivors.append(((a03,b03),(a21,b21)))

len(survivors), survivors[:12]
Tool #7
''
Assistant #8
Tool Call (code to execute)
print(len(survivors))
print(survivors[:16])
Tool #9
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'survivors' is not defined
Assistant #10
# Recompute succinctly and print
import numpy as np
I = np.eye(2); X = np.array([[0,1],[1,0]], complex); Y = np.array([[0,-1j],[1j,0]], complex); Z = np.array([[1,0],[0,-1]], complex)
H = (1/np.sqrt(2))*np.array([[1,1],[1,-1]], complex)
from functools import reduce

def kron(*ops):
    return reduce(np.kron, ops)

def CNOT_ij(i,j):
    P0 = np.array([[1,0],[0,0]], complex)
    P1 = np.array([[0,0],[0,1]], complex)
    ops0 = [I,I,I,I]
    ops1 = [I,I,I,I]
    ops0[i] = P0
    ops1[i] = P1
    ops1[j] = X
    return kron(*ops0) + kron(*ops1)

def H_q(q):
    ops = [I,I,I,I]
    ops[q] = H
    return kron(*ops)

Psingle = [I,X,Y,Z]
U = CNOT_ij(0,3) @ H_q(0) @ CNOT_ij(2,1) @ H_q(2)
zero = np.array([[1],[0]], complex)
psi0 = kron(zero,zero,zero,zero)
psi_ideal = U @ psi0

survivors = []
for a03 in range(4):
    for b03 in range(4):
        E03 = kron(Psingle[a03], np.eye(2), np.eye(2), Psingle[b03])
        for a21 in range(4):
            for b21 in range(4):
                E21 = kron(np.eye(2), Psingle[b21], Psingle[a21], np.eye(2))
                psi = E03 @ CNOT_ij(0,3) @ H_q(0) @ E21 @ CNOT_ij(2,1) @ H_q(2) @ psi0
                ov = (psi_ideal.conj().T @ psi)[0,0]
                if np.allclose(abs(ov), 1.0, atol=1e-10):
                    survivors.append(((a03,b03),(a21,b21)))

print('number survivors =', len(survivors))
# Show which two-qubit paulis on each pair survive (indexes 0:I,1:X,2:Y,3:Z)
print(survivors[:20])
Tool #11
number survivors = 16
[((0, 0), (0, 0)), ((0, 0), (1, 1)), ((0, 0), (2, 2)), ((0, 0), (3, 3)), ((1, 1), (0, 0)), ((1, 1), (1, 1)), ((1, 1), (2, 2)), ((1, 1), (3, 3)), ((2, 2), (0, 0)), ((2, 2), (1, 1)), ((2, 2), (2, 2)), ((2, 2), (3, 3)), ((3, 3), (0, 0)), ((3, 3), (1, 1)), ((3, 3), (2, 2)), ((3, 3), (3, 3))]
Assistant #12
Tool Call (code to execute)
import numpy as np
I = np.eye(2); X = np.array([[0,1],[1,0]], complex); Y = np.array([[0,-1j],[1j,0]], complex); Z = np.array([[1,0],[0,-1]], complex)
H = (1/np.sqrt(2))*np.array([[1,1],[1,-1]], complex)
from functools import reduce

def kron(*ops):
    return reduce(np.kron, ops)

def CNOT_ij(i,j):
    P0 = np.array([[1,0],[0,0]], complex)
    P1 = np.array([[0,0],[0,1]], complex)
    ops0 = [I,I,I,I]
    ops1 = [I,I,I,I]
    ops0[i] = P0
    ops1[i] = P1
    ops1[j] = X
    return kron(*ops0) + kron(*ops1)

def H_q(q):
    ops = [I,I,I,I]
    ops[q] = H
    return kron(*ops)

Psingle = [I,X,Y,Z]
U = CNOT_ij(0,3) @ H_q(0) @ CNOT_ij(2,1) @ H_q(2)
zero = np.array([[1],[0]], complex)
psi0 = kron(zero,zero,zero,zero)
psi_ideal = U @ psi0
rho_ideal = psi_ideal @ psi_ideal.conj().T

# Build final density matrix under the channel parameter p

def rho_of_p(p):
    rho = np.zeros((16,16), complex)
    # enumerate E21 and E03 errors and accumulate weights
    for a03 in range(4):
        for b03 in range(4):
            weight03 = (1-p) if (a03==0 and b03==0) else (p/15)
            E03 = kron(Psingle[a03], I, I, Psingle[b03])
            for a21 in range(4):
                for b21 in range(4):
                    weight21 = (1-p) if (a21==0 and b21==0) else (p/15)
                    E21 = kron(I, Psingle[b21], Psingle[a21], I)
                    psi = E03 @ CNOT_ij(0,3) @ H_q(0) @ E21 @ CNOT_ij(2,1) @ H_q(2) @ psi0
                    rho += weight03 * weight21 * (psi @ psi.conj().T)
    return rho

for p in [0.0, 0.01, 0.1, 0.2, 0.5, 1.0]:
    rho = rho_of_p(p)
    F = (psi_ideal.conj().T @ rho @ psi_ideal)[0,0].real
    print(p, F, 'vs formula', (1 - 4*p/5)**2)
Tool #13
0.0 0.9999999999999992 vs formula 1.0
0.01 0.9840639999999993 vs formula 0.9840639999999999
0.1 0.8463999999999989 vs formula 0.8464
0.2 0.7056000000000002 vs formula 0.7055999999999999
0.5 0.3599999999999996 vs formula 0.36

1.0 0.039999999999999994 vs formula 0.03999999999999998
Assistant #14
  1. Step-by-Step Derivation
  • Ideal state prepared by the circuit
  • Start from |0000⟩.
  • Apply H2: puts qubit 2 in (|0⟩ + |1⟩)/√2.
  • Apply CNOT21 (control 2 → target 1): prepares a Bell pair on qubits (2,1), |Φ+⟩21 = (|00⟩ + |11⟩)/√2.
  • Apply H0 and then CNOT03 (control 0 → target 3): prepares a Bell pair on qubits (0,3), |Φ+⟩03 = (|00⟩ + |11⟩)/√2.
  • Hence the ideal final state is the product of two Bell pairs
\[ |\psi_{\text{ideal}}\rangle = |\Phi^+\rangle_{03}\otimes|\Phi^+\rangle_{21}. \]
In the computational basis (qubits ordered 0,1,2,3):
\[ |\psi_{\text{ideal}}\rangle = \tfrac{1}{2}\big(|0000\rangle + |0110\rangle + |1001\rangle + |1111\rangle\big). \]
  • This state is a code state stabilized by the given code stabilizers \(XXXX\), \(ZZZZ\) and by the logical Bell stabilizers \(Z_AZ_B=IZZI\) and \(X_AX_B=IXXI\).

  • Noise model and where it acts

  • A two-qubit depolarizing channel acts after each CNOT:
    • After CNOT21, a channel on qubits (2,1).
    • After CNOT03, a channel on qubits (0,3).
  • Each channel applies \(II\) with probability \(1-p\), and one of the 15 non-identity two-qubit Paulis with probability \(p/15\) each.
  • The two channels are independent and act on disjoint pairs, so the total error is \(E_{03}\otimes E_{21}\).

  • Fidelity for a Bell pair under two-qubit depolarizing noise

  • For a Bell state \(|\Phi^+\rangle\), the Pauli operators that leave the state invariant (up to an irrelevant global phase) are precisely
\[ \{II,\; XX,\; YY,\; ZZ\}. \]
  • Therefore, for a single two-qubit depolarizing channel with parameter \(p\),
\[ F_{\text{pair}}(p) = \Pr(II) + \Pr(XX) + \Pr(YY) + \Pr(ZZ) = (1-p) + 3\cdot \frac{p}{15} = 1 - \frac{4}{5}p. \]
  • Total four-qubit fidelity
  • Since the ideal state is a product \(|\Phi^+\rangle_{03}\otimes|\Phi^+\rangle_{21}\) and the two channels are independent on the two disjoint pairs, the total fidelity factorizes:
\[ F_{\text{phys}}(p) = \big(F_{\text{pair}}(p)\big)^2 = \left(1 - \frac{4}{5}p\right)^2. \]
  1. Mathematical Typesetting
  • Final expression:
\[ F_{\text{phys}}(p) = \left(1 - \frac{4}{5}p\right)^2 = 1 - \frac{8}{5}p + \frac{16}{25}p^2. \]
  1. Conventions and Units
  • Probabilities are dimensionless. The parameter \(p\in[0,1]\) is the error probability per two-qubit gate.
  1. Final Answer: \(F_{\text{phys}}(p) = \left(1 - \dfrac{4}{5}p\right)^2 = 1 - \dfrac{8}{5}p + \dfrac{16}{25}p^2.\)
User #15

The correct answer is: $ F_{\rm{physical}}=(1-\frac{12}{15}p)^2 $

Now let’s solve the next Checkpoint.

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 #16
Tool Call (code to execute)
import numpy as np
from functools import reduce

# Single-qubit Paulis
I = np.eye(2, 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)

Psingle = [I,X,Y,Z]

# Kronecker helper
kron = lambda *ops: reduce(np.kron, ops)

# Build circuit

def CNOT_ij(i,j):
    P0 = np.array([[1,0],[0,0]], complex)
    P1 = np.array([[0,0],[0,1]], complex)
    ops0 = [I,I,I,I]
    ops1 = [I,I,I,I]
    ops0[i] = P0
    ops1[i] = P1
    ops1[j] = X
    return kron(*ops0) + kron(*ops1)

def H_q(q):
    ops = [I,I,I,I]
    ops[q] = H
    return kron(*ops)

# Circuit: U = CNOT_03 * H0 * CNOT_21 * H2
U = CNOT_ij(0,3) @ H_q(0) @ CNOT_ij(2,1) @ H_q(2)
zero = np.array([[1],[0]], complex)
psi0 = kron(zero,zero,zero,zero)
psi_ideal = U @ psi0

# Stabilizers S1=XXXX, S2=ZZZZ
S1 = kron(X,X,X,X)
S2 = kron(Z,Z,Z,Z)

# Logical operators (one representative choice matching problem statement)
XA = kron(X, I, X, I)
XB = kron(X, X, I, I)
ZA = kron(Z, Z, I, I)
ZB = kron(Z, I, Z, I)

# Logical stabilizers of |Phi+>_AB in code space
Lstab = [np.eye(16), XA@XB, ZA@ZB, (XA@XB)@(ZA@ZB)]

# Enumerate all two-qubit Pauli on pairs (0,3) and (2,1)
# Build E_total(P03, P21)

Ops = [I,X,Y,Z]

# Function to classify a 4-qubit Pauli E as accepted and as good (leaves psi_ideal up to phase)

def is_in_normalizer(E):
    c1 = np.allclose(E@S1 - S1@E, 0)
    c2 = np.allclose(E@S2 - S2@E, 0)
    return c1 and c2

def leaves_state(E):
    psi = E @ psi_ideal
    ov = (psi_ideal.conj().T @ psi)[0,0]
    return np.allclose(abs(ov), 1.0, atol=1e-10)

# Precompute acceptance and good masks for each pair of local paulis
accepted = {}
leaves = {}
for a03 in range(4):
    for b03 in range(4):
        E03 = kron(Ops[a03], I, I, Ops[b03])
        for a21 in range(4):
            for b21 in range(4):
                E21 = kron(I, Ops[b21], Ops[a21], I)
                E = E03 @ E21
                key = (a03,b03,a21,b21)
                accepted[key] = is_in_normalizer(E)
                leaves[key] = leaves_state(E)

# Count categories for sanity
n_acc = sum(accepted.values())
n_leave = sum(v and accepted[k] for k,v in leaves.items())
print('Total combos:', 16*16, 'Accepted (normalizer):', n_acc, 'Good within accepted:', n_leave)

# As expected: normalizer has size 64; E_total restricted to product of two local 2-qubit pauli sets gives 256 combos; acceptance 64

# Build weights for each key given depolarizing probability p

def weights_of_p(p):
    # weights for each local 2-qubit pauli on a pair
    w = np.zeros((4,4))
    for a in range(4):
        for b in range(4):
            if a==0 and b==0:
                w[a,b] = 1-p
            else:
                w[a,b] = p/15
    return w

# Compute acceptance probability and conditional fidelity

def acceptance_and_fidelity(p):
    w03 = weights_of_p(p)
    w21 = weights_of_p(p)
    Pacc = 0.0
    Pgood = 0.0
    for a03 in range(4):
        for b03 in range(4):
            for a21 in range(4):
                for b21 in range(4):
                    key = (a03,b03,a21,b21)
                    w = w03[a03,b03]*w21[a21,b21]
                    if accepted[key]:
                        Pacc += w
                        if leaves[key]:
                            Pgood += w
    Fcond = Pgood/Pacc if Pacc>0 else 1.0
    return Pacc, Fcond

for p in [0.0, 0.01, 0.1, 0.2, 0.5, 1.0]:
    Pacc, Fcond = acceptance_and_fidelity(p)
    print(p, 'Pacc=', Pacc, 'F_logical=', Fcond)
Tool #17
Total combos: 256 Accepted (normalizer): 64 Good within accepted: 16
0.0 Pacc= 1.0 F_logical= 1.0
0.01 Pacc= 0.9840853333333347 F_logical= 0.9999783216631608
0.1 Pacc= 0.848533333333331 F_logical= 0.9974858579509766
0.2 Pacc= 0.7141333333333368 F_logical= 0.9880507841672854
0.5 Pacc= 0.4133333333333337 F_logical= 0.8709677419354832

1.0 Pacc= 0.25333333333333335 F_logical= 0.15789473684210525
Assistant #18
Tool Call (code to execute)
import itertools
import numpy as np

# Build classify functions as before
I = np.eye(2, 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)
Ops = [I,X,Y,Z]

# Parity functions for a 2-qubit operator P⊗Q

def parity_counts_2q(Pa, Pb):
    # returns e_z = (#Z or Y) mod 2, e_x = (#X or Y) mod 2 on the two-qubit pair
    def single_labels(M):
        if np.allclose(M, I): return 'I'
        if np.allclose(M, X): return 'X'
        if np.allclose(M, Y): return 'Y'
        if np.allclose(M, Z): return 'Z'
        raise ValueError
    la = single_labels(Pa)
    lb = single_labels(Pb)
    e_z = (la in ['Z','Y']) + (lb in ['Z','Y'])
    e_x = (la in ['X','Y']) + (lb in ['X','Y'])
    return (e_z % 2, e_x % 2)

# Count distributions across 2-qubit paulis
classes = {(ez,ex):0 for ez in [0,1] for ex in [0,1]}
classes_nonid = {(ez,ex):0 for ez in [0,1] for ex in [0,1]}

for a in range(4):
    for b in range(4):
        ez, ex = parity_counts_2q(Ops[a], Ops[b])
        classes[(ez,ex)] += 1
        if not (a==0 and b==0):
            classes_nonid[(ez,ex)] += 1

classes, classes_nonid
Tool #19
''
Assistant #20
print('All 2-qubit paulis counts by parity (ez,ex):', classes)
print('Non-identity counts by parity (ez,ex):', classes_nonid)
Tool #21
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'classes' is not defined
Assistant #22
# Re-run quickly
import numpy as np
I = np.eye(2, 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)
Ops = [I,X,Y,Z]

def parity_counts_2q(a,b):
    labels = [I,X,Y,Z]
    def lab(M):
        if np.allclose(M, I): return 'I'
        if np.allclose(M, X): return 'X'
        if np.allclose(M, Y): return 'Y'
        if np.allclose(M, Z): return 'Z'
        raise ValueError
    la = lab(a); lb = lab(b)
    ez = (la in 'ZY') + (lb in 'ZY')
    ex = (la in 'XY') + (lb in 'XY')
    return (ez%2, ex%2)

classes = {(ez,ex):0 for ez in [0,1] for ex in [0,1]}
classes_nonid = {(ez,ex):0 for ez in [0,1] for ex in [0,1]}
for a in Ops:
    for b in Ops:
        ez,ex = parity_counts_2q(a,b)
        classes[(ez,ex)] += 1
        if not (a is I and b is I):
            classes_nonid[(ez,ex)] += 1

print(classes)
print(classes_nonid)
Tool #23
{(0, 0): 4, (0, 1): 4, (1, 0): 4, (1, 1): 4}
{(0, 0): 3, (0, 1): 4, (1, 0): 4, (1, 1): 4}
Assistant #24
  1. Step-by-Step Derivation
  • Ideal state prepared by the circuit
  • Start from |0000⟩.
  • Apply H2, then CNOT21: prepares a Bell pair on (2,1): |Φ+⟩21 = (|00⟩ + |11⟩)/√2.
  • Apply H0, then CNOT03: prepares a Bell pair on (0,3): |Φ+⟩03 = (|00⟩ + |11⟩)/√2.
  • Hence the ideal final 4-qubit state is the product
\[ |\psi_{\text{ideal}}\rangle = |\Phi^+\rangle_{03}\otimes|\Phi^+\rangle_{21}. \]
This is a valid code state stabilized by S = {XXXX, ZZZZ}, and for the logical Bell state on A,B it is also stabilized by the logical operators X_AX_B = IXXI and Z_AZ_B = IZZI.
  • Noise model and placement
  • A two-qubit depolarizing channel acts after each CNOT:
    • After CNOT21, a channel on qubits (2,1).
    • After CNOT03, a channel on qubits (0,3).
  • Each channel applies II with probability 1 − p, and one of the 15 non-identity two-qubit Paulis with probability p/15 each.
  • The two channels are independent and on disjoint pairs; thus the net error is E = E03 ⊗ E21, and because they occur after the CNOTs and on disjoint qubits, they commute with the subsequent gates and are effectively applied at the end to |ψideal⟩.

  • Post-selection on detectable errors

  • We post-select on measuring +1 for both stabilizers XXXX and ZZZZ. For a code state, an error E is accepted iff E commutes with both stabilizers, i.e., E lies in the normalizer N(S).
  • Characterize commutation by parities. For a 4-qubit Pauli P0⊗P1⊗P2⊗P3:
    • Commutation with XXXX requires an even number of factors in {Z,Y}.
    • Commutation with ZZZZ requires an even number of factors in {X,Y}.
  • Since E = E03 ⊗ E21 with E03 on (0,3) and E21 on (2,1), define for each pair (e_z, e_x) parities:
    • e_z = parity of the count of {Z,Y} on the two qubits of the pair,
    • e_x = parity of the count of {X,Y} on the two qubits of the pair.
  • Acceptance requires the parity vectors to match across the two pairs:
\[ (e_z^{03}, e_x^{03}) = (e_z^{21}, e_x^{21}). \]
  • Counting on a single two-qubit pair
  • Among the 16 two-qubit Paulis, the parity classes (e_z,e_x) are equally populated: 4 elements each.
  • Among the 15 non-identity operators, the counts by parity are:

    • (0,0): 3 elements (XX, YY, ZZ),
    • (0,1): 4 elements,
    • (1,0): 4 elements,
    • (1,1): 4 elements.
  • Acceptance probability Pacc(p)

  • Sum weights over all accepted combinations (E03, E21). There are three cases: 1) (II, II): 1 combination, weight (1 − p)^2. 2) Exactly one non-identity (say on one pair): accepted only if it is in class (0,0), i.e., 3 choices on that pair; total 2×3 combinations, each with weight (1 − p)·(p/15). 3) Both non-identity: accepted if parity classes match across pairs; number of such combinations is 3^2 + 4^2 + 4^2 + 4^2 = 57, each with weight (p/15)^2.
  • Therefore,
\[ P_{\text{acc}}(p) &= (1-p)^2 + 2\cdot 3\,(1-p)\frac{p}{15} + 57\left(\frac{p}{15}\right)^2 \\ &= 1 - \frac{24}{15}p + \frac{64}{75}p^2. \]
  • “Good” (logically correct) accepted events
  • The target logical Bell state |Φ+⟩AB is stabilized (up to global phase) by the logical operators {I, X_AX_B, Z_AZ_B, Y_AY_B}. At the physical level, this corresponds to applying on each Bell pair one of {II, XX, YY, ZZ}.
  • Thus “good” events are exactly those for which each pair’s two-qubit Pauli is in the (0,0) class. Counting and weighting: 1) (II, II): 1 combination, weight (1 − p)^2. 2) Exactly one non-identity, in (0,0): 2×3 combinations, each of weight (1 − p)(p/15). 3) Both non-identity, both in (0,0): 3×3 = 9 combinations, each of weight (p/15)^2.
  • Hence
\[ P_{\text{good}}(p) &= (1-p)^2 + 2\cdot 3\,(1-p)\frac{p}{15} + 9\left(\frac{p}{15}\right)^2 \\ &= \Big((1-p) + 3\frac{p}{15}\Big)^2 \\ &= \left(1 - \frac{12}{15}p\right)^2. \]
  • Logical state fidelity after post-selection
  • The conditional logical fidelity is the fraction of accepted runs that are “good”:
\[ F_{\text{logical}}(p) = \frac{P_{\text{good}}(p)}{P_{\text{acc}}(p)} = \frac{\left(1 - \frac{12}{15}p\right)^2}{1 - \frac{24}{15}p + \frac{64}{75}p^2}. \]
  • Small-p expansion shows first-order cancellation due to post-selection:
\[ F_{\text{logical}}(p) = 1 - \frac{16}{75}p^2 + O(p^3). \]
  1. Mathematical Typesetting
  • Key expressions are displayed above.
  1. Conventions and Units
  • Probability p ∈ [0,1] is dimensionless; fidelity is dimensionless.
  1. Final Answer: \(F_{\text{logical}}(p) = \dfrac{\left(1 - \dfrac{12}{15}p\right)^2}{1 - \dfrac{24}{15}p + \dfrac{64}{75}p^2} = \dfrac{\left(1 - \dfrac{4}{5}p\right)^2}{1 - \dfrac{8}{5}p + \dfrac{64}{75}p^2}.\)
User #25

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 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$ in Sympy format.

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

    Outputs
    ----------
    F_logical: sympy.Expr, the logical state fidelity as a function of $p$
    """

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

    return F_logical
Assistant #26
import sympy as sp

p = sp.symbols('p')

def answer(p):
    r"""
    Return the expression of 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$ in Sympy format.

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

    Outputs
    ----------
    F_logical: sympy.Expr, the logical state fidelity as a function of $p$
    """

    # ------------------ FILL IN YOUR RESULTS BELOW ------------------
    F_logical = ((1 - sp.Rational(4,5)*p)**2) / (1 - sp.Rational(8,5)*p + sp.Rational(64,75)*p**2)
    # ---------------------------------------------------------------

    return F_logical