Skip to content

Commit

Permalink
change: Allow any real number for gate angles (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt-aws authored Aug 8, 2024
1 parent 2e61d5b commit 7422cb3
Show file tree
Hide file tree
Showing 13 changed files with 349 additions and 378 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ jobs:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: '1'
version: '1.10'
- uses: julia-actions/cache@v1
- name: Configure doc environment
shell: julia --project=docs --color=yes {0}
run: |
using Pkg
Pkg.Registry.update()
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()
- uses: julia-actions/julia-buildpkg@v1
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Braket"
uuid = "19504a0f-b47d-4348-9127-acc6cc69ef67"
authors = ["Katharine Hyatt <[email protected]>"]
version = "0.9.3"
version = "0.9.4"

[deps]
AWS = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
Expand Down Expand Up @@ -39,8 +39,8 @@ Aqua = "=0.8"
AxisArrays = "=0.4.7"
Base64 = "1.6"
CSV = "=0.10.14"
CodeTracking = "=1.3.5"
Compat = "=4.15.0"
CodeTracking = "=1.3.6"
Compat = "=4.16.0"
DataStructures = "=0.18.20"
Dates = "1.6"
DecFP = "=1.3.2"
Expand Down
6 changes: 3 additions & 3 deletions PyBraket/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PyBraket"
uuid = "e85266a6-1825-490b-a80e-9b9469c53660"
authors = ["Katharine Hyatt <[email protected]>"]
version = "0.9.3"
version = "0.9.4"

[deps]
Braket = "19504a0f-b47d-4348-9127-acc6cc69ef67"
Expand All @@ -14,11 +14,11 @@ StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"

[compat]
Aqua = "=0.8"
Braket = "=0.9.3"
Braket = "=0.9.4"
CondaPkg = "=0.2.23"
DataStructures = "=0.18.20"
LinearAlgebra = "1.6"
PythonCall = "=0.9.21"
PythonCall = "=0.9.22"
Statistics = "1"
StructTypes = "=1.10.0"
Test = "1.6"
Expand Down
42 changes: 21 additions & 21 deletions src/gate_applicators.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
(::Type{G})(c::Circuit) where {G<:Gate} = throw(ArgumentError("gate applied to a circuit must have targets."))
(::Type{G})(c::Circuit, args...) where {G<:Gate} = apply_gate!(Val(n_angles(G)), IR.Control(ir_typ(G)), IR.Target(ir_typ(G)), G, c, args...)
apply_gate!(::Type{G}, c::Circuit, args...) where {G<:Gate} = apply_gate!(Val(n_angles(G)), IR.Control(ir_typ(G)), IR.Target(ir_typ(G)), G, c, args...)
(::Type{G})(c::Circuit, args...) where {G<:Gate} = apply_gate!(Val(n_angles(G)), n_controls(G), n_targets(G), G, c, args...)
(::Type{Unitary})(c::Circuit, args...) = apply_gate!(Unitary, c, args...)
apply_gate!(::Type{G}, c::Circuit, args...) where {G<:Gate} = apply_gate!(Val(n_angles(G)), n_controls(G), n_targets(G), G, c, args...)

apply_gate!(::Val{N}, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, arg::IntOrQubit, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), arg))
apply_gate!(::Val{N}, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, v::VecOrQubitSet, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N} = (foreach(i->add_instruction!(c, Instruction{G}(G(angle), i)), v); return c)
apply_gate!(::Val{N}, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, v::NTuple{Nq, Ti}, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N, Nq, Ti} = (foreach(i->add_instruction!(c, Instruction{G}(G(angle), i)), v); return c)
apply_gate!(::Val{N}, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate, N} = (foreach(i->add_instruction!(c, Instruction{G}(G(args[end-(N-1):end]), i)), args[1:end-N]); return c)
apply_gate!(::Val{0}, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, qs::IntOrQubit...) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction{G}(G(), i)), qs); return c)
apply_gate!(::Val{N}, ::Val{0}, ::Val{1}, ::Type{G}, c::Circuit, args...) where {G<:Gate, N} = (foreach(i->add_instruction!(c, Instruction{G}(G(args[end-(N-1):end]), i)), args[1:end-N]); return c)
apply_gate!(::Val{0}, ::Val{0}, ::Val{1}, ::Type{G}, c::Circuit, args::IntOrQubit...) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction{G}(G(), i)), args); return c)
apply_gate!(::Val{0}, ::Val{0}, ::Val{1}, ::Type{G}, c::Circuit, args::VecOrQubitSet) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction{G}(G(), i)), args); return c)
apply_gate!(::Val{N}, ::Val{0}, ::Val{1}, ::Type{G}, c::Circuit, args::VecOrQubitSet, angles::Union{Real, FreeParameter}...) where {N, G<:Gate} = (foreach(i->add_instruction!(c, Instruction{G}(G(tuple(angles[1:N]...)), i)), args); return c)

apply_gate!(::Val{N}, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, t1::IntOrQubit, t2::IntOrQubit, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), [t1, t2]))
apply_gate!(::Val{N}, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), args[1:2]))
apply_gate!(::Val{N}, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::NTuple{2, Ti}, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N, Ti} = add_instruction!(c, Instruction{G}(G(angle), args[1:2]))
apply_gate!(::Val{N}, ::Val{0}, ::Val{2}, ::Type{G}, c::Circuit, t1::IntOrQubit, t2::IntOrQubit, angle::Union{Real, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), [t1, t2]))
apply_gate!(::Val{N}, ::Val{0}, ::Val{2}, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle::Union{Real, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), args[1:2]))
apply_gate!(::Val{N}, ::Val{0}, ::Val{2}, ::Type{G}, c::Circuit, args::NTuple{2, Ti}, angle::Union{Real, FreeParameter}...) where {G<:Gate, N, Ti} = add_instruction!(c, Instruction{G}(G(angle), args[1:2]))

apply_gate!(::Val{N}, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, ci::IntOrQubit, ti::IntOrQubit, angles::Union{Float64, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angles), [ci, ti]))
apply_gate!(::Val{N}, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angles::Union{Float64, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angles), args[1:2]))
apply_gate!(::Val{N}, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::NTuple{2, Ti}, angles::Union{Float64, FreeParameter}...) where {G<:Gate, N, Ti} = add_instruction!(c, Instruction{G}(G(angles), [args...]))
apply_gate!(::Val{N}, ::Val{1}, ::Val{1}, ::Type{G}, c::Circuit, ci::IntOrQubit, ti::IntOrQubit, angles::Union{Real, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angles), [ci, ti]))
apply_gate!(::Val{N}, ::Val{1}, ::Val{1}, ::Type{G}, c::Circuit, args::VecOrQubitSet, angles::Union{Real, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angles), args[1:2]))
apply_gate!(::Val{N}, ::Val{1}, ::Val{1}, ::Type{G}, c::Circuit, args::NTuple{2, Ti}, angles::Union{Real, FreeParameter}...) where {G<:Gate, N, Ti} = add_instruction!(c, Instruction{G}(G(angles), [args...]))

apply_gate!(::Val{N}, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, ci::IntOrQubit, t1::IntOrQubit, t2::IntOrQubit, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), [ci, t1, t2]))
apply_gate!(::Val{N}, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), args[1:3]))
apply_gate!(::Val{N}, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::NTuple{3, Ti}, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N, Ti} = add_instruction!(c, Instruction{G}(G(angle), [args...]))
apply_gate!(::Val{N}, ::Val{1}, ::Val{2}, ::Type{G}, c::Circuit, ci::IntOrQubit, t1::IntOrQubit, t2::IntOrQubit, angle::Union{Real, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), [ci, t1, t2]))
apply_gate!(::Val{N}, ::Val{1}, ::Val{2}, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle::Union{Real, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), args[1:3]))
apply_gate!(::Val{N}, ::Val{1}, ::Val{2}, ::Type{G}, c::Circuit, args::NTuple{3, Ti}, angle::Union{Real, FreeParameter}...) where {G<:Gate, N, Ti} = add_instruction!(c, Instruction{G}(G(angle), [args...]))

apply_gate!(::Val{N}, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, c1::IntOrQubit, c2::IntOrQubit, ti::IntOrQubit, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), [c1, c2, ti]))
apply_gate!(::Val{N}, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), args[1:3]))
apply_gate!(::Val{N}, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::NTuple{3, Ti}, angle::Union{Float64, FreeParameter}...) where {G<:Gate, N, Ti} = add_instruction!(c, Instruction{G}(G(angle), [args...]))
apply_gate!(::Val{N}, ::Val{2}, ::Val{1}, ::Type{G}, c::Circuit, c1::IntOrQubit, c2::IntOrQubit, ti::IntOrQubit, angle::Union{Real, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), [c1, c2, ti]))
apply_gate!(::Val{N}, ::Val{2}, ::Val{1}, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle::Union{Real, FreeParameter}...) where {G<:Gate, N} = add_instruction!(c, Instruction{G}(G(angle), args[1:3]))
apply_gate!(::Val{N}, ::Val{2}, ::Val{1}, ::Type{G}, c::Circuit, args::NTuple{3, Ti}, angle::Union{Real, FreeParameter}...) where {G<:Gate, N, Ti} = add_instruction!(c, Instruction{G}(G(angle), [args...]))

apply_gate!(::Val{0}, ::IR.NoControl, ::IR.MultiTarget, ::Type{Unitary}, c::Circuit, v::VecOrQubitSet, m::Matrix{ComplexF64}) = add_instruction!(c, Instruction{Unitary}(Unitary(m), v))
apply_gate!(::Val{0}, ::IR.NoControl, ::IR.MultiTarget, ::Type{Unitary}, c::Circuit, args...) = add_instruction!(c, Instruction{Unitary}(Unitary(args[end]), [args[1:end-1]...]))
apply_gate!(::Type{Unitary}, c::Circuit, v::VecOrQubitSet, m::Matrix{ComplexF64}) = add_instruction!(c, Instruction{Unitary}(Unitary(m), v))
apply_gate!(::Type{Unitary}, c::Circuit, args...) = add_instruction!(c, Instruction{Unitary}(Unitary(args[end]), [args[1:end-1]...]))
Loading

2 comments on commit 7422cb3

@kshyatt-aws
Copy link
Member 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/112687

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.9.4 -m "<description of version>" 7422cb39ba9f5de46c6c793c803cb86cf997830d
git push origin v0.9.4

Please sign in to comment.