##// END OF EJS Templates
add '/' separator to keys in SSH engine dict...
add '/' separator to keys in SSH engine dict to prevent confusing with number-ending nodenames in log output.

File last commit:

r4637:d919e2ec
r5181:79a50b94
Show More
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]:
$$Z_{1} X_{2} X_{3} Z_{4}$$
In [4]:
M1 = Z(2)*X(3)*X(4)*Z(0); M1
Out[4]:
$$Z_{2} X_{3} X_{4} Z_{0}$$
In [5]:
M2 = Z(3)*X(4)*X(0)*Z(1); M2
Out[5]:
$$Z_{3} X_{4} X_{0} Z_{1}$$
In [6]:
M3 = Z(4)*X(0)*X(1)*Z(2); M3
Out[6]:
$$Z_{4} X_{0} X_{1} Z_{2}$$

These operators should mutually commute.

In [7]:
gate_simp(Commutator(M0,M1).doit())
Out[7]:
$$0$$

And square to the identity.

In [8]:
for o in [M0,M1,M2,M3]:
    display(gate_simp(o*o))
$$1$$
$$1$$
$$1$$
$$1$$

Codewords

In [9]:
zero = Rational(1,4)*(1+M0)*(1+M1)*(1+M2)*(1+M3)*IntQubit(0, 5); zero
Out[9]:
$$\frac{1}{4} \left(1 + Z_{1} X_{2} X_{3} Z_{4}\right) \left(1 + Z_{2} X_{3} X_{4} Z_{0}\right) \left(1 + Z_{3} X_{4} X_{0} Z_{1}\right) \left(1 + Z_{4} X_{0} X_{1} Z_{2}\right) {\left|0\right\rangle }$$
In [10]:
qapply(4*zero)
Out[10]:
$${\left|0\right\rangle } + {\left|3\right\rangle } - {\left|5\right\rangle } + {\left|6\right\rangle } - {\left|9\right\rangle } - {\left|10\right\rangle } + {\left|12\right\rangle } - {\left|15\right\rangle } + {\left|17\right\rangle } - {\left|18\right\rangle } - {\left|20\right\rangle } - {\left|23\right\rangle } + {\left|24\right\rangle } - {\left|27\right\rangle } - {\left|29\right\rangle } - {\left|30\right\rangle }$$
In [11]:
one = Rational(1,4)*(1+M0)*(1+M1)*(1+M2)*(1+M3)*IntQubit(2**5-1, 5); one
Out[11]:
$$\frac{1}{4} \left(1 + Z_{1} X_{2} X_{3} Z_{4}\right) \left(1 + Z_{2} X_{3} X_{4} Z_{0}\right) \left(1 + Z_{3} X_{4} X_{0} Z_{1}\right) \left(1 + Z_{4} X_{0} X_{1} Z_{2}\right) {\left|31\right\rangle }$$
In [12]:
qapply(4*one)
Out[12]:
$$- {\left|1\right\rangle } - {\left|2\right\rangle } - {\left|4\right\rangle } + {\left|7\right\rangle } - {\left|8\right\rangle } - {\left|11\right\rangle } - {\left|13\right\rangle } + {\left|14\right\rangle } - {\left|16\right\rangle } + {\left|19\right\rangle } - {\left|21\right\rangle } - {\left|22\right\rangle } + {\left|25\right\rangle } - {\left|26\right\rangle } + {\left|28\right\rangle } + {\left|31\right\rangle }$$

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]:
<sympy.physics.quantum.circuitplot.CircuitPlot object at 0x38a6950>
No description has been provided for this image
In [15]:
represent(4*encoding_circuit, nqubits=5)
Out[15]:
$$\left(\begin{smallmatrix}1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 0 & -1 & 0 & -1 & 0 & -1 & 0 & -1 & 0 & -1 & 0 & -1 & 0 & -1 & 0 & -1 & -1 & 0 &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