Skip to content

Commit 8ea1a6a

Browse files
committed
rename some type parameters to be more descriptive and make spellchecker happy
1 parent ab65f0d commit 8ea1a6a

14 files changed

+125
-125
lines changed

.typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[default.extend-words]
22
ket = "ket"
3+
anc = "anc"
34

45
[type.ipynb]
56
# It detects false possitives in the base64 encoded images inside notebooks

ext/QuantumCliffordGPUExt/apply.jl

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ using QuantumClifford: getxbit, getzbit, setxbit, setzbit
44
# SingleQubitOperator Kernel
55
##############################
66

7-
function single_qubit_gpu_kernel(xzs::DeviceMatrix{Tme},
8-
phases::DeviceVector{Tmz},
7+
function single_qubit_gpu_kernel(xzs::DeviceMatrix{Tₘₑ},
8+
phases::DeviceVector{Tₚₑ},
99
op::SingleQubitOperator,
1010
rows::Int,
11-
compute_phases::Bool) where {Tme <: Unsigned, Tmz <: Unsigned}
11+
compute_phases::Bool) where {Tₘₑ <: Unsigned, Tₚₑ <: Unsigned}
1212
idx = (blockIdx().x - 1) * blockDim().x + threadIdx().x
1313
if idx > rows
1414
return nothing
1515
end
1616
c = op.q
1717
r = idx
18-
sh = QuantumClifford.getshift(Tme, c)
19-
xx,zx,xz,zz = Tme.((op.xx,op.zx,op.xz,op.zz)) .<< sh # maybe putting this in parent function call will improve speed?
18+
sh = QuantumClifford.getshift(Tₘₑ, c)
19+
xx,zx,xz,zz = Tₘₑ.((op.xx,op.zx,op.xz,op.zz)) .<< sh # maybe putting this in parent function call will improve speed?
2020
anticom = ~iszero((~zz & xz & ~xx & zx) | ( zz & ~xz & xx & zx) | (zz & xz & xx & ~zx))
2121

2222
x = getxbit(xzs, r, c)
@@ -45,20 +45,20 @@ end
4545
# AbstractSingleQubitOperator Kernel
4646
##############################
4747

48-
function abstract_single_qubit_gpu_kernel(xzs::DeviceMatrix{Tme},
49-
phases::DeviceVector{Tmz},
48+
function abstract_single_qubit_gpu_kernel(xzs::DeviceMatrix{Tₘₑ},
49+
phases::DeviceVector{Tₚₑ},
5050
gate::QuantumClifford.AbstractSingleQubitOperator,
5151
rows::Int,
52-
compute_phases::Bool) where {Tme <: Unsigned, Tmz <: Unsigned}
52+
compute_phases::Bool) where {Tₘₑ <: Unsigned, Tₚₑ <: Unsigned}
5353
idx = (blockIdx().x - 1) * blockDim().x + threadIdx().x
5454
if idx > rows
5555
return nothing
5656
end
5757
c = gate.q
5858
r = idx
5959

60-
x::Tme = getxbit(xzs, r, c)
61-
z::Tme = getzbit(xzs, r, c)
60+
x::Tₘₑ = getxbit(xzs, r, c)
61+
z::Tₘₑ = getzbit(xzs, r, c)
6262
x,z,phase::Bool = QuantumClifford.qubit_kernel(gate,x,z)
6363
setxbit(xzs, r, c, x)
6464
setzbit(xzs, r, c, z)
@@ -70,26 +70,26 @@ end
7070
# AbstractTwoQubitOperator Kernel
7171
##############################
7272

73-
function two_qubit_gpu_kernel(xzs::DeviceMatrix{Tme},
74-
phases::DeviceVector{Tze},
73+
function two_qubit_gpu_kernel(xzs::DeviceMatrix{Tₘₑ},
74+
phases::DeviceVector{Tₚ},
7575
gate::QuantumClifford.AbstractTwoQubitOperator,
7676
rows::Int,
77-
compute_phases::Bool=true) where {Tme <: Unsigned, Tze <: Unsigned}
77+
compute_phases::Bool=true) where {Tₘₑ <: Unsigned, Tₚ <: Unsigned}
7878
idx = (blockIdx().x - 1) * blockDim().x + threadIdx().x
7979
if idx > rows
8080
return nothing
8181
end
8282

8383
q1 = gate.q1
8484
q2 = gate.q2
85-
shift = QuantumClifford.getshift(Tme, q1) - QuantumClifford.getshift(Tme, q2)
85+
shift = QuantumClifford.getshift(Tₘₑ, q1) - QuantumClifford.getshift(Tₘₑ, q2)
8686
r = idx;
8787

88-
_x1::Tme = getxbit(xzs, r, q1)
89-
_z1::Tme = getzbit(xzs, r, q1)
90-
_x2::Tme = getxbit(xzs, r, q2)<<shift
91-
_z2::Tme = getzbit(xzs, r, q2)<<shift
92-
x1::Tme,z1::Tme,x2::Tme,z2::Tme,phase::Bool = QuantumClifford.qubit_kernel(gate,_x1,_z1,_x2,_z2) # Most `qubit_kernel` functions are defined by a `qubitop2` macro
88+
_x1::Tₘₑ = getxbit(xzs, r, q1)
89+
_z1::Tₘₑ = getzbit(xzs, r, q1)
90+
_x2::Tₘₑ = getxbit(xzs, r, q2)<<shift
91+
_z2::Tₘₑ = getzbit(xzs, r, q2)<<shift
92+
x1::Tₘₑ,z1::Tₘₑ,x2::Tₘₑ,z2::Tₘₑ,phase::Bool = QuantumClifford.qubit_kernel(gate,_x1,_z1,_x2,_z2) # Most `qubit_kernel` functions are defined by a `qubitop2` macro
9393
setxbit(xzs, r, q1, x1, 0)
9494
setzbit(xzs, r, q1, z1, 0)
9595
setxbit(xzs, r, q2, x2, -shift)
@@ -125,8 +125,8 @@ function _apply!(stab::StabilizerGPU{T},
125125
return stab
126126
end
127127

128-
function _apply!(stab::StabilizerGPU{T},
129-
gate::G;
128+
function _apply!(stab::StabilizerGPU{T},
129+
gate::G;
130130
phases::Val{B}=Val(true)) where {B, G<:QuantumClifford.AbstractTwoQubitOperator, T <: Unsigned}
131131

132132
rows = size(stab, 1)

ext/QuantumCliffordGPUExt/apply_noise.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ function applynoise!(frame::PauliFrameGPU{T},noise::UnbiasedUncorrelatedNoise,i:
1818
end
1919

2020

21-
function applynoise_kernel(xzs::DeviceMatrix{Tme},
21+
function applynoise_kernel(xzs::DeviceMatrix{Tₘₑ},
2222
p::Real,
2323
ibig::Int,
24-
ismallm::Tme,
25-
rows::Int) where {Tme <: Unsigned}
24+
ismallm::Tₘₑ,
25+
rows::Int) where {Tₘₑ <: Unsigned}
2626

2727
f = (blockIdx().x - 1) * blockDim().x + threadIdx().x;
2828
if f > rows

ext/QuantumCliffordGPUExt/pauli_frames.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# sMZ
33
##############################
44

5-
function apply_sMZ_kernel!(xzs::DeviceMatrix{Tme},
5+
function apply_sMZ_kernel!(xzs::DeviceMatrix{Tₘₑ},
66
measurements::DeviceMatrix{Bool},
77
op::sMZ,
88
ibig::Int,
9-
ismallm::Tme,
10-
rows::Int) where {Tme <: Unsigned}
9+
ismallm::Tₘₑ,
10+
rows::Int) where {Tₘₑ <: Unsigned}
1111
f = (blockIdx().x - 1) * blockDim().x + threadIdx().x;
1212
if f > rows
1313
return nothing
14-
end
14+
end
1515
should_flip = !iszero(xzs[ibig,f] & ismallm)
1616
measurements[f,op.bit] = should_flip
1717
return nothing
@@ -33,12 +33,12 @@ end
3333
# sMRZ
3434
##############################
3535

36-
function apply_sMRZ_kernel!(xzs::DeviceMatrix{Tme},
36+
function apply_sMRZ_kernel!(xzs::DeviceMatrix{Tₘₑ},
3737
measurements::DeviceMatrix{Bool},
3838
op::QuantumClifford.sMRZ,
3939
ibig::Int, # todo change to Int
40-
ismallm::Tme,
41-
rows::Int) where {Tme <: Unsigned}
40+
ismallm::Tₘₑ,
41+
rows::Int) where {Tₘₑ <: Unsigned}
4242
f = (blockIdx().x - 1) * blockDim().x + threadIdx().x;
4343
if f > rows
4444
return nothing

ext/QuantumCliffordGPUExt/types.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ DeviceMatrix{T} = Union{CuDeviceArray{T, 2, 1}, Adjoint{T, CuDeviceArray{T, 2, 1
2020

2121

2222
function getTableauGPU(GPUValue, GPUVector, GPUMatrix)
23-
TableauGPU{T} = QuantumClifford.Tableau{Tzv, Tm} where {T <: Unsigned, Tzv <: GPUVector{PhaseInnerType}, Tm <: GPUMatrix{T}}
23+
TableauGPU{T} = QuantumClifford.Tableau{Tₚᵥ, Tₘ} where {T <: Unsigned, Tₚᵥ <: GPUVector{PhaseInnerType}, Tₘ <: GPUMatrix{T}}
2424
end
2525
function getStabilizerGPU(GPUValue, GPUVector, GPUMatrix, GPUTableau)
2626
StabilizerGPU{T} = QuantumClifford.Stabilizer{<:GPUTableau{T}} where {T <: Unsigned}
2727
end
2828
function getPauliOperatorGPU(GPUValue, GPUVector, GPUMatrix, GPUTableau)
29-
PauliOperatorGPU{T} = QuantumClifford.PauliOperator{Tz, Tv} where {T <: Unsigned, Tz<:GPUValue{PhaseInnerType}, Tv<:GPUVector{T}}
29+
PauliOperatorGPU{T} = QuantumClifford.PauliOperator{Tₚ, Tᵥ} where {T <: Unsigned, Tₚ<:GPUValue{PhaseInnerType}, Tᵥ<:GPUVector{T}}
3030
end
3131

3232
# todo. type definition here is stronger than the code in pauliframes.jl this will cause serious problems

src/QuantumClifford.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,18 @@ include("pauli_operator.jl")
130130
"""Internal Tableau type for storing a list of Pauli operators in a compact form.
131131
No special semantic meaning is attached to this type, it is just a convenient way to store a list of Pauli operators.
132132
E.g. it is not used to represent a stabilizer state, or a stabilizer group, or a Clifford circuit."""
133-
struct Tableau{Tzv<:AbstractVector{UInt8}, Tm<:AbstractMatrix{<:Unsigned}}
134-
phases::Tzv
133+
struct Tableau{Tₚᵥ<:AbstractVector{UInt8}, Tₘ<:AbstractMatrix{<:Unsigned}}
134+
phases::Tₚ
135135
nqubits::Int
136-
xzs::Tm
136+
xzs::Tₘ
137137
end
138138

139-
function Tableau(paulis::AbstractVector{PauliOperator{Tz,Tv}}) where {Tz<:AbstractArray{UInt8,0},Tve<:Unsigned,Tv<:AbstractVector{Tve}}
139+
function Tableau(paulis::AbstractVector{PauliOperator{Tₚ,Tᵥ}}) where {Tₚ<:AbstractArray{UInt8,0},Tᵥₑ<:Unsigned,Tᵥ<:AbstractVector{Tᵥₑ}}
140140
r = length(paulis)
141141
n = nqubits(paulis[1])
142-
tab = zero(Tableau{Vector{UInt8},Matrix{Tve}},r,n)::Tableau{Vector{UInt8},Matrix{Tve}} # typeassert for JET
142+
tab = zero(Tableau{Vector{UInt8},Matrix{Tᵥₑ}},r,n)::Tableau{Vector{UInt8},Matrix{Tᵥₑ}} # typeassert for JET
143143
for i in eachindex(paulis)
144-
tab[i] = paulis[i]::PauliOperator{Tz,Tv} # typeassert for JET
144+
tab[i] = paulis[i]::PauliOperator{Tₚ,Tᵥ} # typeassert for JET
145145
end
146146
tab
147147
end
@@ -172,9 +172,9 @@ end
172172
Base.getindex(tab::Tableau, i::Int) = PauliOperator(tab.phases[i], nqubits(tab), tab.xzs[:,i])
173173
@inline function Base.getindex(tab::Tableau, r::Int, c::Int)
174174
# TODO this has code repetition with the Pauli getindex
175-
Tme = eltype(tab.xzs)
176-
x = (tab.xzs[_div(Tme,c-1)+1,r] & Tme(0x1)<<_mod(Tme,c-1))!=0x0
177-
z = (tab.xzs[end÷2+_div(Tme,c-1)+1,r] & Tme(0x1)<<_mod(Tme,c-1))!=0x0
175+
Tₘₑ = eltype(tab.xzs)
176+
x = (tab.xzs[_div(Tₘₑ,c-1)+1,r] & Tₘₑ(0x1)<<_mod(Tₘₑ,c-1))!=0x0
177+
z = (tab.xzs[end÷2+_div(Tₘₑ,c-1)+1,r] & Tₘₑ(0x1)<<_mod(Tₘₑ,c-1))!=0x0
178178
return (x,z)
179179
end
180180
Base.getindex(tab::Tableau, r) = Tableau(tab.phases[r], nqubits(tab), tab.xzs[:,r])
@@ -200,16 +200,16 @@ function Base.setindex!(tab::Tableau, t::Tableau, i)
200200
tab
201201
end
202202

203-
function Base.setindex!(tab::Tableau{Tzv,Tm}, (x,z)::Tuple{Bool,Bool}, i, j) where {Tzv<:AbstractVector{UInt8}, Tme<:Unsigned, Tm<:AbstractMatrix{Tme}} # TODO this has code repetitions with the Pauli setindex
203+
function Base.setindex!(tab::Tableau{Tₚᵥ,Tₘ}, (x,z)::Tuple{Bool,Bool}, i, j) where {Tₚᵥ<:AbstractVector{UInt8}, Tₘₑ<:Unsigned, Tₘ<:AbstractMatrix{Tₘₑ}} # TODO this has code repetitions with the Pauli setindex
204204
if x
205-
tab.xzs[_div(Tme,j-1)+1, i] |= Tme(0x1)<<_mod(Tme,j-1)
205+
tab.xzs[_div(Tₘₑ,j-1)+1, i] |= Tₘₑ(0x1)<<_mod(Tₘₑ,j-1)
206206
else
207-
tab.xzs[_div(Tme,j-1)+1, i] &= ~(Tme(0x1)<<_mod(Tme,j-1))
207+
tab.xzs[_div(Tₘₑ,j-1)+1, i] &= ~(Tₘₑ(0x1)<<_mod(Tₘₑ,j-1))
208208
end
209209
if z
210-
tab.xzs[end÷2+_div(Tme,j-1)+1, i] |= Tme(0x1)<<_mod(Tme,j-1)
210+
tab.xzs[end÷2+_div(Tₘₑ,j-1)+1, i] |= Tₘₑ(0x1)<<_mod(Tₘₑ,j-1)
211211
else
212-
tab.xzs[end÷2+_div(Tme,j-1)+1, i] &= ~(Tme(0x1)<<_mod(Tme,j-1))
212+
tab.xzs[end÷2+_div(Tₘₑ,j-1)+1, i] &= ~(Tₘₑ(0x1)<<_mod(Tₘₑ,j-1))
213213
end
214214
tab
215215
end
@@ -235,7 +235,7 @@ Base.hash(t::Tableau, h::UInt) = hash(t.nqubits, hash(t.phases, hash(t.xzs, h)))
235235

236236
Base.copy(t::Tableau) = Tableau(copy(t.phases), t.nqubits, copy(t.xzs))
237237

238-
function Base.zero(::Type{Tableau{Tzv, Tm}}, r, q) where {Tzv,T<:Unsigned,Tm<:AbstractMatrix{T}}
238+
function Base.zero(::Type{Tableau{Tₚᵥ, Tₘ}}, r, q) where {Tₚᵥ,T<:Unsigned,Tₘ<:AbstractMatrix{T}}
239239
phases = zeros(UInt8,r)
240240
xzs = zeros(UInt, _nchunks(q,T), r)
241241
Tableau(phases, q, xzs)::Tableau{Vector{UInt8},Matrix{UInt}}
@@ -354,8 +354,8 @@ struct Stabilizer{T<:Tableau} <: AbstractStabilizer
354354
tab::T
355355
end
356356

357-
Stabilizer(phases::Tzv, nqubits::Int, xzs::Tm) where {Tzv<:AbstractVector{UInt8}, Tm<:AbstractMatrix{<:Unsigned}} = Stabilizer(Tableau(phases, nqubits, xzs))
358-
Stabilizer(paulis::AbstractVector{PauliOperator{Tz,Tv}}) where {Tz,Tv} = Stabilizer(Tableau(paulis))
357+
Stabilizer(phases::Tₚ, nqubits::Int, xzs::Tₘ) where {Tₚᵥ<:AbstractVector{UInt8}, Tₘ<:AbstractMatrix{<:Unsigned}} = Stabilizer(Tableau(phases, nqubits, xzs))
358+
Stabilizer(paulis::AbstractVector{PauliOperator{Tₚ,Tᵥ}}) where {Tₚ,Tᵥ} = Stabilizer(Tableau(paulis))
359359
Stabilizer(phases::AbstractVector{UInt8}, xs::AbstractMatrix{Bool}, zs::AbstractMatrix{Bool}) = Stabilizer(Tableau(phases, xs, zs))
360360
Stabilizer(phases::AbstractVector{UInt8}, xzs::AbstractMatrix{Bool}) = Stabilizer(Tableau(phases, xzs))
361361
Stabilizer(xs::AbstractMatrix{Bool}, zs::AbstractMatrix{Bool}) = Stabilizer(Tableau(xs,zs))
@@ -832,13 +832,13 @@ end
832832
# TODO is this used anywhere?
833833
"""Swap two columns of a stabilizer in place."""
834834
@inline function colswap!(s::Tableau, i, j)
835-
Tme = eltype(s.xzs)
836-
lowbit = Tme(1)
837-
ibig = _div(Tme,i-1)+1
838-
ismall = _mod(Tme,i-1)
835+
Tₘₑ = eltype(s.xzs)
836+
lowbit = Tₘₑ(1)
837+
ibig = _div(Tₘₑ,i-1)+1
838+
ismall = _mod(Tₘₑ,i-1)
839839
ismallm = lowbit<<(ismall)
840-
jbig = _div(Tme,j-1)+1
841-
jsmall = _mod(Tme,j-1)
840+
jbig = _div(Tₘₑ,j-1)+1
841+
jsmall = _mod(Tₘₑ,j-1)
842842
jsmallm = lowbit<<(jsmall)
843843
for off in [0,size(s.xzs,2)÷2]
844844
ibig += off

src/dense_cliffords.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ function _apply!(stab::AbstractStabilizer, c::CliffordOperator; phases::Val{B}=V
136136
end
137137

138138
# TODO Added a lot of type assertions to help Julia infer types, but they are much too strict for cases where bitpacking varies (check tests)
139-
#@inline function apply_row_kernel!(new_stabrow::PauliOperator{Array{UInt8,0},Vector{Tme}}, row::Int, s_tab::Stabilizer{Tv,Tm}, c_tab::Stabilizer{Tv,Tm}; phases=true) where {Tme,Tv<:AbstractVector{UInt8},Tm<:AbstractMatrix{Tme}}
140139
@inline function apply_row_kernel!(new_stabrow, row, s_tab, c_tab; phases::Val{B}=Val(true)) where B
141140
B && (new_stabrow.phase[] = s_tab.phases[row])
142141
n = nqubits(c_tab)

src/fastmemlayout.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ but it is still optimal given that some bitwrangling is required to extract a gi
1515
See also: [`fastrow`](@ref)"""
1616
function fastcolumn end
1717

18-
fastrow(t::Tableau{Tzv,Tm}) where {Tzv, Tm} = t
19-
fastrow(t::Tableau{Tzv,Tm}) where {Tzv, Tm<:Adjoint} = Tableau(t.phases, t.nqubits, collect(t.xzs))
20-
fastcolumn(t::Tableau{Tzv,Tm}) where {Tzv, Tm} = Tableau(t.phases, t.nqubits, collect(t.xzs')')
21-
fastcolumn(t::Tableau{Tzv,Tm}) where {Tzv, Tm<:Adjoint} = t
18+
fastrow(t::Tableau{Tₚᵥ,Tₘ}) where {Tₚᵥ, Tₘ} = t
19+
fastrow(t::Tableau{Tₚᵥ,Tₘ}) where {Tₚᵥ, Tₘ<:Adjoint} = Tableau(t.phases, t.nqubits, collect(t.xzs))
20+
fastcolumn(t::Tableau{Tₚᵥ,Tₘ}) where {Tₚᵥ, Tₘ} = Tableau(t.phases, t.nqubits, collect(t.xzs')')
21+
fastcolumn(t::Tableau{Tₚᵥ,Tₘ}) where {Tₚᵥ, Tₘ<:Adjoint} = t
2222

2323
fastrow(s::Stabilizer) = Stabilizer(fastrow(s.tab))
2424
fastcolumn(s::Stabilizer) = Stabilizer(fastcolumn(s.tab))

src/misc_ops.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
Particularly useful when acting on [`Register`](@ref).
55
66
See also: [`apply!`](@ref), [`projectrand!`](@ref)."""
7-
struct PauliMeasurement{Tz<:AbstractArray{UInt8,0}, Tv<:AbstractVector{<:Unsigned}} <: AbstractMeasurement
8-
pauli::PauliOperator{Tz,Tv}
7+
struct PauliMeasurement{Tₚ<:AbstractArray{UInt8,0}, Tᵥ<:AbstractVector{<:Unsigned}} <: AbstractMeasurement
8+
pauli::PauliOperator{Tₚ,Tᵥ}
99
bit::Int
1010
end
1111

src/pauli_operator.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ julia> p[1] = (true, true); p
3939
+ YYZ
4040
```
4141
"""
42-
struct PauliOperator{Tz<:AbstractArray{UInt8,0}, Tv<:AbstractVector{<:Unsigned}} <: AbstractCliffordOperator
43-
phase::Tz
42+
struct PauliOperator{Tₚ<:AbstractArray{UInt8,0}, Tᵥ<:AbstractVector{<:Unsigned}} <: AbstractCliffordOperator
43+
phase::Tₚ
4444
nqubits::Int
45-
xz::Tv
45+
xz::T
4646
end
4747

48-
PauliOperator(phase::UInt8, nqubits::Int, xz::Tv) where Tv<:AbstractVector{<:Unsigned} = PauliOperator(fill(UInt8(phase),()), nqubits, xz)
48+
PauliOperator(phase::UInt8, nqubits::Int, xz::T) where Tᵥ<:AbstractVector{<:Unsigned} = PauliOperator(fill(UInt8(phase),()), nqubits, xz)
4949
function PauliOperator(phase::UInt8, x::AbstractVector{Bool}, z::AbstractVector{Bool})
5050
phase = fill(UInt8(phase),())
5151
xs = reinterpret(UInt,BitVector(x).chunks)::Vector{UInt}
@@ -87,19 +87,19 @@ macro P_str(a)
8787
quote _P_str($a) end
8888
end
8989

90-
Base.getindex(p::PauliOperator{Tz,Tv}, i::Int) where {Tz, Tve<:Unsigned, Tv<:AbstractVector{Tve}} = (p.xz[_div(Tve, i-1)+1] & Tve(0x1)<<_mod(Tve,i-1))!=0x0, (p.xz[end÷2+_div(Tve,i-1)+1] & Tve(0x1)<<_mod(Tve,i-1))!=0x0
91-
Base.getindex(p::PauliOperator{Tz,Tv}, r) where {Tz, Tve<:Unsigned, Tv<:AbstractVector{Tve}} = PauliOperator(p.phase[], xbit(p)[r], zbit(p)[r])
90+
Base.getindex(p::PauliOperator{Tₚ,Tᵥ}, i::Int) where {Tₚ, Tᵥₑ<:Unsigned, Tᵥ<:AbstractVector{Tᵥₑ}} = (p.xz[_div(Tᵥₑ, i-1)+1] & Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1))!=0x0, (p.xz[end÷2+_div(Tᵥₑ,i-1)+1] & Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1))!=0x0
91+
Base.getindex(p::PauliOperator{Tₚ,Tᵥ}, r) where {Tₚ, Tᵥₑ<:Unsigned, Tᵥ<:AbstractVector{Tᵥₑ}} = PauliOperator(p.phase[], xbit(p)[r], zbit(p)[r])
9292

93-
function Base.setindex!(p::PauliOperator{Tz,Tv}, (x,z)::Tuple{Bool,Bool}, i) where {Tz, Tve, Tv<:AbstractVector{Tve}}
93+
function Base.setindex!(p::PauliOperator{Tₚ,Tᵥ}, (x,z)::Tuple{Bool,Bool}, i) where {Tₚ, Tᵥₑ, Tᵥ<:AbstractVector{Tᵥₑ}}
9494
if x
95-
p.xz[_div(Tve,i-1)+1] |= Tve(0x1)<<_mod(Tve,i-1)
95+
p.xz[_div(Tᵥₑ,i-1)+1] |= Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1)
9696
else
97-
p.xz[_div(Tve,i-1)+1] &= ~(Tve(0x1)<<_mod(Tve,i-1))
97+
p.xz[_div(Tᵥₑ,i-1)+1] &= ~(Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1))
9898
end
9999
if z
100-
p.xz[end÷2+_div(Tve,i-1)+1] |= Tve(0x1)<<_mod(Tve,i-1)
100+
p.xz[end÷2+_div(Tᵥₑ,i-1)+1] |= Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1)
101101
else
102-
p.xz[end÷2+_div(Tve,i-1)+1] &= ~(Tve(0x1)<<_mod(Tve,i-1))
102+
p.xz[end÷2+_div(Tᵥₑ,i-1)+1] &= ~(Tᵥₑ(0x1)<<_mod(Tᵥₑ,i-1))
103103
end
104104
p
105105
end
@@ -123,13 +123,13 @@ Base.hash(p::PauliOperator, h::UInt) = hash(p.phase,hash(p.nqubits,hash(p.xz, h)
123123
Base.copy(p::PauliOperator) = PauliOperator(copy(p.phase),p.nqubits,copy(p.xz))
124124

125125
_nchunks(i::Int,T::Type{<:Unsigned}) = 2*( (i-1) ÷ (8*sizeof(T)) + 1 )
126-
Base.zero(::Type{PauliOperator{Tz, Tv}}, q) where {Tz,T<:Unsigned,Tv<:AbstractVector{T}} = PauliOperator(zeros(UInt8), q, zeros(T, _nchunks(q,T)))
126+
Base.zero(::Type{PauliOperator{Tₚ, Tᵥ}}, q) where {Tₚ,T<:Unsigned,Tᵥ<:AbstractVector{T}} = PauliOperator(zeros(UInt8), q, zeros(T, _nchunks(q,T)))
127127
Base.zero(::Type{PauliOperator}, q) = zero(PauliOperator{Array{UInt8, 0}, Vector{UInt}}, q)
128128
Base.zero(p::P) where {P<:PauliOperator} = zero(P, nqubits(p))
129129

130130
"""Zero-out the phases and single-qubit operators in a [`PauliOperator`](@ref)"""
131-
@inline function zero!(p::PauliOperator{Tz,Tv}) where {Tz, Tve<:Unsigned, Tv<:AbstractVector{Tve}}
132-
fill!(p.xz, zero(Tve))
131+
@inline function zero!(p::PauliOperator{Tₚ,Tᵥ}) where {Tₚ, Tᵥₑ<:Unsigned, Tᵥ<:AbstractVector{Tᵥₑ}}
132+
fill!(p.xz, zero(Tᵥₑ))
133133
p.phase[] = 0x0
134134
p
135135
end

0 commit comments

Comments
 (0)