-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nzy
committed
Feb 26, 2024
1 parent
782788b
commit eadd2cd
Showing
7 changed files
with
79 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
using TensorQEC, TensorQEC.Yao | ||
using TensorInference | ||
qc=chain(cnot(2, 1, 2)) | ||
cl=clifford_network(qc) | ||
ps = Dict([1=>TensorQEC.BoundarySpec((0.0,1.0,0.0,0.0), false),2=>TensorQEC.BoundarySpec((1.0,0.0,0.0,0.0), false)]) | ||
qs = Dict([i=>TensorQEC.BoundarySpec((ones(Float64,4)...,), true) for i in 1:2]) | ||
tn=generate_tensor_network(cl,ps, qs) | ||
# using Distributions | ||
|
||
marginals(tn) | ||
# function random_pauli_string(N::Int,p::Vector) | ||
# values = [1, 2, 3, 4] # 1: I, 2: X, 3: Y, 4: Z | ||
# return PauliString(([values[rand(Categorical(p[i]))] for i in 1:N]...,)) | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
function correction_pauli_string(qubit_num::Int, syn::Dict{Int,Bool}, prob::Dict{Int,Vector{Float64}}) | ||
ps = ones(Int, qubit_num) | ||
for (k, v) in prob | ||
@show syn[k] | ||
if syn[k] #syn[k] is true, measure outcome is -1, use X or Y | ||
ps[k] = (findmax(v)[2]) == 1 ? 2 : 3 | ||
elseif findmax(v)[2] == 2 | ||
ps[k] = 4 | ||
end | ||
end | ||
return PauliString(ps[1:end]...) | ||
function correction_pauli_string(qubit_num::Int, syn::Dict{Int, Bool}, prob::Dict{Int, Vector{Float64}}) | ||
ps = ones(Int, qubit_num) | ||
for (k, v) in prob | ||
if k ∈ keys(syn) | ||
if syn[k] #syn[k] is true, measure outcome is -1, use X or Y | ||
ps[k] = (findmax(v)[2]) == 1 ? 2 : 3 | ||
elseif findmax(v)[2] == 2 | ||
ps[k] = 4 | ||
end | ||
else | ||
ps[k] = [1,2,3,4][findmax(v)[2]] | ||
end | ||
end | ||
return PauliString(ps[1:end]...) | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Test, TensorQEC, TensorQEC.Yao | ||
|
||
|
||
# simple example: Z1Z3 Z2Z3 stabilizers on 3 qubits | ||
@testset "simple example inference and error correct" begin | ||
qubit_num = 3 | ||
st = [PauliString((1,4,4)),PauliString((4,1,4))] | ||
qc, data_qubits, code = TensorQEC.encode_stabilizers(st) | ||
|
||
reg = join(rand_state(1), zero_state(2)) # join(qubit3, qubit2, qubit1) | ||
regcopy = copy(reg) | ||
apply!(reg, qc) | ||
apply!(reg, put(qubit_num, 3=>X)) | ||
|
||
measure_outcome=measure_syndrome!(reg, st) | ||
syn_dict=TensorQEC.generate_syndrome_dict(code,syndrome_transform(code, measure_outcome)) | ||
|
||
cl = clifford_network(qc) | ||
p = fill([0.85,0.05,0.05,0.05],qubit_num) | ||
pinf = syndrome_inference(cl, syn_dict, p) | ||
ps_ec_phy = TensorQEC.pauli_string_map_iter(correction_pauli_string(qubit_num, syn_dict, pinf), qc) | ||
apply!(reg, Yao.YaoBlocks.Optimise.to_basictypes(ps_ec_phy)) | ||
|
||
@test measure_syndrome!(reg, st) == [1,1] | ||
apply!(reg, qc') | ||
@test fidelity(density_matrix(reg, [data_qubits...]), density_matrix(regcopy, [data_qubits...])) ≈ 1.0 | ||
end | ||
|
||
@testset "syndrome inference and error correct for SurfaceCode3" begin | ||
qubit_num = 9 | ||
st = stabilizers(SurfaceCode{3}()) | ||
qc, data_qubits, code = TensorQEC.encode_stabilizers(st) | ||
|
||
reg = join(zero_state(8),rand_state(1)) | ||
regcopy = copy(reg) | ||
apply!(reg, qc) | ||
apply!(reg, put(9, 3=>Z)) | ||
apply!(reg, put(9, 2=>X)) | ||
|
||
measure_outcome=measure_syndrome!(reg, st) | ||
syn_dict=TensorQEC.generate_syndrome_dict(code,syndrome_transform(code, measure_outcome)) | ||
|
||
cl = clifford_network(qc) | ||
p = fill([0.85,0.05,0.05,0.05],qubit_num) | ||
pinf = syndrome_inference(cl, syn_dict, p) | ||
ps_ec_phy = TensorQEC.pauli_string_map_iter(correction_pauli_string(qubit_num, syn_dict, pinf), qc) | ||
apply!(reg, Yao.YaoBlocks.Optimise.to_basictypes(ps_ec_phy)) | ||
|
||
@test measure_syndrome!(reg, st) == [1,1,1,1,1,1,1,1] | ||
apply!(reg, qc') | ||
@test fidelity(density_matrix(reg, [9]),density_matrix(regcopy, [9])) ≈ 1.0 | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters