Skip to content

Commit

Permalink
change: Allow any real number for gate angles
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt-aws committed Aug 8, 2024
1 parent 2e61d5b commit 6e4a0b9
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 377 deletions.
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]))

Check warning on line 13 in src/gate_applicators.jl

View check run for this annotation

Codecov / codecov/patch

src/gate_applicators.jl#L13

Added line #L13 was not covered by tests

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...]))

Check warning on line 17 in src/gate_applicators.jl

View check run for this annotation

Codecov / codecov/patch

src/gate_applicators.jl#L17

Added line #L17 was not covered by tests

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...]))

Check warning on line 21 in src/gate_applicators.jl

View check run for this annotation

Codecov / codecov/patch

src/gate_applicators.jl#L21

Added line #L21 was not covered by tests

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...]))

Check warning on line 25 in src/gate_applicators.jl

View check run for this annotation

Codecov / codecov/patch

src/gate_applicators.jl#L25

Added line #L25 was not covered by tests

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

0 comments on commit 6e4a0b9

Please sign in to comment.