Skip to content

Commit 671b3fd

Browse files
author
Jan Lukas @ Servercraft
committed
Fixed integer overflow in measure
1 parent f5eda5a commit 671b3fd

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FLOYao"
22
uuid = "6d9310a3-f1d0-41b7-8edb-11c1cf57cd2d"
33
authors = ["janlukas.bosse <[email protected]> and contributors"]
4-
version = "1.6.3"
4+
version = "1.6.4"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

docs/src/vqe_example.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@ samples = measure(reg |> circuit, nshots=10, rng=MersenneTwister(42))
217217
# output
218218
219219
10-element Vector{BitStr{100, BigInt}}:
220-
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ₍₂₎
221-
0000000000000000000000000000000000000000101000000110000000000000000000000000000000000000000000000000 ₍₂₎
222-
0000000000000000000000000000000000000000000000000000000000001101100000000011001100000001100000000000 ₍₂₎
223-
0000000000000000000000000000000000000000000000000000000000000000000000000011000110000001010011000000 ₍₂₎
220+
0000000000000000000000000001111000000000000000000000000000000000000000000000000000000000000000000000 ₍₂₎
221+
0000000000000000000110011000000000000000101000000110000000000000000000000000000000000000000000000000 ₍₂₎
222+
0000000000011000110000000000000000000000000000000000000000001101100000000011001100000001100000000000 ₍₂₎
223+
1100000000000000000000001111000110000000000000000000000000000000000000000011000110000001010011000000 ₍₂₎
224224
0000000000000000000000000000000000000000000000000000000000001010000110000000000000000000000000000000 ₍₂₎
225-
0000000000000000000000000000000000000000100100000011000000011000000000000000000000000000110000000000 ₍₂₎
226-
0000000000000000000000000000000000000000000110000000000000110000100100000000000000110000000000000011 ₍₂₎
227-
0000000000000000000000000000000000000010100000000000000000000000001100000000000110000000000000000000 ₍₂₎
228-
0000000000000000000000000000000000000001101100000000000000000000000000000000000000000011000000000000 ₍₂₎
229-
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ₍₂₎
225+
0000000000000000000000000000110000000000100100000011000000011000000000000000000000000000110000000000 ₍₂₎
226+
1100000001100000001100110000000000000000000110000000000000110000100100000000000000110000000000000011 ₍₂₎
227+
0000000000000000101000000000000000000010100000000000000000000000001100000000000110000000000000000000 ₍₂₎
228+
0000000000000000000000000001100000000001101100000000000000000000000000000000000000000011000000000000 ₍₂₎
229+
0101000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000 ₍₂₎
230230
```

src/measure.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ end
9393
for i in 1:nq
9494
pi = (1 + covmat[2i-1,2i]) / 2
9595
ni = rand(rng) > pi
96-
out += ni * 2^(i-1)
96+
out += ni * BigInt(2)^(i-1)
9797
update_covariance_matrix!(covmat, i, ni ? 1-pi : pi, ni)
9898
end
9999
return out

test/runtests.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ end
9696

9797
# and checking integer overflow stuff
9898
# This first one is currently broken, but not our fault...
99-
# r1 = FLOYao.product_state(Float32, lbit"11111111111111111111111111111111111111111111111111111111111111111")
99+
r1 = FLOYao.product_state(Float32, Yao.lbit"11111111111111111111111111111111111111111111111111111111111111111")
100100
r2 = FLOYao.product_state(Float32, ones(Int, 65))
101101
r3 = FLOYao.product_state(Float32, 65, BigInt(2)^66 - 1)
102102
@test r2 r3
@@ -506,6 +506,13 @@ end
506506
mhist = StatsBase.normalize(fit(Histogram, Int.(msamples), nbins=2^3), mode=:probability)
507507
ahist = StatsBase.normalize(fit(Histogram, Int.(asamples), nbins=2^3), mode=:probability)
508508
@test sum(abs, ahist.weights - mhist.weights) < 0.01
509+
510+
511+
# and with more than 64 qubits
512+
bit_str = Yao.lbit"100101010010100101010010100101010010010010101001010010101001010010101001"
513+
mreg = FLOYao.product_state(bit_str)
514+
sample = measure(mreg) |> only
515+
@test sample == bit_str
509516
end
510517

511518
@testset "utils" begin

0 commit comments

Comments
 (0)