Skip to content

Commit

Permalink
fix for wrong SIMD mul_left! #320 (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krastanov committed Jul 23, 2024
1 parent 3ea5414 commit 1fb1783
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

# News

## v0.9.7 - 2024-07-23

- **(fix `#320`)** Fix a serious correctness bug in the SIMD implementation of Pauli string multiplication (affects the correctness of canonicalization and traceout for tableaux bigger than ~500 qubits; does not affect symbolic gates or Pauli frame simulations of any scale)
## v0.9.6 - 2024-07-12

- `inv` implementation for single-qubit "symbolic" Clifford operators (subtypes of `AbstractSingleQubitOperator`).
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumClifford"
uuid = "0525e862-1e90-11e9-3e4d-1b39d7109de1"
authors = ["Stefan Krastanov <stefan@krastanov.org> and QuantumSavory community members"]
version = "0.9.6"
version = "0.9.7"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
2 changes: 1 addition & 1 deletion src/mul_leftright.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function mul_ordered!(r::AbstractVector{T}, l::AbstractVector{T}; phases::Val{B}
r[i+len+lane] = newz1 = z1 z2
x1z2 = x1 & z2
anti_comm = (x2 & z1) x1z2
cnt2 ⊻= (newx1 newz1 x1z2) & anti_comm
cnt2 ⊻= (cnt1 newx1 newz1 x1z2) & anti_comm
cnt1 ⊻= anti_comm
end
for i in 1:length(cnt1)
Expand Down
17 changes: 16 additions & 1 deletion test/test_mul_leftright.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Test

test_sizes = [1,2,10,63,64,65,127,128,129] # Including sizes that would test off-by-one errors in the bit encoding.

@testset "Inner product between stabilizer states" begin
@testset "Pauli string multiplication" begin
for n in test_sizes
for _ in 1:20
p1 = random_pauli(n)
Expand All @@ -22,3 +22,18 @@ test_sizes = [1,2,10,63,64,65,127,128,129] # Including sizes that would test off
end
end
end

# test for #320
@testset "verify SIMD implementation" begin
for i in 1:10,
n in 1:30,
T in [UInt8, UInt16, UInt32, UInt64]
a = rand(T, n)
b = rand(T, n)
c1,c2 = QuantumClifford.mul_ordered!(copy(a),copy(b))
n1,n2 = QuantumClifford._mul_ordered_nonvec!(copy(a),copy(b))
np = ((n1 (n2<<1))&0x3)
cp = ((c1 (c2<<1))&0x3)
@test np==cp
end
end
13 changes: 13 additions & 0 deletions test/test_stabcanon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,16 @@ test_sizes = [1,2,10,63,64,65,127,128,129] # Including sizes that would test off
end
end
end

@testset "canonicalization invariants" begin
s = random_stabilizer(40,100)
ss = tensor_pow(s,20)
sa1 = canonicalize!(canonicalize_rref!(copy(ss))[1])
sa2 = canonicalize!(copy(ss))
@test sa1 == sa2
ms = MixedDestabilizer(s)
mss = tensor_pow(ms, 20)
msa1 = canonicalize!(canonicalize_rref!(copy(mss))[1])
msa2 = canonicalize!(copy(mss))
@test stabilizerview(msa1) == stabilizerview(msa2) == sa1
end

2 comments on commit 1fb1783

@Krastanov
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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/111624

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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:

git tag -a v0.9.7 -m "<description of version>" 1fb178385c2a343d3cf7148505c27bd88f7990c3
git push origin v0.9.7

Please sign in to comment.