qerror.ipynb
269 lines
| 60.8 KiB
| text/plain
|
TextLexer
Quantum Error Correction
In [1]:
%load_ext sympyprinting
In [2]:
from sympy import sqrt, symbols, Rational
from sympy import expand, Eq, Symbol, simplify, exp, sin
from sympy.physics.quantum import *
from sympy.physics.quantum.qubit import *
from sympy.physics.quantum.gate import *
from sympy.physics.quantum.grover import *
from sympy.physics.quantum.qft import QFT, IQFT, Fourier
from sympy.physics.quantum.circuitplot import circuit_plot
5 qubit code
In [3]:
M0 = Z(1)*X(2)*X(3)*Z(4); M0
Out[3]:
In [4]:
M1 = Z(2)*X(3)*X(4)*Z(0); M1
Out[4]:
In [5]:
M2 = Z(3)*X(4)*X(0)*Z(1); M2
Out[5]:
In [6]:
M3 = Z(4)*X(0)*X(1)*Z(2); M3
Out[6]:
These operators should mutually commute.
In [7]:
gate_simp(Commutator(M0,M1).doit())
Out[7]:
And square to the identity.
In [8]:
for o in [M0,M1,M2,M3]:
display(gate_simp(o*o))
Codewords
In [9]:
zero = Rational(1,4)*(1+M0)*(1+M1)*(1+M2)*(1+M3)*IntQubit(0, 5); zero
Out[9]:
In [10]:
qapply(4*zero)
Out[10]:
In [11]:
one = Rational(1,4)*(1+M0)*(1+M1)*(1+M2)*(1+M3)*IntQubit(2**5-1, 5); one
Out[11]:
In [12]:
qapply(4*one)
Out[12]:
The encoding circuit
In [13]:
encoding_circuit = H(3)*H(4)*CNOT(2,0)*CNOT(3,0)*CNOT(4,0)*H(1)*H(4)*\
CNOT(2,1)*CNOT(4,1)*H(2)*CNOT(3,2)*CNOT(4,2)*H(3)*\
H(4)*CNOT(4, 3)*Z(4)*H(4)*Z(4)
In [14]:
circuit_plot(encoding_circuit, nqubits=5, scale=0.5)
Out[14]:
In [15]:
represent(4*encoding_circuit, nqubits=5)
Out[15]: