-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Memory layout optimizations and removing Polyester (#143)
- Loading branch information
Showing
14 changed files
with
134 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Convert a tableau to a memory layout that is fast for row operations. | ||
In this layout a Pauli string (a row of the tableau) is stored contiguously in memory. | ||
See also: [`fastrow`](@ref)""" | ||
function fastrow end | ||
|
||
"""Convert a tableau to a memory layout that is fast for column operations. | ||
In this layout a column of the tableau is stored (mostly) contiguously in memory. | ||
Due to bitpacking, e.g., packing 64 bits into a single `UInt64`, | ||
the memory layout is not perfectly contiguous, | ||
but it is still optimal given that some bitwrangling is required to extract a given bit. | ||
See also: [`fastrow`](@ref)""" | ||
function fastcolumn end | ||
|
||
fastrow(t::Tableau{Tzv,Tm}) where {Tzv, Tm} = t | ||
fastrow(t::Tableau{Tzv,Tm}) where {Tzv, Tm<:Adjoint} = Tableau(t.phases, t.nqubits, collect(t.xzs)) | ||
fastcolumn(t::Tableau{Tzv,Tm}) where {Tzv, Tm} = Tableau(t.phases, t.nqubits, collect(t.xzs')') | ||
fastcolumn(t::Tableau{Tzv,Tm}) where {Tzv, Tm<:Adjoint} = t | ||
|
||
fastrow(s::Stabilizer) = Stabilizer(fastrow(s.tab)) | ||
fastcolumn(s::Stabilizer) = Stabilizer(fastcolumn(s.tab)) | ||
|
||
fastrow(s::Destabilizer) = Destabilizer(fastrow(s.tab)) | ||
fastcolumn(s::Destabilizer) = Destabilizer(fastcolumn(s.tab)) | ||
|
||
fastrow(s::MixedStabilizer) = MixedStabilizer(fastrow(s.tab), s.rank) | ||
fastcolumn(s::MixedStabilizer) = MixedStabilizer(fastcolumn(s.tab), s.rank) | ||
|
||
fastrow(s::MixedDestabilizer) = MixedDestabilizer(fastrow(s.tab), s.rank) | ||
fastcolumn(s::MixedDestabilizer) = MixedDestabilizer(fastcolumn(s.tab), s.rank) | ||
|
||
fastrow(s::PauliFrame) = PauliFrame(fastrow(s.frame), s.measurements) | ||
fastcolumn(s::PauliFrame) = PauliFrame(fastcolumn(s.frame), s.measurements) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Random | ||
using QuantumClifford | ||
using Test | ||
|
||
@testset "Column-fast vs row-fast operations" begin | ||
for n in [3, 300] | ||
for T in (Stabilizer, Destabilizer, MixedStabilizer, MixedDestabilizer) | ||
s = T(random_stabilizer(n,n)) | ||
@test fastrow(copy(s)) == fastrow(fastcolumn(copy(s))) # TODO should not need to convert to the same layout for comparisons | ||
@test canonicalize!(fastrow(copy(s))) == fastrow(canonicalize!(fastcolumn(copy(s)))) # TODO should not need to convert to the same layout for comparisons | ||
c = random_clifford(n) | ||
layouts = [] | ||
for layout in (fastrow, fastcolumn) | ||
ss = layout(copy(s)) | ||
@test typeof(ss) == typeof(deepcopy(ss)) | ||
apply!(ss, c) | ||
apply!(ss, sCNOT(1,n-1)) | ||
push!(layouts, ss) | ||
end | ||
@test fastrow(copy(layouts[1])) == fastrow(copy(layouts[2])) | ||
end | ||
end | ||
end |
14ee2c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
14ee2c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/86865
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: