Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests and Bug fixes #2

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PauliOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include("function_base.jl")
include("function_convert.jl")
include("function_commute.jl")
include("function_otimes.jl")

include("function_osum.jl")

# Exports
export Pauli
Expand Down
8 changes: 4 additions & 4 deletions src/function_mul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
Multiply two `Pauli`'s together
"""
function Base.:*(p1::Pauli{N}, p2::Pauli{N}) where {N}
θ = (p1.θ + p2.θ + phase(p1.pauli) + phase(p2.pauli) + phase(p1.pauli, p2.pauli)) % 4
θ = (p1.θ + p2.θ + phase(p1.pauli, p2.pauli)) % 4
return Pauli{N}(θ, p1.pauli*p2.pauli)
end

Expand All @@ -215,7 +215,7 @@
# θ = (p1.θ + phase(p2)) % 4
# θ += (2*count_ones(p1.x & p2.z)) % 4
# return Pauli{N}(θ, z, x)
θ = (p1.θ + phase(p1.pauli) + phase(p2) + phase(p1.pauli, p2)) % 4
θ = (p1.θ + phase(p1.pauli, p2)) % 4

Check warning on line 218 in src/function_mul.jl

View check run for this annotation

Codecov / codecov/patch

src/function_mul.jl#L218

Added line #L218 was not covered by tests
return Pauli{N}(θ, p1.pauli*p2)
end

Expand All @@ -225,7 +225,7 @@
# θ = (phase(p1) + p2.θ) % 4
# θ += (2*count_ones(p1.x & p2.z)) % 4
# return Pauli{N}(θ, z, x)
θ = (p2.θ + phase(p1) + phase(p2.pauli) + phase(p1, p2.pauli)) % 4
θ = (p2.θ + phase(p1, p2.pauli)) % 4

Check warning on line 228 in src/function_mul.jl

View check run for this annotation

Codecov / codecov/patch

src/function_mul.jl#L228

Added line #L228 was not covered by tests
return Pauli{N}(θ,p1*p2.pauli)
end

Expand Down Expand Up @@ -277,4 +277,4 @@
tmp = p.pauli.x ⊻ ψ.v
sign = count_ones(p.pauli.z & tmp) % 2
return p.coeff*(-1)^sign, KetBitString{N}(tmp)
end
end
6 changes: 3 additions & 3 deletions src/function_otimes.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
otimes(p1::Pauli{N}, p2::Pauli{M}) where {N,M} = Pauli{N+M}((p1.θ + p2.θ)%4, p1.pauli ⊗ p2.pauli)
otimes(p1::FixedPhasePauli{N}, p2::FixedPhasePauli{M}) where {N,M} = FixedPhasePauli{N+M}(p1.z | p2.z << N, p1.x | p2.x << N)
otimes(p::Pauli{N}, fpp::FixedPhasePauli{M}) where {N,M} = otimes(p, Pauli{M}(0,fpp.z, fpp.x))
otimes(fpp::FixedPhasePauli{M}, p::Pauli{N}) where {N,M} = otimes(Pauli{M}(0,fpp.z, fpp.x), p)
otimes(p::Pauli{N}, fpp::FixedPhasePauli{M}) where {N,M} = otimes(p, Pauli{M}(0,fpp))
otimes(fpp::FixedPhasePauli{M}, p::Pauli{N}) where {N,M} = otimes(Pauli{M}(0,fpp), p)

Check warning on line 4 in src/function_otimes.jl

View check run for this annotation

Codecov / codecov/patch

src/function_otimes.jl#L3-L4

Added lines #L3 - L4 were not covered by tests

function otimes(ps::PauliSum{N}, p::Pauli{M}) where {N,M}
out = PauliSum(N+M)
Expand All @@ -27,4 +27,4 @@
end
return out
end
const ⊗ = otimes
const ⊗ = otimes
4 changes: 2 additions & 2 deletions src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
Check if operator is diagonal in the computational (z) basis. E.g., does this operator consist of only I and/or Z?
"""
function is_diagonal(p::Pauli)
return count_ones(p.x) == 0
return count_ones(p.pauli.x) == 0

Check warning on line 141 in src/operations.jl

View check run for this annotation

Codecov / codecov/patch

src/operations.jl#L141

Added line #L141 was not covered by tests
end


Expand All @@ -158,6 +158,6 @@

println(p)

count_ones(p.z & ket.v) % 2 == 0 || return -(1im)^p.θ
count_ones(p.pauli.z & ket.v) % 2 == 0 || return -(1im)^p.θ

Check warning on line 161 in src/operations.jl

View check run for this annotation

Codecov / codecov/patch

src/operations.jl#L161

Added line #L161 was not covered by tests
return (1im)^p.θ
end
22 changes: 17 additions & 5 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ using Random


println("Test Multiply")
for i in 1:10
N = 8
a = random_Pauli(N)
b = random_Pauli(N)

display(a * b)
# println()
# display(s2)

@test all(Matrix(a) * Matrix(b) - Matrix(a * b) .≈ 0)
end


println("Test Addition")
for i in 1:10
N = 8
a = random_Pauli(N)
Expand All @@ -100,14 +114,12 @@ using Random

s1 = a + b + d
s2 = a + c + d
display(s1 * s2)
# println()
# display(s2)

@test all(Matrix(s1) * Matrix(s2) - Matrix(s1 * s2) .≈ 0)
@test all(Matrix(s1) + Matrix(s2) - Matrix(s1 + s2) .≈ 0)
end



a = random_Pauli(6)
b = random_Pauli(6)
s = a + b
Expand Down
Loading