Skip to content

Commit

Permalink
Merge branch 'nmayhall-vt:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ddhawan11 authored Oct 2, 2023
2 parents 8c55872 + ffe3f1a commit 0a37e78
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 44 deletions.
47 changes: 25 additions & 22 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ jobs:
matrix:
version:
- '1.7'
- 'nightly'
- '1.8'
os:
- ubuntu-latest
- macOS-latest
arch:
- x64
#- x86
allow_failures:
- julia_version: 'nightly'

steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
Expand All @@ -39,24 +42,24 @@ jobs:
- uses: codecov/codecov-action@v2
with:
files: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
permissions:
contents: write
statuses: write
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-docdeploy@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
julia --project=docs -e '
using Documenter: DocMeta, doctest
using PauliOperators
DocMeta.setdocmeta!(PauliOperators, :DocTestSetup, :(using PauliOperators); recursive=true)
doctest(PauliOperators)'
# docs:
# name: Documentation
# runs-on: ubuntu-latest
# permissions:
# contents: write
# statuses: write
# steps:
# - uses: actions/checkout@v2
# - uses: julia-actions/setup-julia@v1
# with:
# version: '1'
# - uses: julia-actions/julia-buildpkg@v1
# - uses: julia-actions/julia-docdeploy@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - run: |
# julia --project=docs -e '
# using Documenter: DocMeta, doctest
# using PauliOperators
# DocMeta.setdocmeta!(PauliOperators, :DocTestSetup, :(using PauliOperators); recursive=true)
# doctest(PauliOperators)'
25 changes: 21 additions & 4 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ version = "1.3.2"
deps = ["Arpack", "InteractiveUtils", "LinearAlgebra", "LinearMaps", "Printf", "Random"]
git-tree-sha1 = "181fe1ffc1f9adb45e558be29f9a76d1a4b17757"
repo-rev = "main"
repo-url = "https://github.com/nmayhall-vt/BlockDavidson.jl"
repo-url = "git@github.com:nmayhall-vt/BlockDavidson.jl.git"
uuid = "b4c031f8-e7c9-4879-896c-063a10ff8103"
version = "0.1.0"

Expand Down Expand Up @@ -93,10 +93,10 @@ uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.9.3"

[[deps.Documenter]]
deps = ["ANSIColoredPrinters", "Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
git-tree-sha1 = "39fd748a73dce4c05a9655475e437170d8fb1b67"
deps = ["ANSIColoredPrinters", "AbstractTrees", "Base64", "Dates", "DocStringExtensions", "Downloads", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "MarkdownAST", "Pkg", "PrecompileTools", "REPL", "RegistryInstances", "SHA", "Test", "Unicode"]
git-tree-sha1 = "f1a7eaf2b5ac7a4feb27973a09d25daf80dc56db"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.27.25"
version = "1.0.1"

[[deps.Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
Expand Down Expand Up @@ -153,6 +153,11 @@ git-tree-sha1 = "31e996f0a15c7b280ba9f76636b3ff9e2ae58c9a"
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.4"

[[deps.LazilyInitializedFields]]
git-tree-sha1 = "410fe4739a4b092f2ffe36fcb0dcc3ab12648ce1"
uuid = "0e77f7df-68c5-4e49-93ce-4cd80f5598bf"
version = "1.2.1"

[[deps.LeftChildRightSiblingTrees]]
deps = ["AbstractTrees"]
git-tree-sha1 = "fb6803dafae4a5d62ea5cab204b1e657d9737e7f"
Expand Down Expand Up @@ -195,6 +200,12 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[deps.MarkdownAST]]
deps = ["AbstractTrees", "Markdown"]
git-tree-sha1 = "e8513266815200c0c8f522d6d44ffb5e9b366ae4"
uuid = "d0879d2d-cac2-40c8-9cee-1863dc0c7391"
version = "0.1.1"

[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
Expand Down Expand Up @@ -260,6 +271,12 @@ git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.2.2"

[[deps.RegistryInstances]]
deps = ["LazilyInitializedFields", "Pkg", "TOML", "Tar"]
git-tree-sha1 = "ffd19052caf598b8653b99404058fce14828be51"
uuid = "2792f1a3-b283-48e8-9a74-f99dce5104f3"
version = "0.1.0"

[[deps.Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7"
Expand Down
1 change: 1 addition & 0 deletions src/PauliOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export otimes
export clip!
export
export
export expectation_value

end

2 changes: 1 addition & 1 deletion src/function_add.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Base.:+(p1::ScaledPauli{N}, p2::ScaledPauli{N}) where {T,N}
end
end
function Base.:+(p::ScaledPauli{N}, a::Number) where {T,N}
return p + ScaledPauli{N}(a, Pauli{N}(0,0,0))
return p + ScaledPauli{N}(a, Pauli{N}(0,FixedPhasePauli{N}(0,0)))
end
Base.:+(p::ScaledPauli{N}, a::Pauli{N}) where {T,N} = p + ScaledPauli{N}(1, a)
Base.:+(a::Pauli{N}, p::ScaledPauli{N}) where {T,N} = p + a
Expand Down
21 changes: 16 additions & 5 deletions src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ function negate(p::Pauli{N}) where N
end

"""
is_diagonal(p::Pauli)
is_diagonal(p::FixedPhasePauli)
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.pauli.x) == 0
function is_diagonal(p::FixedPhasePauli)
return count_ones(p.x) == 0
end
is_diagonal(p::Pauli) = is_diagonal(p.pauli)
is_diagonal(p::ScaledPauli) = is_diagonal(p.pauli)



Expand All @@ -153,11 +155,20 @@ end
compute expectation value of Pauli `o` for a product state `ket`
"""
function expectation_value_sign(p::Pauli{N}, ket::KetBitString{N}) where N

function expectation_value(p::FixedPhasePauli{N}, ket::KetBitString{N}) where N
is_diagonal(p) || return 0.0

println(p)
count_ones(p.z & ket.v) % 2 == 0 || return -1
return 1
end

function expectation_value(p::Pauli{N}, ket::KetBitString{N}) where N
is_diagonal(p) || return 0.0

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

expectation_value_sign(p::Pauli{N}, ket::KetBitString{N}) where N = expectation_value(p::Pauli{N}, ket::KetBitString{N}) where N
expectation_value_sign(p::FixedPhasePauli{N}, ket::KetBitString{N}) where N = expectation_value(p::FixedPhasePauli{N}, ket::KetBitString{N}) where N
12 changes: 12 additions & 0 deletions src/type_KetBitString.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,16 @@ function Base.string(p::KetBitString{N}) where N
out[i] = 1
end
return join(out[1:N])
end


"""
Base.Vector(k::KetBitString{N}) where N
TBW
"""
function Base.Vector(k::KetBitString{N}) where N
vec = zeros(Int8,2^N)
vec[k.v+1] = 1
return vec
end
19 changes: 7 additions & 12 deletions src/type_PauliSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ end
TBW
"""
function PauliSum(N)
function PauliSum(N::Integer)
return PauliSum{N}(Dict{FixedPhasePauli{N},ComplexF64}())
end
function PauliSum(o::Pauli{N}) where N
return PauliSum{N}(Dict(o.pauli => get_phase(o)))
end


"""
Expand All @@ -36,9 +39,9 @@ Base.get(ps::PauliSum{N}, p::FixedPhasePauli{N}) where N = get(ps.ops, p, zero(C
Base.get(ps::PauliSum{N}, p::Pauli{N}) where N = get(ps.ops, p.pauli, zero(ComplexF64))
Base.get(ps::PauliSum{N}, p::ScaledPauli{N}) where N = get(ps.ops, p.pauli, zero(ComplexF64))
Base.keys(ps::PauliSum) = keys(ps.ops)
Base.getindex(ps::PauliSum{N}, p::Pauli{N}) where N = ps.ops[p]
Base.getindex(ps::PauliSum{N}, p::Pauli{N}) where N = ps.ops[p.pauli]
Base.getindex(ps::PauliSum{N}, p::FixedPhasePauli{N}) where N = ps.ops[p]
Base.setindex!(ps::PauliSum{N}, v, p::Pauli{N}) where N = ps.ops[p] = v*get_phase(p)
Base.setindex!(ps::PauliSum{N}, v, p::Pauli{N}) where N = ps.ops[p.pauli] = v*get_phase(p)
Base.setindex!(ps::PauliSum{N}, v, p::FixedPhasePauli{N}) where N = ps.ops[p] = v
Base.haskey(ps::PauliSum, v) = haskey(ps.ops, v)

Expand Down Expand Up @@ -164,15 +167,7 @@ end
Delete Pauli's with coeffs smaller than thresh
"""
function clip!(ps::PauliSum; thresh=1e-16)
to_delete = []
for (op,coeff) in ps.ops
if abs(coeff) < thresh
push!(to_delete, op)
end
end
for k in to_delete
delete!(ps.ops, k)
end
filter!(p->abs(p.second) > thresh, ps.ops)
end

"""
Expand Down
19 changes: 19 additions & 0 deletions test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ using Random
display(sum1)
println()

display(a)
display(sum1[a])
display(sum1[a.pauli])
sum1[a] = 3
display(a)

sum2 = a + d
display(sum2)

Expand Down Expand Up @@ -176,6 +182,19 @@ using Random
@test Pauli("YZXZ") * KetBitString([1,1,1,0]) == (1im, KetBitString([0,1,0,0]))
@test Pauli("XZXZ") * KetBitString([1,1,1,0]) == (-1, KetBitString([0,1,0,0]))

for i in 1:50
N = 8
# o = Pauli("XYZI")
# v = KetBitString([1,0,0,0])
o = random_Pauli(N)
v = KetBitString{N}(rand(1:2^N-1))
@test expectation_value(o, v) == Vector(v)'*Matrix(o)*Vector(v)

o = random_FixedPhasePauli(N)
v = KetBitString{N}(rand(1:2^N-1))
@test expectation_value(o, v) == Vector(v)'*Matrix(o)*Vector(v)
end

# ScaledPauli
N=8
for i in 1:10
Expand Down

0 comments on commit 0a37e78

Please sign in to comment.