Skip to content

Commit

Permalink
fix: Support arbitrary angle Molmer-Sorenson gate. (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt-aws authored Jul 26, 2023
1 parent d1cd7e8 commit c43bc16
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 41 deletions.
34 changes: 23 additions & 11 deletions src/gate_applicators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,58 @@ for (G, IRG) in zip((:H,:I,:X,:Y,:Z,:S,:Si,:T,:Ti,:V,:Vi,:CNot,:Swap,:ISwap,:CV,
end
apply_gate!(::IR.NonAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, arg::IntOrQubit) where {G<:Gate} = add_instruction!(c, Instruction(G(), arg))
apply_gate!(::IR.Angled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, arg::IntOrQubit, angle) where {G<:Gate} = add_instruction!(c, Instruction(G(angle), arg))
apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, arg::IntOrQubit, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), arg))
#apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, arg::IntOrQubit, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), arg))
apply_gate!(::IR.TripleAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, arg::IntOrQubit, angle1, angle2, angle3) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2, angle3), arg))

apply_gate!(::IR.NonAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, arg::VecOrQubitSet) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(), i)), arg); return c)
apply_gate!(::IR.Angled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, v::VecOrQubitSet, angle) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(angle), i)), v); return c)
apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, v::VecOrQubitSet, angle1, angle2) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(angle1, angle2), i)), v); return c)
#apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, v::VecOrQubitSet, angle1, angle2) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(angle1, angle2), i)), v); return c)
apply_gate!(::IR.TripleAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, v::VecOrQubitSet, angle1, angle2, angle3) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(angle1, angle2, angle3), i)), v); return c)

apply_gate!(::IR.NonAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(), i)), args); return c)
apply_gate!(::IR.Angled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(args[end]), i)), args[1:end-1]); return c)
apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(args[end-1], args[end]), i)), args[1:end-2]); return c)
#apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(args[end-1], args[end]), i)), args[1:end-2]); return c)
apply_gate!(::IR.TripleAngled, ::IR.NoControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = (foreach(i->add_instruction!(c, Instruction(G(args[end-2], args[end-1], args[end]), i)), args[1:end-2]); return c)

apply_gate!(::IR.NonAngled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet) where {G<:Gate} = add_instruction!(c, Instruction(G(), args[1:2]))
apply_gate!(::IR.Angled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle) where {G<:Gate} = add_instruction!(c, Instruction(G(angle), args[1:2]))
apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), args[1:2]))
#apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), args[1:2]))
apply_gate!(::IR.TripleAngled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2, angle3) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2, angle3), args[1:3]))

apply_gate!(::IR.NonAngled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(), [args[1:2]...]))
apply_gate!(::IR.Angled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end]), [args[1:2]...]))
apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-1], args[end]), [args[1:2]...]))
#apply_gate!(::IR.DoubleAngled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-1], args[end]), [args[1:2]...]))
apply_gate!(::IR.TripleAngled, ::IR.NoControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-2], args[end-1], args[end]), [args[1:2]...]))

apply_gate!(::IR.NonAngled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet) where {G<:Gate} = add_instruction!(c, Instruction(G(), args[1:2]))
apply_gate!(::IR.Angled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle) where {G<:Gate} = add_instruction!(c, Instruction(G(angle), args[1:2]))
apply_gate!(::IR.DoubleAngled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), args[1:2]))
#apply_gate!(::IR.DoubleAngled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), args[1:2]))
apply_gate!(::IR.TripleAngled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2, angle3) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2, angle3), args[1:2]))

apply_gate!(::IR.NonAngled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(), [args[1:2]...]))
apply_gate!(::IR.Angled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end]), [args[1:2]...]))
apply_gate!(::IR.DoubleAngled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-1], args[end]), [args[1:2]...]))
#apply_gate!(::IR.DoubleAngled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-1], args[end]), [args[1:2]...]))
apply_gate!(::IR.TripleAngled, ::IR.SingleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-2], args[end-1], args[end]), [args[1:2]...]))

apply_gate!(::IR.NonAngled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet) where {G<:Gate} = add_instruction!(c, Instruction(G(), args[1:3]))
apply_gate!(::IR.Angled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle) where {G<:Gate} = add_instruction!(c, Instruction(G(angle), args[1:3]))
apply_gate!(::IR.DoubleAngled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), args[1:3]))
#apply_gate!(::IR.DoubleAngled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), args[1:3]))
apply_gate!(::IR.TripleAngled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2, angle3) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2, angle3), args[1:3]))

apply_gate!(::IR.NonAngled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(), [args[1:3]...]))
apply_gate!(::IR.Angled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end]), [args[1:3]...]))
apply_gate!(::IR.DoubleAngled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-1], args[end]), [args[1:3]...]))
#apply_gate!(::IR.DoubleAngled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-1], args[end]), [args[1:3]...]))
apply_gate!(::IR.TripleAngled, ::IR.SingleControl, ::IR.DoubleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-2], args[end-1], args[end]), [args[1:3]...]))

apply_gate!(::IR.NonAngled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet) where {G<:Gate} = add_instruction!(c, Instruction(G(), args[1:3]))
apply_gate!(::IR.Angled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle) where {G<:Gate} = add_instruction!(c, Instruction(G(angle), args[1:3]))
apply_gate!(::IR.DoubleAngled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), args[1:3]))
#apply_gate!(::IR.DoubleAngled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2), args[1:3]))
apply_gate!(::IR.TripleAngled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args::VecOrQubitSet, angle1, angle2, angle3) where {G<:Gate} = add_instruction!(c, Instruction(G(angle1, angle2, angle3), args[1:3]))

apply_gate!(::IR.NonAngled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(), [args[1:3]...]))
apply_gate!(::IR.Angled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end]), [args[1:3]...]))
apply_gate!(::IR.DoubleAngled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-1], args[end]), [args[1:3]...]))
#apply_gate!(::IR.DoubleAngled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-1], args[end]), [args[1:3]...]))
apply_gate!(::IR.TripleAngled, ::IR.DoubleControl, ::IR.SingleTarget, ::Type{G}, c::Circuit, args...) where {G<:Gate} = add_instruction!(c, Instruction(G(args[end-2], args[end-1], args[end]), [args[1:3]...]))

apply_gate!(::IR.NonAngled, ::IR.NoControl, ::IR.MultiTarget, ::Type{Unitary}, c::Circuit, v::VecOrQubitSet, m::Matrix{ComplexF64}) = add_instruction!(c, Instruction(Unitary(m), v))
apply_gate!(::IR.NonAngled, ::IR.NoControl, ::IR.MultiTarget, ::Type{Unitary}, c::Circuit, args...) = add_instruction!(c, Instruction(Unitary(args[end]), [args[1:end-1]...]))
37 changes: 19 additions & 18 deletions src/gates.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export Gate,AngledGate,DoubleAngledGate,H,I,X,Y,Z,S,Si,T,Ti,V,Vi,CNot,Swap,ISwap,CV,CY,CZ,ECR,CCNot,CSwap,Unitary,Rx,Ry,Rz,PhaseShift,PSwap,XY,CPhaseShift,CPhaseShift00,CPhaseShift01,CPhaseShift10,XX,YY,ZZ,GPi,GPi2,MS
export Gate,AngledGate,TripleAngledGate,H,I,X,Y,Z,S,Si,T,Ti,V,Vi,CNot,Swap,ISwap,CV,CY,CZ,ECR,CCNot,CSwap,Unitary,Rx,Ry,Rz,PhaseShift,PSwap,XY,CPhaseShift,CPhaseShift00,CPhaseShift01,CPhaseShift10,XX,YY,ZZ,GPi,GPi2,MS
"""
Gate <: QuantumOperator
Abstract type representing a quantum gate.
"""
abstract type Gate <: QuantumOperator end
StructTypes.StructType(::Type{Gate}) = StructTypes.AbstractType()
StructTypes.subtypes(::Type{Gate}) = (angledgate=AngledGate, doubleangledgate=DoubleAngledGate, h=H, i=I, x=X, y=Y, z=Z, s=S, si=Si, t=T, ti=Ti, v=V, vi=Vi, cnot=CNot, swap=Swap, iswap=ISwap, cv=CV, cy=CY, cz=CZ, ecr=ECR, ccnot=CCNot, cswap=CSwap, unitary=Unitary, rx=Rx, ry=Ry, rz=Rz, phaseshift=PhaseShift, pswap=PSwap, xy=XY, cphaseshift=CPhaseShift, cphaseshift00=CPhaseShift00, cphaseshift01=CPhaseShift01, cphaseshift10=CPhaseShift10, xx=XX, yy=YY, zz=ZZ, gpi=GPi, gpi2=GPi2, ms=MS)
StructTypes.subtypes(::Type{Gate}) = (angledgate=AngledGate, tripleangledgate=TripleAngledGate, h=H, i=I, x=X, y=Y, z=Z, s=S, si=Si, t=T, ti=Ti, v=V, vi=Vi, cnot=CNot, swap=Swap, iswap=ISwap, cv=CV, cy=CY, cz=CZ, ecr=ECR, ccnot=CCNot, cswap=CSwap, unitary=Unitary, rx=Rx, ry=Ry, rz=Rz, phaseshift=PhaseShift, pswap=PSwap, xy=XY, cphaseshift=CPhaseShift, cphaseshift00=CPhaseShift00, cphaseshift01=CPhaseShift01, cphaseshift10=CPhaseShift10, xx=XX, yy=YY, zz=ZZ, gpi=GPi, gpi2=GPi2, ms=MS)

"""
AngledGate <: Gate
Expand All @@ -18,13 +18,13 @@ StructTypes.StructType(::Type{AngledGate}) = StructTypes.AbstractType()
StructTypes.subtypes(::Type{AngledGate}) = (rx=Rx, ry=Ry, rz=Rz, phaseshift=PhaseShift, pswap=PSwap, xy=XY, cphaseshift=CPhaseShift, cphaseshift00=CPhaseShift00, cphaseshift01=CPhaseShift01, cphaseshift10=CPhaseShift10, xx=XX, yy=YY, zz=ZZ, gpi=GPi, gpi2=GPi2)

"""
DoubleAngledGate <: Gate
TripleAngledGate <: Gate
Abstract type representing a quantum gate with two `angle` parameters.
Abstract type representing a quantum gate with three `angle` parameters.
"""
abstract type DoubleAngledGate <: Gate end
StructTypes.StructType(::Type{DoubleAngledGate}) = StructTypes.AbstractType()
StructTypes.subtypes(::Type{DoubleAngledGate}) = (ms=MS)
abstract type TripleAngledGate <: Gate end
StructTypes.StructType(::Type{TripleAngledGate}) = StructTypes.AbstractType()
StructTypes.subtypes(::Type{TripleAngledGate}) = (ms=MS)

for (G, IRG, label, qc, c) in zip((:Rx, :Ry, :Rz, :PhaseShift, :PSwap, :XY, :CPhaseShift, :CPhaseShift00, :CPhaseShift01, :CPhaseShift10, :XX, :YY, :ZZ, :GPi, :GPi2), (:(IR.Rx), :(IR.Ry), :(IR.Rz), :(IR.PhaseShift), :(IR.PSwap), :(IR.XY), :(IR.CPhaseShift), :(IR.CPhaseShift00), :(IR.CPhaseShift01), :(IR.CPhaseShift10), :(IR.XX), :(IR.YY), :(IR.ZZ), :(IR.GPi), :(IR.GPi2)), ("rx", "ry", "rz", "phaseshift", "pswap", "xy", "cphaseshift", "cphaseshift00", "cphaseshift01", "cphaseshift10", "xx", "yy", "zz", "gpi", "gpi2"), (:1, :1, :1, :1, :2, :2, :2, :2, :2, :2, :2, :2, :2, :1, :1), (["Rx(ang)"], ["Ry(ang)"], ["Rz(ang)"], ["PHASE(ang)"], ["PSWAP(ang)", "PSWAP(ang)"], ["XY(ang)", "XY(ang)"], ["C", "PHASE(ang)"], ["C", "PHASE00(ang)"], ["C", "PHASE01(ang)"], ["C", "PHASE10(ang)"], ["XX(ang)", "XX(ang)"], ["YY(ang)", "YY(ang)"], ["ZZ(ang)", "ZZ(ang)"], ["GPi(ang)"], ["GPi2(ang)"]))
@eval begin
Expand All @@ -51,29 +51,30 @@ for (G, IRG, label, qc, c) in zip((:Rx, :Ry, :Rz, :PhaseShift, :PSwap, :XY, :CPh
end
end
end
for (G, IRG, label, qc, c) in zip((:MS,), (:(IR.MS),), ("ms",), (:2,), (["MS(ang1, ang2)", "MS(ang1, ang2)"],))
for (G, IRG, label, qc, c) in zip((:MS,), (:(IR.MS),), ("ms",), (:2,), (["MS(ang1, ang2, ang3)", "MS(ang1, ang2, ang3)"],))
@eval begin
@doc """
$($G) <: DoubleAngledGate
$($G)(angle1::Union{Float64, FreeParameter}, angle2::Union{Float64, FreeParameter}) -> $($G)
$($G) <: TripleAngledGate
$($G)(angle1::Union{Float64, FreeParameter}, angle2::Union{Float64, FreeParameter}, angle3::Union{Float64, FreeParameter}) -> $($G)
$($G) gate.
"""
struct $G <: DoubleAngledGate
struct $G <: TripleAngledGate
angle1::Union{Float64, FreeParameter}
angle2::Union{Float64, FreeParameter}
angle3::Union{Float64, FreeParameter}
end
chars(g::$G) = map(char->replace(string(char), "ang1"=>string(g.angle1), "ang2"=>string(g.angle2)), $c)
chars(g::$G) = map(char->replace(string(char), "ang1"=>string(g.angle1), "ang2"=>string(g.angle2), "ang3"=>string(g.angle3)), $c)
qubit_count(g::$G) = $qc
qubit_count(::Type{$G}) = $qc
function ir(g::$G, target::QubitSet, ::Val{:JAQCD}; kwargs...)
t_c = IR._generate_control_and_target(IR.ControlAndTarget($IRG)..., target)
return $IRG(g.angle1, g.angle2, collect(t_c)..., $label)
return $IRG(g.angle1, g.angle2, g.angle3, collect(t_c)..., $label)
end
function ir(g::$G, target::QubitSet, ::Val{:OpenQASM}; serialization_properties=OpenQASMSerializationProperties())
t_c = IR._generate_control_and_target(IR.ControlAndTarget($IRG)..., target)
t = format_qubits(t_c, serialization_properties)
return $label*"($(g.angle1), $(g.angle2)) $t;"
return $label*"($(g.angle1), $(g.angle2), $(g.angle3)) $t;"
end
end
end
Expand Down Expand Up @@ -129,18 +130,18 @@ abstract type Parametrizable end
struct Parametrized end
struct NonParametrized end

Parametrizable(g::DoubleAngledGate) = Parametrized()
Parametrizable(g::TripleAngledGate) = Parametrized()
Parametrizable(g::AngledGate) = Parametrized()
Parametrizable(g::Gate) = NonParametrized()

parameters(g::DoubleAngledGate) = filter(a->a isa FreeParameter, [g.angle1, g.angle2])
parameters(g::TripleAngledGate) = filter(a->a isa FreeParameter, [g.angle1, g.angle2, g.angle3])
parameters(g::AngledGate) = g.angle isa FreeParameter ? [g.angle] : FreeParameter[]
parameters(g::Gate) = FreeParameter[]
bind_value!(g::G, params::Dict{Symbol, Number}) where {G<:Gate} = bind_value!(Parametrizable(g), g, params)
bind_value!(::NonParametrized, g::G, params::Dict{Symbol, Number}) where {G<:Gate} = g

function bind_value!(::Parametrized, g::G, params::Dict{Symbol, Number}) where {G<:DoubleAngledGate}
new_angles = map([g.angle2, g.angle2]) do angle
function bind_value!(::Parametrized, g::G, params::Dict{Symbol, Number}) where {G<:TripleAngledGate}
new_angles = map([g.angle1, g.angle2, g.angle3]) do angle
angle isa FreeParameter || return angle
return get(params, angle.name, angle)
end
Expand Down
9 changes: 8 additions & 1 deletion src/raw_schema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ StructTypes.defaults(::Type{GeneralizedAmplitudeDamping}) = Dict{Symbol, Any}(:t
struct MS <: AbstractIR
angle1::Float64
angle2::Float64
angle3::Float64
targets::Vector{Int}
type::String
end
Expand Down Expand Up @@ -713,11 +714,17 @@ for g in [:Rx, :Ry, :Rz, :PhaseShift, :CPhaseShift, :CPhaseShift00, :CPhaseShift
end
end
struct DoubleAngled <: Angle end
for g in [:MS]
for g in []
@eval begin
Angle(::Type{$g}) = DoubleAngled()
end
end
struct TripleAngled <: Angle end
for g in [:MS]
@eval begin
Angle(::Type{$g}) = TripleAngled()
end
end
struct NonAngled <: Angle end
Angle(::Type{G}) where {G<:AbstractIR} = NonAngled()
abstract type ProbabilityCount end
Expand Down
Loading

0 comments on commit c43bc16

Please sign in to comment.