# Simulation for the [5,1,3] stabilizer code in Qiskit

Sorry that I keep asking questions for the same subject. It is driving me crazy.

I have followed the [5,1,3] stabilizer code circuit designed by Gottesman in page 35 in his paper (also illustrated in my another question). This code has four stabilizer generators $$XZZXI$$, $$IXZZX$$, $$XIXZZ$$, $$ZXIXZ$$.

The following is a minimal working example in which I only draw the stabilizer generator $$IXZZX$$,

from qiskit import *

encoded = QuantumRegister(5,'encoded')
stab = QuantumRegister(4,'stab')
syndr = ClassicalRegister(4, 'syndr')
five = QuantumCircuit(encoded)
fiveS = QuantumCircuit(encoded, stab, syndr)

#----------------------------------encode----------------------------------
five.h(encoded[0])
five.h(encoded[1])
five.h(encoded[2])
five.h(encoded[3])

five.z(encoded[0])
five.z(encoded[3])

five.cz(encoded[0],encoded[1])
five.cz(encoded[0],encoded[3])
five.cy(encoded[0],encoded[4])

five.cz(encoded[1],encoded[2])
five.cz(encoded[1],encoded[3])
five.cx(encoded[1],encoded[4])

five.cz(encoded[2],encoded[0])
five.cz(encoded[2],encoded[1])
five.cx(encoded[2],encoded[4])

five.cz(encoded[3],encoded[0])
five.cz(encoded[3],encoded[2])
five.cy(encoded[3],encoded[4])

five.barrier()

#-------------------stabilizer generator IXZZX------------------------------
fiveS.h(stab[1])
fiveS.cx(stab[1],encoded[1])
fiveS.cz(stab[1],encoded[2])
fiveS.cz(stab[1],encoded[3])
fiveS.cx(stab[1],encoded[4])
fiveS.h(stab[1])

fiveS.measure(stab,syndr)

#----------------circuit visualization--------------------
#%matplotlib inline
#(five+fiveS).draw(output='mpl')

counts = execute( five+fiveS, Aer.get_backend('qasm_simulator'), shots=10000).result().get_counts()
print(counts)


Measuring stabilizer generators should return $$0000$$ but instead I get half $$0000$$ and half $$0010$$ (Same results returns when measuring $$XIXZZ$$, $$ZXIXZ$$). Where am I wrong?

## Question updated

I tried to add all qubits in one quantum register and produce one quantum circuit.

from qiskit import *

stab = QuantumRegister(9,'stab')
syndr = ClassicalRegister(4, 'syndr')
five = QuantumCircuit(stab, syndr)

#----------------------------------encode----------------------------------
five.h(stab[0])
five.h(stab[1])
five.h(stab[2])
five.h(stab[3])

five.z(stab[0])
five.z(stab[3])

five.cz(stab[0],stab[1])
five.cz(stab[0],stab[3])
five.cy(stab[0],stab[4])

five.cz(stab[1],stab[2])
five.cz(stab[1],stab[3])
five.cx(stab[1],stab[4])

five.cz(stab[2],stab[0])
five.cz(stab[2],stab[1])
five.cx(stab[2],stab[4])

five.cz(stab[3],stab[0])
five.cz(stab[3],stab[2])
five.cy(stab[3],stab[4])

five.barrier()

#-------------------stabilizer generator IXZZX------------------------------
five.h(stab[6])
five.cx(stab[6],stab[1])
five.cz(stab[6],stab[2])
five.cz(stab[6],stab[3])
five.cx(stab[6],stab[4])
five.h(stab[6])

five.measure(stab[5],syndr[0])
five.measure(stab[6],syndr[1])
five.measure(stab[7],syndr[2])
five.measure(stab[8],syndr[3])

#----------------circuit visualization--------------------
#%matplotlib inline
#five.draw(output='mpl')

counts = execute( five, Aer.get_backend('qasm_simulator'), shots=10000).result().get_counts()
print(counts)


However, the same happens. The following are my running results.

• Could you retry this while adding the encoding operation into the circuit/program fiveS instead of five? It might be the case that the 'encoded' register in fiveS does actually not have the encoded state - that means that the state of the data qubits is mostly shared even over the +1 and -1 eigenspace of the generator you are measuring
– JSdJ
Jan 7, 2020 at 13:55
• Thank you for your help! I tried. However, the same happens. I have updated new circuit version and running results in my original question. Jan 7, 2020 at 15:17
• My Qiskit installation is broken, so I can't run any code of my own... It's weird, everything looks correct to me. Could you try a couple of things: - Try to run the stabilizer measurement without the encoding scheme, - Try a different stabilizer, And report back if you are still getting these -1 eigenvalues? I'm not familiar with the encoding scheme from Gottesman here (I don't know how he got it), so I don't really know if it is correct
– JSdJ
Jan 7, 2020 at 15:45
• -If I run without the encoding scheme, $IXZZX$ won't stabilize $|00000\rangle$, it returns half $+1$ half $-1$ as expected. -Only XZZXI returns all $+1$, the other three still get $-1$ eigenvalues. I could only guess that this encoding scheme does not match these stabilizer generators. Jan 8, 2020 at 2:16