lanl-ansi / QuantumAnnealing.jl

Tools for the Simulation and Execution of Quantum Annealing Algorithms
Other
23 stars 5 forks source link

StackOverflowError Issue #14

Closed ccoffrin closed 2 years ago

ccoffrin commented 2 years ago

I am getting a ERROR: StackOverflowError: when building a system with 9 or more qubits. Tested on Julia v1.7.0.

MWE:

using QuantumAnnealing
n = 9
@time ρ = simulate(Dict((i,) => 1.0 for i in 1:n), 1.0, AS_CIRCULAR)
zmorrell commented 2 years ago

@ccoffrin That is a surprisingly low number of qubits. I just tried to replicate on my own machine and was able to get up to 12 qubits successfully, with the process being killed (likely due to lack of memory) at 13 qubits. The following is my output. I am running Julia 1.7.1 on a system with 8 GB of RAM. I do agree that we should ideally improve the scalability, I am just surprised that we are having such a large difference in number of qubits and error modes.

n = 12

iter |  steps  |    max(Δ)    |    mean(Δ)   |
   1 |       4 | 5.372611e-03 | 3.621762e-05 |
   2 |       8 | 4.046612e-05 | 4.065840e-07 |

converged
   iterations........: 2
   simulation steps..: 8
   maximum difference: 4.046612e-05 <= 1.000000e-04
   mean difference...: 4.065840e-07 <= 1.000000e-06
   runtime (seconds).: 531.093272

534.307696 seconds (22.98 M allocations: 42.642 GiB, 4.51% gc time, 2.05% compilation time)
n = 13

iter |  steps  |    max(Δ)    |    mean(Δ)   |
Killed
ccoffrin commented 2 years ago

Thanks for double checking this. I confirmed the issue was in Julia, I updated to 1.7.2 on OS X and it resolved the issue. The code easily scaled to 12 qubits on a MacBook Pro with 32GB of memory. At 13 qubits CPU time is currently the primary bottle neck.

I started using this for testing to see how far I can go,

for n in 1:20
    println("qubits: $(n)")
    @time ρ = simulate(Dict((i,) => 1.0 for i in 1:n), 1.0, AS_CIRCULAR, 2);
end
ccoffrin commented 2 years ago

As the stack overflow issue is resolved I am closing this in favor of #5.

For reference, here are the basic runtime and memory requirements,

qubits: 2
  0.000100 seconds (484 allocations: 38.062 KiB)
...
qubits: 4
  0.000162 seconds (806 allocations: 169.359 KiB)
...
qubits: 8
  0.044671 seconds (1.95 k allocations: 20.817 MiB, 52.92% gc time)
qubits: 9
  0.134527 seconds (2.37 k allocations: 84.108 MiB, 29.86% gc time)
qubits: 10
  0.583697 seconds (2.80 k allocations: 328.743 MiB, 21.82% gc time)
qubits: 11
  2.883114 seconds (3.43 k allocations: 1.269 GiB, 8.99% gc time)
qubits: 12
 21.319456 seconds (4.07 k allocations: 5.041 GiB, 4.27% gc time)
qubits: 13
172.125511 seconds (4.69 k allocations: 20.092 GiB, 1.27% gc time)
qubits: 14
1497.746993 seconds (5.36 k allocations: 80.195 GiB, 0.30% gc time)
...

Basic memory requirements (without matrix exponentiation),

qubits: 9
  0.006588 seconds (2.31 k allocations: 15.519 MiB)
qubits: 10
  0.031300 seconds (2.74 k allocations: 55.468 MiB, 22.60% gc time)
qubits: 11
  0.104134 seconds (3.37 k allocations: 208.946 MiB, 6.35% gc time)
qubits: 12
  0.598221 seconds (4.00 k allocations: 804.009 MiB, 31.72% gc time)
qubits: 13
  1.642825 seconds (4.62 k allocations: 3.079 GiB, 10.64% gc time)
qubits: 14
  6.358479 seconds (5.29 k allocations: 12.167 GiB, 8.27% gc time)
qubits: 15
126.56007 seconds (6.01 k allocations: 48.373 GiB, 0.62% gc time)
qubits: 16
... killed (OOM)