Skip to content

Commit

Permalink
Implement sqrt of some operators
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Jun 30, 2023
1 parent 9703d49 commit b7cd54c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Gate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ end
The ``\\theta`` rotation around the X-axis gate.
"""
abstract type Rx <: Operator{NamedTuple{(:θ,),Tuple{Float64}}} end
Base.sqrt(g::Gate{X}) = Rx(lanes(g)..., θ = π / 2)
Base.sqrt(::Type{X}) = (lane) -> Rx(lane, θ = π / 2)

"""
Ry(lane, θ)
The ``\\theta`` rotation around the Y-axis gate.
"""
abstract type Ry <: Operator{NamedTuple{(:θ,),Tuple{Float64}}} end
Base.sqrt(g::Gate{Y}) = Ry(lanes(g)..., θ = π / 2)
Base.sqrt(::Type{Y}) = (lane) -> Ry(lane, θ = π / 2)

"""
Rz(lane, θ)
Expand All @@ -119,6 +123,13 @@ The ``\\theta`` rotation around the Z-axis gate.
- The `U1` gate is an alias of `Rz`.
"""
abstract type Rz <: Operator{NamedTuple{(:θ,),Tuple{Float64}}} end
Base.sqrt(g::Gate{Z}) = S(lanes(g)...)
Base.sqrt(::Type{Z}) = (lane) -> S(lane)

Base.sqrt(g::Gate{S}) = T(lanes(g)...)
Base.sqrt(::Type{S}) = (lane) -> T(lane)
Base.sqrt(g::Gate{Sd}) = Td(lanes(g)...)
Base.sqrt(::Type{Sd}) = (lane) -> Td(lane)

for Op in [:Rx, :Ry, :Rz]
@eval Base.length(::Type{$Op}) = 1
Expand Down

0 comments on commit b7cd54c

Please sign in to comment.