Skip to content

Commit

Permalink
Merge pull request #219 from GTorlai/multi-qubit-gates
Browse files Browse the repository at this point in the history
fixed n-qubit gates (n>2)
  • Loading branch information
GTorlai authored Jul 20, 2021
2 parents d838cf4 + dbef799 commit f488809
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PastaQ"
uuid = "30b07047-aa8b-4c78-a4e8-24d720215c19"
authors = ["Giacomo Torlai <[email protected]>", "Matthew Fishman <[email protected]>"]
version = "0.0.8"
version = "0.0.9"

[deps]
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
Expand Down
10 changes: 2 additions & 8 deletions src/circuits/gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,8 @@ acting on sites `(site[1],site[2])`, with indices identical to a
reference state `M` (`MPS` or `MPO`).
"""
function gate(M::Union{MPS,MPO}, gatename::String, site::Tuple; kwargs...)
site_ind1 = (
typeof(M) == MPS ? siteind(M, site[1]) : firstind(M[site[1]]; tags="Site", plev=0)
)
site_ind2 = (
typeof(M) == MPS ? siteind(M, site[2]) : firstind(M[site[2]]; tags="Site", plev=0)
)

return gate(gatename, site_ind1, site_ind2; kwargs...)
site_inds = [typeof(M) == MPS ? siteind(M, s) : firstind(M[s]; tags="Site", plev=0) for s in site]
return gate(gatename, site_inds...; kwargs...)
end

gate(M::Union{MPS,MPO}, gatedata::Tuple) = gate(M, gatedata...)
Expand Down
19 changes: 19 additions & 0 deletions test/runcircuit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ end
@test prod(ρ) runcircuit(prod(ρ0), buildcircuit(ρ0, gates); apply_dag=true)
end


@testset "runcircuit: (n>2)-qubit gates" begin
N = 3
depth = 4
gates = randomcircuit(N, depth; layered=false)
push!(gates, ("Toffoli",(1,2,3)))
#Pure state, noiseless circuit
ψ0 = productstate(N)
ψ = runcircuit(ψ0, gates)
@test prod(ψ) runcircuit(prod(ψ0), buildcircuit(ψ0, gates))
@test PastaQ.array(prod(ψ)) PastaQ.array(prod(runcircuit(N, gates)))
@test PastaQ.array(prod(ψ)) PastaQ.array(prod(runcircuit(gates)))

# Mixed state, noiseless circuit
ρ0 = MPO(productstate(N))
ρ = runcircuit(ρ0, gates)
@test prod(ρ) runcircuit(prod(ρ0), buildcircuit(ρ0, gates); apply_dag=true)
end

@testset "runcircuit: noisy quantum circuit" begin
N = 5
depth = 4
Expand Down

2 comments on commit f488809

@GTorlai
Copy link
Owner 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/41201

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.0.9 -m "<description of version>" f488809f6958cb06ba3fe6bc4f3ee91f8147ccc2
git push origin v0.0.9

Please sign in to comment.