Skip to content

Rotation Gates #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ext/QuantumOpticsExt/QuantumOpticsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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,
Expand All @@ -31,6 +31,13 @@
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

Check warning on line 39 in ext/QuantumOpticsExt/QuantumOpticsExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/QuantumOpticsExt/QuantumOpticsExt.jl#L34-L39

Added lines #L34 - L39 were not covered by tests
end
const _cnot = _l00⊗_id + _l11⊗_x
const _cphase = _l00⊗_id + _l11⊗_z
const _phase = _l00 + im*_l11
Expand All @@ -47,6 +54,7 @@
express_nolookup(::XGate, ::QuantumOpticsRepr) = _x
express_nolookup(::YGate, ::QuantumOpticsRepr) = _y
express_nolookup(::ZGate, ::QuantumOpticsRepr) = _z
express_nolookup(g::RGate, ::QuantumOpticsRepr) = _r(g)

Check warning on line 57 in ext/QuantumOpticsExt/QuantumOpticsExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/QuantumOpticsExt/QuantumOpticsExt.jl#L57

Added line #L57 was not covered by tests
express_nolookup(::CPHASEGate, ::QuantumOpticsRepr) = _cphase
express_nolookup(::CNOTGate, ::QuantumOpticsRepr) = _cnot

Expand Down
4 changes: 2 additions & 2 deletions src/QSymbolicsBase/QSymbolicsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions src/QSymbolicsBase/predefined.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@
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

Check warning on line 115 in src/QSymbolicsBase/predefined.jl

View check run for this annotation

Codecov / codecov/patch

src/QSymbolicsBase/predefined.jl#L113-L115

Added lines #L113 - L115 were not covered by tests

@withmetadata struct CNOTGate <: AbstractTwoQubitGate end
symbollabel(::CNOTGate) = "CNOT"
ishermitian(::CNOTGate) = true
Expand Down Expand Up @@ -143,6 +151,12 @@
const Pp = const σ₊ = PauliP()
"""Hadamard gate"""
const H = HGate()
"""Rotation X gate"""
const Rx(θ::Float64) = RGate(:x, θ)

Check warning on line 155 in src/QSymbolicsBase/predefined.jl

View check run for this annotation

Codecov / codecov/patch

src/QSymbolicsBase/predefined.jl#L155

Added line #L155 was not covered by tests
"""Rotation Y gate"""
const Ry(θ::Float64) = RGate(:y, θ)

Check warning on line 157 in src/QSymbolicsBase/predefined.jl

View check run for this annotation

Codecov / codecov/patch

src/QSymbolicsBase/predefined.jl#L157

Added line #L157 was not covered by tests
"""Rotation Z gate"""
const Rz(θ::Float64) = RGate(:z, θ)

Check warning on line 159 in src/QSymbolicsBase/predefined.jl

View check run for this annotation

Codecov / codecov/patch

src/QSymbolicsBase/predefined.jl#L159

Added line #L159 was not covered by tests
"""CNOT gate"""
const CNOT = CNOTGate()
"""CPHASE gate"""
Expand Down
Loading