From d29d930650ddbb918906b72c639db16464acd2be Mon Sep 17 00:00:00 2001 From: sagnikpal2004 Date: Mon, 23 Dec 2024 16:38:27 +0530 Subject: [PATCH 1/3] add RGate --- ext/QuantumOpticsExt/QuantumOpticsExt.jl | 10 +++++++++- src/QSymbolicsBase/predefined.jl | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ext/QuantumOpticsExt/QuantumOpticsExt.jl b/ext/QuantumOpticsExt/QuantumOpticsExt.jl index fff1fd5..9ee3e7c 100644 --- a/ext/QuantumOpticsExt/QuantumOpticsExt.jl +++ b/ext/QuantumOpticsExt/QuantumOpticsExt.jl @@ -4,7 +4,7 @@ using QuantumInterface, QuantumOpticsBase using QuantumInterface: samebases using QuantumSymbolics using QuantumSymbolics: - HGate, XGate, YGate, ZGate, CPHASEGate, CNOTGate, PauliP, PauliM, + HGate, XGate, YGate, ZGate, RGate, CPHASEGate, CNOTGate, PauliP, PauliM, XCXGate, XCYGate, XCZGate, YCXGate, YCYGate, YCZGate, ZCXGate, ZCYGate, ZCZGate, XBasisState, YBasisState, ZBasisState, NumberOp, CreateOp, DestroyOp, @@ -31,6 +31,13 @@ const _z = sigmaz(_b2) const _x = sigmax(_b2) const _y = sigmay(_b2) const _hadamard = (sigmaz(_b2)+sigmax(_b2))/√2 +const _r(g::RGate) = if g.dir == :x + cos(g.θ/2)*_id - im*sin(g.θ/2)*_x +elseif g.dir == :y + cos(g.θ/2)*_id - im*sin(g.θ/2)*_y +elseif g.dir == :z + cos(g.θ/2)*_id - im*sin(g.θ/2)*_z +end const _cnot = _l00⊗_id + _l11⊗_x const _cphase = _l00⊗_id + _l11⊗_z const _phase = _l00 + im*_l11 @@ -47,6 +54,7 @@ express_nolookup(::HGate, ::QuantumOpticsRepr) = _hadamard express_nolookup(::XGate, ::QuantumOpticsRepr) = _x express_nolookup(::YGate, ::QuantumOpticsRepr) = _y express_nolookup(::ZGate, ::QuantumOpticsRepr) = _z +express_nolookup(g::RGate, ::QuantumOpticsRepr) = _r(g) express_nolookup(::CPHASEGate, ::QuantumOpticsRepr) = _cphase express_nolookup(::CNOTGate, ::QuantumOpticsRepr) = _cnot diff --git a/src/QSymbolicsBase/predefined.jl b/src/QSymbolicsBase/predefined.jl index 789f045..3ebe97e 100644 --- a/src/QSymbolicsBase/predefined.jl +++ b/src/QSymbolicsBase/predefined.jl @@ -106,6 +106,14 @@ symbollabel(::HGate) = "H" ishermitian(::HGate) = true isunitary(::HGate) = true +@withmetadata struct RGate <: AbstractSingleQubitGate + dir::Symbol + θ::Float64 +end +symbollabel(g::RGate) = "R$(g.dir)($(g.θ))" +ishermitian(::RGate) = true +isunitary(::RGate) = true + @withmetadata struct CNOTGate <: AbstractTwoQubitGate end symbollabel(::CNOTGate) = "CNOT" ishermitian(::CNOTGate) = true @@ -143,6 +151,10 @@ const Pm = const σ₋ = PauliM() const Pp = const σ₊ = PauliP() """Hadamard gate""" const H = HGate() +"""Rotation gates""" +const Rx(θ::Float64) = RGate(:x, θ) +const Ry(θ::Float64) = RGate(:y, θ) +const Rz(θ::Float64) = RGate(:z, θ) """CNOT gate""" const CNOT = CNOTGate() """CPHASE gate""" From 62c2ff2c01698f51d68b8447b4ca0f6225ff86c9 Mon Sep 17 00:00:00 2001 From: sagnikpal2004 Date: Tue, 24 Dec 2024 11:07:31 +0530 Subject: [PATCH 2/3] export --- src/QSymbolicsBase/QSymbolicsBase.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/QSymbolicsBase/QSymbolicsBase.jl b/src/QSymbolicsBase/QSymbolicsBase.jl index 955a40d..46bc977 100644 --- a/src/QSymbolicsBase/QSymbolicsBase.jl +++ b/src/QSymbolicsBase/QSymbolicsBase.jl @@ -27,7 +27,7 @@ export SymQObj,QObj, tensor,⊗, dagger,projector,commutator,anticommutator,conj,transpose,inv,exp,vec,tr,ptrace, I,X,Y,Z,σˣ,σʸ,σᶻ,Pm,Pp,σ₋,σ₊, - H,CNOT,CPHASE,XCX,XCY,XCZ,YCX,YCY,YCZ,ZCX,ZCY,ZCZ, + H,Rx,Ry,Rz,CNOT,CPHASE,XCX,XCY,XCZ,YCX,YCY,YCZ,ZCX,ZCY,ZCZ, X1,X2,Y1,Y2,Z1,Z2,X₁,X₂,Y₁,Y₂,Z₁,Z₂,L0,L1,Lp,Lm,Lpi,Lmi,L₀,L₁,L₊,L₋,L₊ᵢ,L₋ᵢ, vac,F₀,F0,F₁,F1,inf_fock_basis, N,n̂,Create,âꜛ,Destroy,â,basis,SpinBasis,FockBasis, @@ -40,7 +40,7 @@ export SymQObj,QObj, SConjugate,STranspose,SProjector,SDagger,SInvOperator,SExpOperator,SVec,STrace,SPartialTrace, MixedState,IdentityOp, SApplyKet,SApplyBra,SMulOperator,SSuperOpApply,SCommutator,SAnticommutator,SBraKet,SOuterKetBra, - HGate,XGate,YGate,ZGate,CPHASEGate,CNOTGate, + HGate,XGate,YGate,ZGate,RGate,CPHASEGate,CNOTGate, XBasisState,YBasisState,ZBasisState,FockState,CoherentState,SqueezedState, NumberOp,CreateOp,DestroyOp,PhaseShiftOp,DisplaceOp,SqueezeOp, XCXGate,XCYGate,XCZGate,YCXGate,YCYGate,YCZGate,ZCXGate,ZCYGate,ZCZGate, From 45d8269c6e35c0747224ed6a508b961d69674045 Mon Sep 17 00:00:00 2001 From: sagnikpal2004 Date: Tue, 24 Dec 2024 14:46:19 +0530 Subject: [PATCH 3/3] update docstring --- src/QSymbolicsBase/predefined.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/QSymbolicsBase/predefined.jl b/src/QSymbolicsBase/predefined.jl index 3ebe97e..3c594a1 100644 --- a/src/QSymbolicsBase/predefined.jl +++ b/src/QSymbolicsBase/predefined.jl @@ -151,9 +151,11 @@ const Pm = const σ₋ = PauliM() const Pp = const σ₊ = PauliP() """Hadamard gate""" const H = HGate() -"""Rotation gates""" +"""Rotation X gate""" const Rx(θ::Float64) = RGate(:x, θ) +"""Rotation Y gate""" const Ry(θ::Float64) = RGate(:y, θ) +"""Rotation Z gate""" const Rz(θ::Float64) = RGate(:z, θ) """CNOT gate""" const CNOT = CNOTGate()