Skip to content
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

better bit-wrangling abstraction using less boilerplate #367

Merged
merged 6 commits into from
Nov 2, 2024
Merged
Changes from 1 commit
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
45 changes: 17 additions & 28 deletions src/pauli_frames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,22 @@ function apply!(frame::PauliFrame, op::sMRX) # TODO implement a faster direct ve
apply!(frame, sMRZ(op.qubit, op.bit))
end

function _get_bitmask_idxs(frame::PauliFrame, i::Int)
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved
T = eltype(frame.frame.tab.xzs)
lowbit = T(1)
ibig = _div(T, i-1) + 1
ismall = _mod(T, i-1)
ismallm = lowbit << ismall
return ibig, ismall, ismallm
end

function apply!(frame::PauliFrame, op::sMZ) # TODO sMY, and faster sMX
op.bit == 0 && return frame
i = op.qubit
xzs = frame.frame.tab.xzs
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved
T = eltype(xzs)
lowbit = T(1)
ibig = _div(T,i-1)+1
ismall = _mod(T,i-1)
ismallm = lowbit<<(ismall)
ibig, ismall, ismallm = _get_bitmask_idxs(frame,i)

@inbounds @simd for f in eachindex(frame)
should_flip = !iszero(xzs[ibig,f] & ismallm)
should_flip = !iszero(frame.frame.tab.xzs[ibig,f] & ismallm)
frame.measurements[f,op.bit] = should_flip
end

Expand All @@ -99,35 +103,25 @@ end

function apply!(frame::PauliFrame, op::sMRZ) # TODO sMRY, and faster sMRX
i = op.qubit
xzs = frame.frame.tab.xzs
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved
T = eltype(xzs)
lowbit = T(1)
ibig = _div(T,i-1)+1
ismall = _mod(T,i-1)
ismallm = lowbit<<(ismall)
ibig, ismall, ismallm = _get_bitmask_idxs(frame,i)

if op.bit != 0
@inbounds @simd for f in eachindex(frame)
should_flip = !iszero(xzs[ibig,f] & ismallm)
should_flip = !iszero(frame.frame.tab.xzs[ibig,f] & ismallm)
frame.measurements[f,op.bit] = should_flip
end
end
@inbounds @simd for f in eachindex(frame)
xzs[ibig,f] &= ~ismallm
rand(Bool) && (xzs[end÷2+ibig,f] ⊻= ismallm)
frame.frame.tab.xzs[ibig,f] &= ~ismallm
rand(Bool) && (frame.frame.tab.xzs[end÷2+ibig,f] ⊻= ismallm)
end

return frame
end

function applynoise!(frame::PauliFrame,noise::UnbiasedUncorrelatedNoise,i::Int)
p = noise.p
T = eltype(frame.frame.tab.xzs)

lowbit = T(1)
ibig = _div(T,i-1)+1
ismall = _mod(T,i-1)
ismallm = lowbit<<(ismall)
ibig, ismall, ismallm = _get_bitmask_idxs(frame,i)
p = p/3

@inbounds @simd for f in eachindex(frame)
Expand All @@ -145,12 +139,7 @@ function applynoise!(frame::PauliFrame,noise::UnbiasedUncorrelatedNoise,i::Int)
end

function applynoise!(frame::PauliFrame,noise::PauliNoise,i::Int)
T = eltype(frame.frame.tab.xzs)

lowbit = T(1)
ibig = _div(T,i-1)+1
ismall = _mod(T,i-1)
ismallm = lowbit<<(ismall)
ibig, ismall, ismallm = _get_bitmask_idxs(frame,i)

@inbounds @simd for f in eachindex(frame)
r = rand()
Expand Down
Loading