Skip to content

Commit

Permalink
Merge branch 'master' of github.com:GTorlai/PastaQ.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Apr 14, 2022
2 parents 44ffc4b + 22b36a8 commit 6d49251
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/circuits/circuits.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
function nqubits(g::Tuple)
s = g[2]
n = (s isa Number ? s : maximum(s))
return n
end
# This makes use of the `ITensors.Ops.Op` type, which
# automatically parses a gate represented as a Tuple
# into it's name, sites, and parameters.
nqubits(gate::Tuple) = maximum(Ops.sites(Op(gate)))

nqubits(gates::Vector{<:Any}) = maximum((nqubits(gate) for gate in gates))
nqubits(gates::Vector) = maximum((nqubits(gate) for gate in gates))

nlayers(circuit::Vector{<:Any}) = 1
nlayers(circuit::Vector{<:Vector{<:Any}}) = length(circuit)
nlayers(circuit::Vector) = 1
nlayers(circuit::Vector{<:Vector}) = length(circuit)

ngates(circuit::Vector{<:Any}) = length(circuit)
ngates(circuit::Vector{<:Vector{<:Any}}) = length(vcat(circuit...))
ngates(circuit::Vector) = length(circuit)
ngates(circuit::Vector{<:Vector}) = sum(length, circuit)

"""
--------------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions test/gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ using ITensors
using Test
using LinearAlgebra

@testset "nqubits" begin
@test nqubits(("X", 1, 2)) == 2
@test nqubits([("X", 1, 2), ("Y", 3, 2)]) == 3
@test nqubits(("X", (1, 2))) == 2
@test nqubits([("X", (1, 2)), ("Y", 3, 4)]) == 4
@test nqubits(("X", (1, 2), (; θ=π/2))) == 2
@test nqubits([("X", (1, 2)), ("Y", 3, 4, (; ϕ=2.3))]) == 4
end

@testset "Gate generation: 1-qubit gates" begin
i = Index(2, tags = "Qubit")

Expand Down

2 comments on commit 6d49251

@mtfishman
Copy link
Collaborator 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/58521

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.21 -m "<description of version>" 6d49251efdd8708216d6022b0b3081879ec14d64
git push origin v0.0.21

Please sign in to comment.