Skip to content

Commit

Permalink
Predefined useful states.
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Krastanov <stefan@krastanov.org>
  • Loading branch information
Krastanov committed Jun 17, 2021
1 parent 203bd4c commit 5e0b1df
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/QuantumClifford.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export @P_str, PauliOperator, ⊗, I, X, Y, Z, permute,
apply_single_z!, apply_single_x!, apply_single_y!,
random_invertible_gf2,
random_pauli, random_stabilizer, random_destabilizer, random_clifford, random_singlequbitop,
bell, ghz,
BadDataStructure

# Predefined constants representing the permitted phases encoded
Expand Down Expand Up @@ -339,6 +340,10 @@ function apply!(s::AbstractStabilizer, p::AbstractCliffordOperator, indices; pha
s
end

function (ops::AbstractStabilizer...)
foldl(, ops[2:end], init=ops[1])
end

##############################
# Destabilizer formalism
##############################
Expand Down Expand Up @@ -1135,7 +1140,7 @@ function apply!(s::Stabilizer, p::PauliOperator, indices; phases::Bool=true)
s
end

function tensor_pow(op::AbstractCliffordOperator,power::Integer)
function tensor_pow(op,power::Integer) # TODO optimize (recursively) for large power
(repeat([op],power)...)
end

Expand Down Expand Up @@ -1900,6 +1905,7 @@ RecipesBase.@recipe function f(s::Stabilizer; xzcomponents=:split)
end

include("./randoms.jl")
include("./useful_states.jl")
include("./experimental/Experimental.jl")

end #module
98 changes: 98 additions & 0 deletions src/useful_states.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""Prepare one or more Bell pairs (with optional phases).
```jldoctest
julia> bell()
+ XX
+ ZZ
julia> bell(2)
+ XX__
+ ZZ__
+ __XX
+ __ZZ
julia> bell((true, false))
- XX
+ ZZ
julia> bell([true, false, true, true])
- XX__
+ ZZ__
- __XX
- __ZZ
```
"""
function bell end

function bell()
copy(S"XX
ZZ")
end

function bell(n::Integer)
tensor_pow(bell(), n)
end

function bell(phase::Tuple{Bool, Bool})
s = bell()
s.phases[1] = phase[1] ? 0x2 : 0x0
s.phases[2] = phase[2] ? 0x2 : 0x0
s
end

function bell(phases::AbstractVector{Tuple{Bool, Bool}})
((bell(t) for t in phases)...)
end

function bell(phases::AbstractVector{Bool})
s = bell(length(phases)÷2)
for i in 1:length(s)
phases[i]
s.phases[i] = phases[i] ? 0x2 : 0x0
s[i], s.phases[i]
end
s
end

"""
Prepare a GHZ state of n qubits.
```jldoctest
julia> ghz()
+ XXX
+ ZZ_
+ _ZZ
julia> ghz(2)
+ XX
+ ZZ
julia> ghz(4)
+ XXXX
+ ZZ__
+ _ZZ_
+ __ZZ
```
"""
function ghz end

function ghz()
copy(S"XXX
ZZI
IZZ")
end

function ghz(n::Integer)
s = zero(Stabilizer, n)
for i in 1:n
s[1,i] = (true,false)
end
for i in 2:n
s[i,i] = (false,true)
s[i,i-1] = (false,true)
end
s
end

# TODO document these explicitly
# TODO cluster states, toric code, planar code, other codes from python libraries

2 comments on commit 5e0b1df

@Krastanov
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/39080

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.9 -m "<description of version>" 5e0b1dfba879aa63a6aeeac155ab0be142309346
git push origin v0.2.9

Please sign in to comment.