Skip to content

Commit

Permalink
change: Add PRx gate (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt-aws committed May 3, 2024
1 parent a290387 commit 4d6a7fe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/gates.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export Gate, AngledGate, 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, 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, PRx
"""
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, 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, 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, prx=PRx)

"""
AngledGate{NA} <: Gate
Expand Down Expand Up @@ -34,7 +34,9 @@ for gate_def in (
(:ZZ, :1, :2, ("ZZ(ang)", "ZZ(ang)")),
(:GPi, :1, :1, ("GPi(ang)",)),
(:GPi2, :1, :1, ("GPi2(ang)",)),
(:MS, :3, :2, ("MS(ang)", "MS(ang)")))
(:MS, :3, :2, ("MS(ang)", "MS(ang)")),
(:PRx, :2, :1, ("PRx(ang)", "PRx(ang)")),
)
G, n_angle, qc, c = gate_def
@eval begin
@doc """
Expand Down
16 changes: 13 additions & 3 deletions src/raw_schema.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export Program, AHSProgram, AbstractIR, AbstractProgramResult, CompilerDirective

abstract type AbstractIR end
StructTypes.StructType(::Type{AbstractIR}) = StructTypes.AbstractType()
StructTypes.subtypes(::Type{AbstractIR}) = (z=Z, sample=Sample, cphaseshift01=CPhaseShift01, phase_damping=PhaseDamping, rz=Rz, generalized_amplitude_damping=GeneralizedAmplitudeDamping, xx=XX, zz=ZZ, phase_flip=PhaseFlip, vi=Vi, depolarizing=Depolarizing, variance=Variance, two_qubit_depolarizing=TwoQubitDepolarizing, densitymatrix=DensityMatrix, cphaseshift00=CPhaseShift00, ecr=ECR, ccnot=CCNot, unitary=Unitary, bit_flip=BitFlip, y=Y, swap=Swap, cz=CZ, cnot=CNot, adjoint_gradient=AdjointGradient, cswap=CSwap, ry=Ry, i=I, si=Si, amplitude_damping=AmplitudeDamping, statevector=StateVector, iswap=ISwap, h=H, xy=XY, yy=YY, t=T, ahsprogram=AHSProgram, two_qubit_dephasing=TwoQubitDephasing, x=X, ti=Ti, cv=CV, pauli_channel=PauliChannel, pswap=PSwap, expectation=Expectation, probability=Probability, phaseshift=PhaseShift, v=V, cphaseshift=CPhaseShift, s=S, rx=Rx, kraus=Kraus, amplitude=Amplitude, cphaseshift10=CPhaseShift10, multi_qubit_pauli_channel=MultiQubitPauliChannel, cy=CY, ms=MS, gpi=GPi, gpi2=GPi2)
StructTypes.subtypes(::Type{AbstractIR}) = (z=Z, sample=Sample, cphaseshift01=CPhaseShift01, phase_damping=PhaseDamping, rz=Rz, generalized_amplitude_damping=GeneralizedAmplitudeDamping, xx=XX, zz=ZZ, phase_flip=PhaseFlip, vi=Vi, depolarizing=Depolarizing, variance=Variance, two_qubit_depolarizing=TwoQubitDepolarizing, densitymatrix=DensityMatrix, cphaseshift00=CPhaseShift00, ecr=ECR, ccnot=CCNot, unitary=Unitary, bit_flip=BitFlip, y=Y, swap=Swap, cz=CZ, cnot=CNot, adjoint_gradient=AdjointGradient, cswap=CSwap, ry=Ry, i=I, si=Si, amplitude_damping=AmplitudeDamping, statevector=StateVector, iswap=ISwap, h=H, xy=XY, yy=YY, t=T, ahsprogram=AHSProgram, two_qubit_dephasing=TwoQubitDephasing, x=X, ti=Ti, cv=CV, pauli_channel=PauliChannel, pswap=PSwap, expectation=Expectation, probability=Probability, phaseshift=PhaseShift, v=V, cphaseshift=CPhaseShift, s=S, rx=Rx, kraus=Kraus, amplitude=Amplitude, cphaseshift10=CPhaseShift10, multi_qubit_pauli_channel=MultiQubitPauliChannel, cy=CY, ms=MS, gpi=GPi, gpi2=GPi2, prx=PRx)

const IRObservable = Union{Vector{Union{String, Vector{Vector{Vector{Float64}}}}}, String}
Base.convert(::Type{IRObservable}, v::Vector{String}) = convert(Vector{Union{String, Vector{Vector{Vector{Float64}}}}}, v)
Expand Down Expand Up @@ -472,6 +472,16 @@ end
StructTypes.StructType(::Type{MS}) = StructTypes.UnorderedStruct()
StructTypes.defaults(::Type{MS}) = Dict{Symbol, Any}(:type => "ms")

struct PRx <: AbstractIR
angle1::Float64
angle2::Float64
target::Int
type::String
end
StructTypes.StructType(::Type{PRx}) = StructTypes.UnorderedStruct()
StructTypes.defaults(::Type{PRx}) = Dict{Symbol, Any}(:type => "prx")


struct ECR <: AbstractIR
targets::Vector{Int}
type::String
Expand Down Expand Up @@ -714,7 +724,7 @@ for g in [:Swap, :CSwap, :ISwap, :PSwap, :XY, :ECR, :XX, :YY, :ZZ, :TwoQubitDepo
end
end
struct SingleTarget <: Target end
for g in [:H, :I, :X, :Y, :Z, :Rx, :Ry, :Rz, :S, :T, :Si, :Ti, :PhaseShift, :CPhaseShift, :CPhaseShift00, :CPhaseShift01, :CPhaseShift10, :CNot, :CCNot, :CV, :CY, :CZ, :V, :Vi, :BitFlip, :PhaseFlip, :PauliChannel, :Depolarizing, :AmplitudeDamping, :GeneralizedAmplitudeDamping, :PhaseDamping, :GPi, :GPi2]
for g in [:H, :I, :X, :Y, :Z, :Rx, :Ry, :Rz, :S, :T, :Si, :Ti, :PhaseShift, :CPhaseShift, :CPhaseShift00, :CPhaseShift01, :CPhaseShift10, :CNot, :CCNot, :CV, :CY, :CZ, :V, :Vi, :BitFlip, :PhaseFlip, :PauliChannel, :Depolarizing, :AmplitudeDamping, :GeneralizedAmplitudeDamping, :PhaseDamping, :GPi, :GPi2, :PRx]
@eval begin
Target(::Type{$g}) = SingleTarget()
end
Expand Down Expand Up @@ -745,7 +755,7 @@ for g in [:Rx, :Ry, :Rz, :PhaseShift, :CPhaseShift, :CPhaseShift00, :CPhaseShift
end
end
struct DoubleAngled <: Angle end
for g in Symbol[]
for g in [:PRx]
@eval begin
Angle(::Type{$g}) = DoubleAngled()
end
Expand Down
4 changes: 4 additions & 0 deletions src/schemas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function Instruction(x)
o_fns = (:angles, :angle)
args = (Float64(x[:angle]),)
op = o_type(args)
elseif o_type <: AngledGate{2}
o_fns = (:angles, :angle1, :angle2)
args = tuple([x[fn] for fn in [Symbol("angle$i") for i in 1:n_angles(o_type)]]...)
op = o_type(args)
elseif o_type <: AngledGate{3}
o_fns = (:angles, :angle1, :angle2, :angle3)
args = tuple([x[fn] for fn in [Symbol("angle$i") for i in 1:n_angles(o_type)]]...)
Expand Down
7 changes: 7 additions & 0 deletions test/gates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ T_mat = round.(reduce(hcat, [[1.0, 0], [0, 0.70710678 + 0.70710678im]]), digits=
@test Braket.Parametrizable(g) == Braket.Parametrized()
@test Braket.parameters(g) == Braket.FreeParameter[]
end
@testset for g in (PRx(angle, angle),)
@test qubit_count(g) == 1
ix = Instruction(g, [0])
@test JSON3.read(JSON3.write(ix), Instruction) == ix
@test Braket.Parametrizable(g) == Braket.Parametrized()
@test Braket.parameters(g) == Braket.FreeParameter[]
end
@testset for g in (MS,)
@test qubit_count(g) == 2
c = Circuit()
Expand Down

0 comments on commit 4d6a7fe

Please sign in to comment.