Inference with Tensor Network
This example demonstrates how to define stabilizers, encode data qubits measure syndromes, and use tensor network to infer the most likely error[Ferris].
We take the $3\times 3$ surface code as an example, and use Yao.jl to verify the error correction circuit.
Definition of Stabilizers
using TensorQEC, TensorQEC.Yao
surface_stabilizers = stabilizers(SurfaceCode(3,3))
8-element Vector{PauliString{9}}:
XXIXXIIII
IIIIXXIXX
IIXIIXIII
IIIXIIXII
IZZIZZIII
IIIZZIZZI
ZZIIIIIII
IIIIIIIZZ
Then we can generate the encoding circuits of the stabilizers by encode_stabilizers
.
encoder, data_qubits, bimatrix = encode_stabilizers(surface_stabilizers)
vizcircuit(encoder)
where encoder
is the encoding circuit, data_qubits
are the qubits that we should put initial qubtis in, and bimatrix
is a CSSBimatrix
instance that records information of the encoding circuit. For more details on Bimatrix
, please check [Gottesman].
The process of obtaining the encoding circuit requires adjusting the generators of the stabilizer group. The new generators are
TensorQEC.bimatrix2stabilizers(bimatrix)
8-element Vector{PauliString{9}}:
XXIIIXXXX
IIIIXXIXX
IIXIIXIII
IIIXIIXII
ZZIIIIIII
IIIZZIZIZ
ZIZIZZIII
IIIIIIIZZ
Circuit Simulation with Yao.jl
Create a random qubit state to be encoded.
data = rand_state(1)
ArrayReg{2, ComplexF64, Array...}
active qubits: 1/1
nlevel: 2
We use place_qubits
to create a quantum register. data_qubits
records the position of data qubits, and the rest ancilla qubits are in the $|0\rangle$ state.
logic_state = place_qubits(data, data_qubits, nqubits(encoder))
ArrayReg{2, ComplexF64, Array...}
active qubits: 9/9
nlevel: 2
Apply the encoding circuits.
apply!(logic_state, encoder)
ArrayReg{2, ComplexF64, Array...}
active qubits: 9/9
nlevel: 2
Apply an X error on the third qubit.
apply!(logic_state, put(9, 3 => X))
ArrayReg{2, ComplexF64, Array...}
active qubits: 9/9
nlevel: 2
Measure the Syndrome and Inference the Error Probability
We first measure the stabilizers to get the error syndrome by measure_syndrome!
. 1 means the stabilizer is not violated, and -1 means the stabilizer is violated. Though the stabilizers are not the same as the initial stabilizers, we can't directly measure the current stabilizers to get the syndrome. The reason is that there may be some long range term in the current stabilizers, which can' be measrued physically. So we still measure the initial stabilizers to get the syndrome.
measure_outcome = measure_syndrome!(logic_state, surface_stabilizers)
8-element Vector{Int64}:
1
1
1
1
-1
1
1
1
Then we transform the syndrome in the current stabilizers by transformed_syndrome_dict
. The syndrome is transformed to 0 if the measurement outcome is 1, and 1 if the measurement outcome is -1.
syn_dict = transformed_syndrome_dict(measure_outcome, bimatrix)
Dict{Int64, Bool} with 8 entries:
5 => 0
4 => 0
6 => 1
7 => 0
2 => 0
8 => 0
3 => 0
1 => 0
Now we generate the tensor network for syndrome inference by clifford_network
.
tensor_network = clifford_network(encoder)
CliffordNetwork{Float64}(TensorInference.Factor{Float64}[TensorInference.Factor{Float64, 2}((10, 1), [0.9999999999999998 0.0 0.0 0.0; 0.0 0.0 0.0 0.9999999999999998; 0.0 0.0 -0.9999999999999998 0.0; 0.0 0.9999999999999998 0.0 0.0]), TensorInference.Factor{Float64, 2}((11, 5), [0.9999999999999998 0.0 0.0 0.0; 0.0 0.0 0.0 0.9999999999999998; 0.0 0.0 -0.9999999999999998 0.0; 0.0 0.9999999999999998 0.0 0.0]), TensorInference.Factor{Float64, 2}((12, 3), [0.9999999999999998 0.0 0.0 0.0; 0.0 0.0 0.0 0.9999999999999998; 0.0 0.0 -0.9999999999999998 0.0; 0.0 0.9999999999999998 0.0 0.0]), TensorInference.Factor{Float64, 2}((13, 4), [0.9999999999999998 0.0 0.0 0.0; 0.0 0.0 0.0 0.9999999999999998; 0.0 0.0 -0.9999999999999998 0.0; 0.0 0.9999999999999998 0.0 0.0]), TensorInference.Factor{Float64, 4}((14, 15, 9, 7), [1.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0;;; 0.0 0.0 0.0 0.0; 0.0 1.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0;;; 0.0 0.0 0.0 0.0; 0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0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0;;;; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 1.0;;; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 -1.0 0.0; 0.0 0.0 0.0 0.0;;; 0.0 0.0 0.0 0.0; 0.0 0.0 1.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0;;; 0.0 0.0 0.0 1.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0])], [26, 19, 34, 36, 32, 35, 37, 31, 33], [1, 2, 3, 4, 5, 6, 7, 8, 9], 37)
Define the prior error probability of each physical qubit. Here we assume the error probability of each qubit is the same. There are probability of 85% that the qubits are correct, and 5% that there is an X error, Y error, or Z error respectively.
prior = fill([0.85, 0.05, 0.05, 0.05], 9)
9-element Vector{Vector{Float64}}:
[0.85, 0.05, 0.05, 0.05]
[0.85, 0.05, 0.05, 0.05]
[0.85, 0.05, 0.05, 0.05]
[0.85, 0.05, 0.05, 0.05]
[0.85, 0.05, 0.05, 0.05]
[0.85, 0.05, 0.05, 0.05]
[0.85, 0.05, 0.05, 0.05]
[0.85, 0.05, 0.05, 0.05]
[0.85, 0.05, 0.05, 0.05]
We can use the syndrome_inference
function to infer the error probability.
pinf = syndrome_inference(tensor_network, syn_dict, prior)
Dict{Int64, Vector{Float64}} with 9 entries:
5 => [0.944546, 0.055454]
4 => [0.969398, 0.0306025]
6 => [0.99312, 0.00688033]
7 => [0.999994, -5.56561e-6]
2 => [0.978016, -0.0219838]
9 => [0.936903, 0.0547069, 0.00156424, 0.00682565]
8 => [0.994764, 0.00523646]
3 => [0.527763, 0.472237]
1 => [0.999636, 0.000364208]
Generate the Pauli string for error correction. correction_pauli_string
generates the error Pauli string in the coding space. To correct the error, we still need to transform it to the physical space by clifford_simulate
. The corretion pauli string here is $X_6$. Since there is a stabilizer $X_3X_6$, applying $X_3$ or $X_6$ on the coding space are equivalent.
ps_ec_phy = clifford_simulate(correction_pauli_string(9, syn_dict, pinf), encoder).output
IIIIIXIII
Or we can simply use the inference
function to infer error pauli string in one function.
ps_ec_phy = inference(measure_outcome, bimatrix, encoder, prior)
IIIIIXIII
Error Correction
Apply the error correction.
apply!(logic_state, Yao.YaoBlocks.Optimise.to_basictypes(ps_ec_phy))
ArrayReg{2, ComplexF64, Array...}
active qubits: 9/9
nlevel: 2
Finally, we can measure the stabilizers after error correction to check whether the error is corrected.
measure_syndrome!(logic_state, surface_stabilizers)
8-element Vector{Int64}:
1
1
1
1
1
1
1
1
And we can calculate the fidelity after error correction to check whether the initial state is recovered.
apply!(logic_state, encoder')
fidelity_after = fidelity(density_matrix(logic_state, data_qubits), density_matrix(data))
1.0
This page was generated using Literate.jl.
- FerrisFerris, A. J.; Poulin, D. Tensor Networks and Quantum Error Correction. Phys. Rev. Lett. 2014, 113 (3), 030501. https://doi.org/10.1103/PhysRevLett.113.030501.
- GottesmanGottesman, D. (1997). Stabilizer Codes and Quantum Error Correction (arXiv:quant-ph/9705052). arXiv. http://arxiv.org/abs/quant-ph/9705052