Skip to content

Commit

Permalink
Fix gate parsing issue that was introduced in ITensors 0.3.14 (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Jun 19, 2022
1 parent 54cc060 commit 482e76e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions 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.23"
version = "0.0.24"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand All @@ -19,7 +19,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
[compat]
ChainRulesCore = "1.10"
HDF5 = "0.13.1, 0.14, 0.15"
ITensors = "0.3.6"
ITensors = "0.3.16"
JLD2 = "0.4.14"
Observers = "0.0"
Optimisers = "0.1.0"
Expand Down
35 changes: 34 additions & 1 deletion src/circuits/circuits.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
# Specialized PastaQ parsing of a gate
# ITensors 0.3.14 (https://github.com/ITensor/ITensors.jl/pull/920)
# introduced an Op redesign, such that:
#
# Op("O", (1, 2))
#
# get interpreted as an operator with one site with a multidimensional
# index, for example the site `(1, 2)` on a square lattice.
#
# Op("O", 1, 2)
#
# is the way to indicate a two-site operator. This is at odds with
# the PastaQ convention that:
#
# ("O", (1, 2))
#
# or
#
# ("O", 1, 2)
#
# get interpreted as a multi-site operator with support on sites 1 and 2.
# `gate_to_op` is a wrapper around `Op` that fixes this discrepency.
gate_to_op(gate::Tuple) = gate_to_op(gate...)
gate_to_op(which_op, sites::Tuple) = Op(which_op, sites...)
gate_to_op(which_op, sites::Tuple, params::NamedTuple) = Op(which_op, sites...; params...)
gate_to_op(which_op, sites::Int...) = Op(which_op, sites...)
gate_to_op(which_op, site::Int, params::NamedTuple) = Op(which_op, site; params...)
function gate_to_op(which_op, sites_and_params::Union{Int,NamedTuple}...)
sites = Base.front(sites_and_params)
params = last(sites_and_params)
return Op(which_op, sites...; params...)
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(gate::Tuple) = maximum(ITensors.sites(gate_to_op(gate)))

nqubits(gates::Vector) = maximum((nqubits(gate) for gate in gates))

Expand Down

2 comments on commit 482e76e

@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/62618

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.24 -m "<description of version>" 482e76e784fa258936e441d034a067b75598c7fc
git push origin v0.0.24

Please sign in to comment.