Skip to content

Instantly share code, notes, and snippets.

@Strilanc
Created September 2, 2022 14:11
Show Gist options
  • Save Strilanc/40c4607b8b95165c92734eeced27d450 to your computer and use it in GitHub Desktop.
Save Strilanc/40c4607b8b95165c92734eeced27d450 to your computer and use it in GitHub Desktop.
This is a stim circuit that implements entanglement distillation using the 5 qubit perfect code. Basically you share five noisy EPR pairs between Alice and Bob, then Alice and Bob both measure the 5Q code stabilizers, and they discard whenever their measured stabilizers disagree. For a depolarization strength of 1e-3 this results in a discard ra…
# Quirk testing URL:
# https://algassert.com/quirk#circuit=%7B%22cols%22%3A%5B%5B%22H%22%2C%22H%22%2C%22H%22%2C%22H%22%2C%22H%22%5D%2C%5B%22%E2%80%A2%22%2C1%2C1%2C1%2C1%2C%22X%22%5D%2C%5B1%2C%22%E2%80%A2%22%2C1%2C1%2C1%2C1%2C%22X%22%5D%2C%5B1%2C1%2C%22%E2%80%A2%22%2C1%2C1%2C1%2C1%2C%22X%22%5D%2C%5B1%2C1%2C1%2C%22%E2%80%A2%22%2C1%2C1%2C1%2C1%2C%22X%22%5D%2C%5B1%2C1%2C1%2C1%2C%22%E2%80%A2%22%2C1%2C1%2C1%2C1%2C%22X%22%5D%2C%5B%22xpar%22%2C%22zpar%22%2C%22xpar%22%2C%22xpar%22%2C1%2C%220%22%5D%2C%5B%22Measure%22%5D%2C%5B%22zpar%22%2C1%2C%22zpar%22%2C%22xpar%22%2C%22zpar%22%2C%220%22%5D%2C%5B1%2C1%2C1%2C1%2C%22H%22%5D%2C%5B1%2C1%2C1%2C1%2C%22Measure%22%5D%2C%5B%22zpar%22%2C%22xpar%22%2C%22xpar%22%2C1%2C%22zpar%22%2C%220%22%5D%2C%5B1%2C%22Measure%22%5D%2C%5B1%2C%22zpar%22%2C%22zpar%22%2C%22zpar%22%2C%22zpar%22%2C%220%22%5D%2C%5B1%2C1%2C1%2C%22H%22%5D%2C%5B1%2C1%2C1%2C%22Measure%22%5D%2C%5B1%2C1%2C1%2C1%2C1%2C%22xpar%22%2C%22zpar%22%2C%22xpar%22%2C%22xpar%22%2C1%2C1%2C1%2C1%2C1%2C1%2C%22X%22%5D%2C%5B1%2C1%2C1%2C1%2C1%2C%22zpar%22%2C1%2C%22zpar%22%2C%22xpar%22%2C%22zpar%22%2C1%2C1%2C1%2C1%2C%22X%22%5D%2C%5B1%2C1%2C1%2C1%2C1%2C1%2C%22zpar%22%2C%22zpar%22%2C%22zpar%22%2C%22xpar%22%2C1%2C1%2C1%2C%22X%22%5D%2C%5B1%2C1%2C1%2C1%2C1%2C%22zpar%22%2C%22xpar%22%2C%22xpar%22%2C1%2C%22xpar%22%2C1%2C1%2C%22X%22%5D%2C%5B1%2C1%2C%22xpar%22%2C%22zpar%22%2C%22zpar%22%2C1%2C1%2C%22xpar%22%2C%22xpar%22%2C%22xpar%22%2C1%2C%22X%22%5D%2C%5B%22zpar%22%2C%22zpar%22%2C%22zpar%22%2C1%2C1%2C%22zpar%22%2C%22zpar%22%2C%22zpar%22%2C1%2C1%2C%22X%22%5D%5D%7D
# To get discard rate (it's around 1 per 100):
# stim detect --in circuit.stim --append_observables --shots 10000000 | grep -P ".*1.*.." | wc -l
# To get bad kept output rate (it's around 1 per hundred million):
# stim detect --in circuit.stim --append_observables --shots 1000000000 | grep -P "0000(10|01|11)" | wc -l
# Noisy EPR pair distribution
H 1 2 3 4 5
CX 1 11 2 12 3 13 4 14 5 15
DEPOLARIZE1(0.001) 1 2 3 4 5 11 12 13 14 15
# Measure stabilizers at Alice.
MPP X1*Z2*X3*X4
MZ 1
MPP Z3*X4*Z5
MX 5
MPP X2*X3
MZ 2
MPP Z3*Z4
MX 4
# output is in qubit 3 (up to feedback Paulis from measurements)
# Measure stabilizers at Bob.
MPP X11*Z12*X13*X14
MZ 11
MPP Z13*X14*Z15
MX 15
MPP X12*X13
MZ 12
MPP Z13*Z14
MX 14
# output is in qubit 13 (up to feedback Paulis from measurements)
# Pauli frame tracking for the logical XX and ZZ observables between Alice and Bob.
OBSERVABLE_INCLUDE(0) rec[-1] rec[-5] rec[-9] rec[-13]
OBSERVABLE_INCLUDE(1) rec[-3] rec[-7] rec[-11] rec[-15]
# Check whether the stabilizers were identical between Alice and Bob.
DETECTOR rec[-2] rec[-3] rec[-5] rec[-10] rec[-11] rec[-13]
DETECTOR rec[-4] rec[-5] rec[-7] rec[-12] rec[-13] rec[-15]
DETECTOR rec[-6] rec[-7] rec[-14] rec[-15]
DETECTOR rec[-8] rec[-16]
# Magically verify whether the entangled observables between Alice and Bob were correct.
MPP X3*X13
OBSERVABLE_INCLUDE(0) rec[-1]
MPP Z3*Z13
OBSERVABLE_INCLUDE(1) rec[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment