[PYTHON] Basics of Quantum Information Theory: Quantum Error Correction (Shor's Code)

\def\bra#1{\mathinner{\left\langle{#1}\right|}} \def\ket#1{\mathinner{\left|{#1}\right\rangle}} \def\braket#1#2{\mathinner{\left\langle{#1}\middle|#2\right\rangle}}

Introduction

When the principle of quantum computing was first clarified in the 1980s, there was no theory of error correction like that used in classical digital processing, or it was extremely difficult to establish that theory, so quantum computers are realistic. It seems that some people thought it was impossible. In the case of classical bits, it is only necessary to consider the error that the bit is inverted, whereas in the case of the qubit, the change has infinite degrees of freedom, so it is necessary to deal with an error of an infinite pattern. If you imagine a Bloch sphere, there are infinite ways to shift the quantum state. You have to think about restoring the original state accurately from the shifted state. In addition, quantum states cannot be replicated innocently like classical information, and are broken when measured. It seems that there were various things such as, and it was thought that the difficulty was not odd. Peter Shor was the first to break it. By using the "Shor code" proposed by this Shor, any error acting on one qubit can be corrected. This "arbitrary" place is amazing. Moreover, it can be realized with a relatively simple quantum circuit. This time, after explaining the theory, I would like to realize its power with the quantum calculation simulator qlazy.

The following documents were used as references.

  1. Nielsen, Chan "Quantum Computer and Quantum Communication (3)" Ohmsha (2005)
  2. Tomita "Quantum Information Engineering" Morikita Publishing (2017)
  3. Nakayama "Quantum Algorithm" Gihodo Publishing (2014)

Confirmation of theory

Classical error correction (repetition code)

As a preparatory exercise before going into the story of quantum error correction, I will review the basic idea of error correction in classical information. Now consider transmitting 1-bit information through a noisy classical channel. Suppose that this channel causes the bits to be inverted with a probability of p. That is, if the input bit is 0, the probability p flips the bit to 1 and the probability 1-p keeps it 0. Also, if the input bit is 1, the bit is inverted to 0 with probability p and remains 1 with probability 1-p. Such a channel is called a "binary symmetric channel". If you don't think about it and just use this channel, the error rate is p, of course. Is it possible to reduce the error rate by performing some processing on the premise of this channel?

The basic and well-known method is to duplicate bits and intentionally make them redundant. For example, the given 1-bit information is converted (encoded) into 3 bits as shown below.

\begin{align}
0 &\rightarrow 000 \\
1 &\rightarrow 111 \\
\end{align}

This is transmitted one after another through the classical channel. The amount of information will be tripled, but the idea is that there is no choice but to correct errors. The bit string 000 may be 010 on the receiving side, as the noise stochastically inverts the bits. However, this is because the middle bit is inverted, and I guess it is actually 000. In other words, it is a method of taking a majority vote and assuming that many bits are the original bits. It is called an "repetition code" because it repeats and encodes the input bits. As you can see, it's possible that the input is 000 and the noise results in 110. However, I think it is better if the total average error rate is small. So how is the average error rate calculated specifically? Since 0 or 1 bit inversion can be corrected, only the probability that 2 or 3 bits will be inverted will give the desired error rate. The probability of flipping 3 at a time is $ p ^ 3 $, and the probability of flipping 2 is $ 3p ^ 2 (1-p) $ for 3 patterns. Add this to get $ p ^ 3 + 3p ^ 2 (1-p) = 3p ^ 2 --2p ^ 3 $. Since the error rate when nothing was done was $ p $, the condition that the error rate is smaller when the error is corrected is $ p> 3p ^ 2 --2p ^ 3 $, that is, $ p <1 / It will be 2 $. In other words, if the value of $ p $ is less than $ 1/2 $, the effect of this repeating code will be exhibited.

Bit inversion code for 3 qubits

Coding

In the case of qubits, they are encoded in a similar way. For example, if the state of one qubit is $ \ ket {\ psi} = a \ ket {0} + b \ ket {1} $, then it is $ a \ ket {000} + b \ ket {111} Consider whether it can be transformed (encoded) like $. As you can see easily, it can be realized by passing through the following quantum circuit.

|psi> --*--*-- ...
        |  |
  |0> --X----- ...
           |  
  |0> -----X-- ...

In this state, even if one bit is inverted and changed to $ \ ket {000} \ rightarrow \ ket {010} $, the original state can be restored. I will explain that from now on (the dots in the figure indicate that they are noise channels, and so on).

Error detection (syndrome diagnosis)

First, we need to know which bit is inverted. This procedure is called "error-detection" or "syndrome diagnosis". In the case of 3 bits, you can find out by performing the following projection operation.

\begin{align}
P_0 &= \ket{000} \bra{000} + \ket{111} \bra{111} \\
P_1 &= \ket{100} \bra{100} + \ket{011} \bra{011} \\
P_2 &= \ket{010} \bra{010} + \ket{101} \bra{101} \\
P_3 &= \ket{001} \bra{001} + \ket{110} \bra{110} \tag{1}
\end{align}

$ P_0 $ is a projection operator for measurements that detect that nothing is wrong. $ P_1 $ is a projection measurement that detects that the first bit is incorrect. Below, $ P_2 $ is a projection measurement that detects an error in the second bit and $ P_3 $ is an error in the third bit. If the noise results in $ a \ ket {100} + b \ ket {011} $, only $ \ bra {\ psi} P_1 \ ket {\ psi} $ will be 1 and all others will be 0. So you can see that $ P_1 $ is certainly an operator for error detection in the first bit.

In addition to this example, there is a projection measurement for diagnosing syndrome. In equation (1), we used four operators, but there is a suguremono that can be done with two. Let me conclude first. How to measure the $ Z_1 Z_2 $ and $ Z_2 Z_3 $ observables, where the Pauli $ Z $ operators applied to the first, second, and third qubits are $ Z_1, Z_2, and Z_3 $, respectively. is. Even if it is said that it is crazy, it may be in a state of "Hmm?", So I will add a little explanation.

Pauli $ Z $ can be written as $ Z = \ ket {0} \ bra {0}-\ ket {1} \ bra {1} $, so

\begin{align}
Z_1 Z_2 &= (\ket{0}_{1}\bra{0}_{1}-\ket{1}_{1}\bra{1}_{1})(\ket{0}_{2}\bra{0}_{2}-\ket{1}_{2}\bra{1}_{2}) \\
&= \ket{00}\bra{00} + \ket{11}\bra{11} - \ket{01}\bra{01} - \ket{10}\bra{10} \\
&= (\ket{00}\bra{00} + \ket{11}\bra{11}) \otimes I_3 - (\ket{01}\bra{01} + \ket{10}\bra{10}) \otimes I_3 \tag{2}
\end{align}

Can be expanded. As you can see by staring at this equation, if the first and second qubits are the same (called "even parity"), measuring this observable will output 1. Conversely, if the first and second qubits are different (called "odd parity"), -1 is output [^ 1]. That is, you can check the parity of the first and second qubits by making a measurement of $ Z_1 Z_2 $. Similarly, a measurement of $ Z_2 Z_3 $ reveals the parity of the second and third qubits.

[^ 1]: Here, the expression "measure the observable" may be a little confusing, so I will add a little explanation. Observable is literally "observable amount". In the framework of quantum mechanics, physically observable quantities can be expressed as Hermitian operators. The representative player is Hamiltonian who expressed the physical quantity of energy as a Hermitian operator. Measuring a physical quantity is equivalent to solving the corresponding eigenvalue problem of the observable-Hermitian operator, the measured value is the eigenvalue (because it is Hermitian, it is always a real value), and the state after measurement is the eigenvalue. It becomes the corresponding eigenvector (eigenstate). What is currently given as an observable is Pauli $ Z $ (product). Measuring Pauli $ Z $ means, physically, measuring the energy value of the system given by Hamiltonian $ H = Z $. In other words, it is a measurement in the Z-axis direction of a 1-spin system. In other words, you can think of it as the measurement of qubits, which is familiar in quantum circuits. After all, "measuring the observable" of $ Z_1 Z_2 $ is nothing, measuring the first qubit on a computational basis to get a value of -1 or 1 and the second qubit Is to measure with a qubit to get a value of -1 or 1 and take the product of them. At this time, the order of the first and second measurements can be either (because they can be exchanged as operators). By the way, measuring the observable called Pauli $ X $ means performing the measurement in the X-axis direction in terms of qubits, so after applying the Hadamard gate, measure in the Z-axis direction. Equivalent to doing.

The table is as follows.

Z_1 Z_2Measured value (parity) Z_2 Z_3Measured value (parity) Inverting bits
+1 (even) +1 (even) None
+1 (even) -1 (odd) The third
-1 (odd) +1 (even) First
-1 (odd) -1 (odd) The second

In the first line, the first and second are even parity, and the second and third are even parity, so it seems that it can be estimated that there are no inverted bits.

In the second line, the first and second are even parity, and the second and third are odd parity, so it can be estimated that the third is inverted.

In the 3rd line, the 1st and 2nd are odd parity, and the 2nd and 3rd are even parity, so the 1st is likely to be inverted.

In the last 4th line, the 1st and 2nd are odd parity, and the 2nd and 3rd are odd parity, so it seems likely that the 2nd in the middle is inverted.

Therefore, it is possible to estimate the number of the inverted qubit. If there is at most one qubit that is inverted, it is possible to completely identify the number of the inverted qubit.

What kind of quantum circuit can this syndrome diagnosis be realized? You just have to measure it

|psi> --*--*-- ... --M--
        |  |
  |0> --X----- ... --M--
           |  
  |0> -----X-- ... --M--

It may end up as. But this is no good. The qubit that I want to correct the error has been destroyed by measurement. Therefore, in order not to destroy the quantum state that you want to correct the error, add an auxiliary qubit (ancillary) as shown below, let the target quantum state escape there, and do not measure that state. I can't.

|psi> --*--*-- ... --*------------
        |  |         |
  |0> --X----- ... -----*--*------
           |         |  |  |
  |0> -----X-- ... -----------*---
                     |  |  |  |
               |0> --X--X--------M1
                           |  |
               |0> --------X--X--M2

Here, the measurement of $ Z_1 Z_2 $ is expressed as M1 and the measurement of $ Z_2 Z_3 $ is expressed as M2 [^ 2].

[^ 2]: The target bit is measured after passing two CNOTs with the first and second qubits as control bits (Measurement of M1), but why did I measure $ Z_1 Z_2 $? Will that happen? If you write $ \ ket {x} \ ket {y} \ ket {0} \ rightarrow \ ket {x} \ ket {y} \ ket {x \ oplus y} $, $ x $ and $ y $ If they are the same, they are $ \ ket {x} \ ket {y} \ ket {0} $, and the measured value of M1 is +1. If they are different, they are $ \ ket {x} \ ket {y} \ ket {1} $. , The measured value of M1 is -1.

recovery

Now that the qubit that is being inverted has been identified by the syndrome diagnosis, the next step is to invert the qubit again and restore it. Turns the X gate ON / OFF according to the values of M1 and M2.

|psi> --*--*-- ... --*------------X---
        |  |         |            ||
  |0> --X----- ... -----*--*------X---
           |         |  |  |      ||
  |0> -----X-- ... -----------*---X---
                     |  |  |  |   ||
               |0> --X--X---------M1
                           |  |   ||
               |0> --------X--X---M2

I tried to express the control of the gate according to the measurement result with a double vertical bar (it is difficult to understand and it is not a formal way of writing, but please feel it, sweat). X-gate any of the three qubits with the pattern shown in the table above. This will return it to its original state [^ 3].

[^ 3]: Of course, the current premise is that the number of qubits inverted due to noise is 1 or less, so if 2 bits or more are inverted, it cannot be restored.

Instead of manipulating the gate according to the measurement result, you can do the same with CNOT and Toffoli.

              [noise]
|psi> --*--*-- ... --*-------------------X--X--
        |  |         |                   |  |
  |0> --X----- ... -----*--*----------------X--
           |         |  |  |             |  |
  |0> -----X-- ... -----------*-------X-----X--
                     |  |  |  |       |  |  |
               |0> --X--X----------------*--*--
                           |  |       |     |
               |0> --------X--X-------*-----*--

     [Coding]     [Syndrome diagnosis]  [correction]

Do you understand this?

At the stage of syndrome diagnosis, if the first ansila is +1 ($ \ ket {0} ) and the second ansila is +1 ( \ ket {0} $), it is described as [correction]. Since the control bits of the circuit section are both $ \ ket {0} $, nothing is done.

If the first qubit is +1 ($ \ ket {0} ) and the second qubit is -1 ( \ ket {1} $), then only the second qubit in the correction circuit is $ \ ket {1 Since it becomes} $, the X gate is applied to the third qubit and it is inverted.

If the first qubit is -1 ($ \ ket {1} ) and the second qubit is +1 ( \ ket {0} $), then only the first qubit in the correction circuit is $ \ ket {1 Since it becomes} $, the X gate is applied to the first qubit and it is inverted.

If the first qubit is -1 ($ \ ket {1} ) and the second qubit is -1 ( \ ket {1} $), then both qubits in the correction circuit are $ \ ket {1} $. Therefore, the X gate is applied to the second qubit and it is inverted.

So now we are able to recover the bits for all error patterns.

Decryption

Finally, do the reverse of the encoding to completely restore it to its original state.

              [noise]
|psi> --*--*-- ... --*-------------------X--X---*--*-- |psi>
        |  |         |                   |  |   |  |
  |0> --X----- ... -----*--*----------------X------X-- |0>
           |         |  |  |             |  |   |
  |0> -----X-- ... -----------*-------X-----X---X----- |0>
                     |  |  |  |       |  |  |
               |0> --X--X----------------*--*--
                           |  |       |     |
               |0> --------X--X-------*-----*--

     [Coding]     [Syndrome diagnosis]  [correction]   [Decryption]

This completes the error correction circuit for the inversion of one qubit.

However, it is not good that an extra 2 qubits are required as an ansila. The circuit that was conceived is shown below because we want to eliminate ancilla if possible. The idea is that only the first qubit needs to be recovered, so the second and third do not have to be restored. However, make sure there is no entanglement between at least the first qubit and the other qubits.

|psi> --*--*-- ... --*--*--X-- |psi>
        |  |         |  |  |
  |0> --X----- ... -----X--*--
           |         |     |
  |0> -----X-- ... --X-----*--

How about that. It's pretty simple, but is it really error-correcting? Let's check with a mathematical formula. The input state is $ \ ket {\ psi} = a \ ket {0} + b \ ket {1} $. It is clear that the state will be $ a \ ket {000} + b \ ket {111} $ at the stage of encoding, so let's see the change immediately after that.

If there are no qubits to invert

\begin{align}
a\ket{000} + b\ket{111} &\rightarrow a\ket{000} + b\ket{110} \rightarrow a\ket{000} + b\ket{100} \rightarrow a\ket{000} + b\ket{100} \\
&= (a\ket{0} + b\ket{1}) \otimes \ket{00}  \tag{3}
\end{align}

If the first qubit is inverted due to noise

\begin{align}
a\ket{100} + b\ket{011} &\rightarrow a\ket{101} + b\ket{011} \rightarrow a\ket{111} + b\ket{011} \rightarrow a\ket{011} + b\ket{111} \\
&= (a\ket{0} + b\ket{1}) \otimes \ket{11}  \tag{4}
\end{align}

If the second qubit is inverted due to noise

\begin{align}
a\ket{010} + b\ket{101} &\rightarrow a\ket{010} + b\ket{100} \rightarrow a\ket{010} + b\ket{110} \rightarrow a\ket{010} + b\ket{110} \\
&= (a\ket{0} + b\ket{1}) \otimes \ket{10}  \tag{5}
\end{align}

If the third qubit is inverted due to noise

\begin{align}
a\ket{001} + b\ket{110} &\rightarrow a\ket{001} + b\ket{111} \rightarrow a\ket{001} + b\ket{101} \rightarrow a\ket{001} + b\ket{101} \\
&= (a\ket{0} + b\ket{1}) \otimes \ket{01}  \tag{6}
\end{align}

So the 2nd and 3rd qubits don't necessarily revert to $ \ ket {00} $, but at least the 1st qubit is $ \ ket {\ psi} = a \ ket {in all patterns. It has returned to 0} + b \ ket {1} $ and is not entangled with other qubits (= in a product state).

3 qubit phase inversion code

Next, we will discuss error correction when one qubit has phase inversion. Bit inversion can be represented by the X gate, but phase inversion is the action of the Z gate. In other words, the change is $ a \ ket {0} + b \ ket {1} \ rightarrow a \ ket {0} -b \ ket {1} $. I want to recover from this condition, what should I do? Actually, there is a simple prescription. All you have to do is to use the Hadamard Gate. The action of the Hadamard gate is

\begin{align}
\ket{0} &\rightarrow \ket{+} = \frac{1}{2} (\ket{0} + \ket{1})  \\
\ket{1} &\rightarrow \ket{-} = \frac{1}{2} (\ket{0} - \ket{1})  \tag{7}
\end{align}

So, the phase inversion of $ a \ ket {0} + b \ ket {1} \ rightarrow a \ ket {0} -b \ ket {1} $ is

\begin{align}
& \frac{1}{2} (a+b) \ket{+} \frac{1}{2} (a-b) \ket{-} \\
& \rightarrow \frac{1}{2} (a+b) \ket{-} \frac{1}{2} (a-b) \ket{+}  \tag{8}
\end{align}

Is expressed as. In other words, phase inversion is nothing but bit inversion at the basis of $ \ {\ ket {+}, \ ket {-} \} $. Therefore, in the bit inverting circuit mentioned earlier, Hadamard is applied after coding, then it is put into the noise channel, and Hadamard is applied immediately before decoding to restore it.

|psi> --*--*--H-- ... --H--*--*--X-- |psi>
        |  |               |  |  |
  |0> --X-----H-- ... --H-----X--*--
           |               |     |
  |0> -----X--H-- ... --H--X-----*--

This completes the error correction for phase inversion.

Shor's algorithm

"Shor's code" realizes error correction of bit inversion and phase inversion at the same time. In phase inversion error correction, 1 qubit in the initial state is made redundant to 3 qubits, and Hadamard is applied to each. Since bit inversion error correction is also performed for each qubit, each is made redundant to 3 qubits. As a result, a total of 9 qubits are needed. In the circuit diagram,

|psi> --*--*--H----*--*-- ... --*--*--X--H--*--*--X---- |psi>
        |  |       |  |         |  |  |     |  |  |
        |  | |0> --X----- ... -----X--*--   |  |  |
        |  |       |  |         |     |     |  |  |
        |  | |0> -----X-- ... --X-----*--   |  |  |
        |  |                                |  |  |
  |0> --X-----H----*--*-- ... --*--*--X--H-----X--*--
           |       |  |         |  |  |     |     |
           | |0> --X----- ... -----X--*--   |     |
           |          |         |     |     |     |
           | |0> -----X-- ... --X-----*--   |     |
           |                                |     |
  |0> -----X--H----*--*-- ... --*--*--X--H--X-----*--
                   |  |         |  |  |
             |0> --X----- ... -----X--*--
                      |         |     |
             |0> -----X-- ... --X-----*--

It will be. This allows us to recover the original state against bit inversion and phase inversion errors (of course, we are now assuming that only one of the qubits will be inverted by noise. is). However, in fact, the Shor's code constructed in this way has an even stronger effect. Not only easy-to-understand discrete errors such as bit inversion and phase inversion, but also arbitrary continuous changes (errors) can be corrected properly.

For example, suppose the encoded state is $ \ ket {\ psi} $. If only this first qubit receives the noise described by the Kraus operator $ \ {E_ {i} \} $, the change is:

\ket{\psi}\bra{\psi} \rightarrow \sum_{i} E_{i} \ket{\psi}\bra{\psi} E_{i}^{\dagger}  \tag{9}

You can write like this. Here, $ E_i $ uses Pauli operators $ X_1, Z_1 $ and complex coefficients $ \ {e_ {ij} \} $ that work on the first qubit,

E_i = e_{i0} I + e_{i1} X_1 + e_{i2} Z_1 + e_{i3} X_1 Z_1  \tag{10}

Can be expanded with [^ 5].

[^ 5]: Here, $ X_1 Z_1 $ is equal to $ Y_1 $ excluding the coefficients, so $ E_i $ can be expanded using the Pauli operator. This expansion is possible for any 2D matrix.

Focusing only on one $ i $ term in equation (9), the quantum states are $ \ ket {\ psi}, X_ {1} \ ket {\ psi}, Z_ {1} \ ket {\ psi}. It means that it changes to the superposition state of, X_ {1} Z_ {1} \ ket {\ psi} $. That is, the state $ \ ket {\ psi} $ itself, the bit inversion of the state $ \ ket {\ psi} $, the phase inversion of the state $ \ ket {\ psi} $, the bit of the state $ \ ket {\ psi} $ -It is a superposition of four states called phase inversion. A syndrome diagnosis can be applied to this to determine which of the four was. Once found, the next step is to restore the quantum state by passing through the gate according to the error pattern. Equation (9) is the sum of all $ i $, but the same argument allows error correction for other $ i $, and the same argument for qubit numbers other than the first. Allows error correction.

simulation

Implementation

Now, let's simulate the circuit diagram of error correction by the Shor code. Here is the entire Python code.

import random
from qlazypy import DensOp

def create_densop():

    de_ini = DensOp(qubit_num=9).h(0)
    de_fin = de_ini.clone()
    return de_ini, de_fin
    
def noise(self, kind='', prob=0.0, qid=[]):

    qchannel = {'bit_flip':self.bit_flip,
                'phase_flip':self.phase_flip,
                'bit_phase_flip':self.bit_phase_flip,
                'depolarize':self.depolarize,
                'amp_dump':self.amp_dump,
                'phase_dump':self.phase_dump}
    [qchannel[kind](i,prob=prob) for i in qid]
    return self

def code(self):

    self.cx(0,3).cx(0,6)
    self.h(0).h(3).h(6)
    self.cx(0,1).cx(0,2)
    self.cx(3,4).cx(3,5)
    self.cx(6,7).cx(6,8)
    return self
    
def correct(self):

    self.cx(0,2).cx(0,1)
    self.cx(3,5).cx(3,4)
    self.cx(6,8).cx(6,7)
    self.ccx(2,1,0).ccx(5,4,3).ccx(8,7,6)
    self.h(0).h(3).h(6)
    self.cx(0,3).cx(0,6)
    self.ccx(6,3,0)
    return self

if __name__ == '__main__':

    # add custom gate
    DensOp.add_method(code)
    DensOp.add_method(noise)
    DensOp.add_method(correct)

    # settings
    kind = 'depolarize' # bit_flip,phase_flip,bit_phase_flip,depolarize,amp_dump,phase_dump
    prob = 1.0
    qid = [0]
    print("== settings ==")
    print("* kind of noise        =", kind)
    print("* probability of noise =", prob)
    print("* noisy channels       =", qid)

    # error correction (shor code)
    de_ini, de_fin = create_densop()
    de_fin.code()
    de_fin.noise(kind=kind, prob=prob, qid=qid)
    de_fin.correct()

    # evaluate fidelity
    fid = de_fin.fidelity(de_ini, qid=[0])
    print("== result ==")
    print("* fidelity = {:.6f}".format(fid))

    # free all densops
    DensOp.free_all(de_ini, de_fin)

I will explain what you are doing in order. First, look at the main processing section.

# add custom gate
DensOp.add_method(code)
DensOp.add_method(noise)
DensOp.add_method(correct)

Now, register the required processing as a custom gate. The functions code, noise, and correct are defined at the top so that they can be used as methods of the QState class.

# settings
kind = 'depolarize' # bit_flip,phase_flip,bit_phase_flip,depolarize,amp_dump,phase_dump
prob = 1.0
qid = [0]

The parameters for the simulation are set in. kind represents the noise pattern you want to apply. In'bit_flip'(bit inversion),'phase_flip' (phase inversion),'bit_phase_flip' (bit phase inversion),'depolarize' (depolarization),'amp_dump' (amplitude damping),'phase_dump' (phase damping) Select the pattern name you want to apply from. The typical quantum channels described in the previous article (https://qiita.com/SamN/items/9d86224a35c4b6c031b8) can be applied to the density operator (quantum channel application to the density operator is v0.0.34). Added). prob represents the probability (intensity) of adding noise in each quantum channel. qid is a list that sets which qubit to apply noise to. In the above example, it is applied to the 0th qubit. You can also specify multiple bit numbers.

de_ini, de_fin = create_densop()

Then, create a quantum state (density operator) appropriately. As you can see from the function definition, a total of 9 qubits are initialized to $ \ ket {0} $, and only the 0th qubit is Hadamard gated. It doesn't have to be Hadamard, but it's appropriate here. You can change it appropriately according to what kind of input state you expect. Also, here, two exactly the same quantum states (density operators), de_ini and de_fin, are output, but after that, only de_fin is processed, and finally it is compared with the original state de_ini. I am trying to output one.

de_fin.code()

Then, encode it. If you look at the function definition, it will be obvious. The quantum circuit up to just before the noise enters is implemented honestly.

de_fin.noise(kind=kind, qid=qid, prob=prob)

Then, the quantum channel defined by kind is applied to the quantum number defined by qid with the intensity of probability prob. The contents of the function definition may be confusing at first glance, but in reality, it just performs the operation de_ini.depolarize (0, prob = 1.0). In the quantum circuit diagram, it corresponds to the dotted parts.

dde_fin.correct()

So, we will do error correction and decryption together. As you can see by looking at the function definition (again, it's just a straightforward implementation).

fid = de_fin.fidelity(de_ini, qid=[0])
print("== result ==")
print("* fidelity = {:.6f}".format(fid))

So, in order to compare the initial state with the state after error correction, the fidelity for the 0th qubit is calculated and displayed.

DensOp.free_all(de_ini, de_fin)

Finally, free the used memory. You can release the argument specified by the class method free_all at once (added in v0.0.33).

Now, for the 0th qubit, error correction simulation can be performed when depolarization is performed with a probability of 1 (that is, noise is added that completely displaces the direction).

Execution result

The execution result is shown.

== settings ==
* kind of noise        = depolarize
* probability of noise = 1.0
* noisy channels       = [0]
== result ==
* fidelity = 1.000000

So, for the noise of 1 qubit, we were able to completely correct the error.

In addition, error correction was possible even for quantum channels other than polarization elimination, and it was okay for any qubit to contain noise. The following is an example.

== settings ==
* kind of noise        = amp_dump
* probability of noise = 1.0
* noisy channels       = [5]
== result ==
* fidelity = 1.000000

However, it didn't work when there were two or more noise channels. It is as follows.

== settings ==
* kind of noise        = depolarize
* probability of noise = 1.0
* noisy channels       = [0, 2]
== result ==
* fidelity = 0.866025

How about setting the probability to 0.5?

== settings ==
* kind of noise        = depolarize
* probability of noise = 0.5
* noisy channels       = [0, 2]
== result ==
* fidelity = 0.968246

This was also useless. As explained above, only one qubit error can be completely error-corrected with Shor's code. I understand that.

in conclusion

This time, I took up and explained "Shor's code", which is the simplest and most accessible method among various proposed methods for quantum error correction. It is interesting that I should have made an error correction circuit that supports bit inversion and phase inversion, but for some reason it was a circuit that can handle all continuous errors. I think that it is effective that continuous operations on quantum states can actually be expressed by superposition of discrete Pauli operators.

So, it was an introduction to the basics of quantum error correction. For the time being, I plan to continue to understand the basics while enjoying the various aspects of quantum error correction.

that's all

Recommended Posts

Basics of Quantum Information Theory: Quantum Error Correction (Shor's Code)
Basics of Quantum Information Theory: Quantum Error Correction (CSS Code)
Basics of Quantum Information Theory: Quantum Error Correction (Stabilizer Code: 4)
Basics of Quantum Information Theory: Quantum Error Correction (Classical Linear Code)
Basics of Quantum Information Theory: Topological Toric Code
Basics of Quantum Information Theory: Entropy (2)
Basics of Quantum Information Theory: Universal Quantum Calculation by Toric Code (1)
Basics of Quantum Information Theory: Horebaud Limits
Basics of Quantum Information Theory: Trace Distance
Basics of Quantum Information Theory: Quantum State Tomography
Basics of Quantum Information Theory: Data Compression (2)
Basics of Quantum Information Theory: Logical Operation by Toric Code (Brading)
Basics of Quantum Information Theory: Fault Tolerant Quantum Computation
Read "Basics of Quantum Annealing" Day 5
Read "Basics of Quantum Annealing" Day 6
Basics of Tableau Basics (Visualization Using Geographic Information)