diff --git a/src/gates.jl b/src/gates.jl index cefd8d6f..5be9c984 100644 --- a/src/gates.jl +++ b/src/gates.jl @@ -1,4 +1,4 @@ -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 @@ -6,7 +6,7 @@ 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 @@ -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 """ diff --git a/src/raw_schema.jl b/src/raw_schema.jl index 872ed386..a2c0f923 100644 --- a/src/raw_schema.jl +++ b/src/raw_schema.jl @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/src/schemas.jl b/src/schemas.jl index 25b1b582..23f0ba88 100644 --- a/src/schemas.jl +++ b/src/schemas.jl @@ -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)]]...) diff --git a/test/gates.jl b/test/gates.jl index 825d78b4..56ff36a5 100644 --- a/test/gates.jl +++ b/test/gates.jl @@ -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()