Skip to content

Commit

Permalink
fix: QEC decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
aydindeger committed Jun 22, 2024
1 parent 33bbe77 commit 5c3a367
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/func.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ Calculate the expectation value for quantum states or density matrices given an
- The expectation value as a `Float64` or a vector of `Float64` for multiple qubits.
"""
expect(state::AbstractVectorS,op::QuantumOps)=real(state'*op.expand(get_N(state))*state)
expect(rho::sa.SparseMatrixCSC,op::QuantumOps)=real(la.tr(rho*op.expand(get_N(rho))))
expect(rho::AbstractMatrixS,op::QuantumOps)=real(la.tr(rho*op.expand(get_N(rho))))

# expect(state::AbstractVectorS,op_str::String,qubit::Int)=real(state'*expand_multi_op(op_str,[qubit],get_N(state))*state)
# expect(rho::sa.SparseMatrixCSC,op_str::String,qubit::Int)=real(la.tr(rho*expand_multi_op(op_str,[qubit],get_N(rho))))

expect(state::AbstractVectorS,op_str::String)=[real(state'*expand_multi_op(op_str,[qubit],get_N(state))*state) for qubit=1:get_N(state)]
expect(rho::sa.SparseMatrixCSC,op_str::String)=[real(la.tr(rho*expand_multi_op(op_str,[qubit],get_N(rho)))) for qubit=1:get_N(rho)]
expect(rho::AbstractMatrixS,op_str::String)=[real(la.tr(rho*expand_multi_op(op_str,[qubit],get_N(rho)))) for qubit=1:get_N(rho)]

expect(state::AbstractVectorS,matrix::sa.SparseMatrixCSC)=real(state'*matrix*state)
expect(rho::sa.SparseMatrixCSC,matrix::sa.SparseMatrixCSC)=real(la.tr(rho*matrix))
expect(state::AbstractVectorS,matrix::AbstractMatrixS)=real(state'*matrix*state)
expect(rho::AbstractMatrixS,matrix::AbstractMatrixS)=real(la.tr(rho*matrix))

"""
Alias:
Expand Down Expand Up @@ -141,7 +141,7 @@ function correlation(state::AbstractVectorS,list_of_operators::String,qubits_app
return real(state'*matrix*state)
end

function correlation(rho::sa.SparseMatrixCSC,list_of_operators::String,qubits_applied::Vector)
function correlation(rho::AbstractMatrixS,list_of_operators::String,qubits_applied::Vector)
matrix=expand_multi_op(list_of_operators,qubits_applied,get_N(rho))
return real(la.tr(rho*matrix))
end
Expand Down
1 change: 1 addition & 0 deletions src/gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const gate = (
T = [1. 0; 0 exp(im * π / 4)],
HSp = (1/sqrt(2)) * [1.0+0im 0-1im;1+0im 0+1im],
HY = (1/sqrt(2)) * [1 -1im;1im -1.0],
H2 = [0.5 0.5 0.5 0.5;0.5 -0.5 0.5 -0.5;0.5 0.5 -0.5 -0.5;0.5 -0.5 -0.5 0.5],
# HS = (1/sqrt(2)) * [1.0 1;1im -1im],
P0=[1.0 0; 0 0], #|0><0> #projector
P1=[0 0; 0 1.0], #|1><1> #projector #n
Expand Down
4 changes: 2 additions & 2 deletions src/ops.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
get_N(state::AbstractVectorS) -> Int
get_N(rho::sa.SparseMatrixCSC) -> Int
get_N(rho::AbstractMatrixS) -> Int
"""
get_N(state::AbstractVectorS)=Int(log(2,length(state)))
get_N(rho::sa.SparseMatrixCSC)=Int(log(2,size(rho,1)))
get_N(rho::AbstractMatrixS)=Int(log(2,size(rho,1)))

get_M(state::it.MPS)=it.siteinds(state)
get_N(psi::it.MPS)=length(get_M(psi))
Expand Down
7 changes: 6 additions & 1 deletion src/qec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,12 @@ struct StabilizerCode #alpha version
state_partial=partial_trace(state,collect(n-k+1:n))
e,v=la.eigen(state_partial)

return sa.sparse(v[:,findfirst(isapprox(1), e)])
e_pos=findfirst(isapprox(1), e)
if isa(e_pos,Number)
return sa.sparse(v[:,e_pos])
else
return state_partial
end

end

Expand Down

0 comments on commit 5c3a367

Please sign in to comment.