4
$\begingroup$

I'm new to Q# and I was curious on how one would find the number of Q# simulatable qubits for a specific machine. I know Microsoft has an approximation of 16GB ~ 30 qubits but I wanted a better estimation for my own machines.

I wrote this quick program that runs a loop which allocates a register of increasing size. When I get a std::bad_alloc error I then have an estimate. I'm guessing there is a better way either through a tool or some pre-written code.

$\endgroup$
1
$\begingroup$

The simple rule is:

Doubling the memory gives you one additional qubit.

So if Microsoft says that

16GB -> 30 qubits

then

 8GB -> 29 qubits
 4GB -> 28 qubits
 2GB -> 27 qubits
 ...
32GB -> 31 qubits
64GB -> 32 qubits

and so further.

This scaling, as well as the number quoted by Microsoft, can be understood from an argument as the one in the linked answer, using that

  1. each complex number equals 2 real numbers with double precision (8 bytes each), so 16 bytes are needed per comples number,

  2. to describe $N$ qubits, $2^N$ numbers are needed,

  3. and 1GB=$1024^3$ bytes

which together yields $16\cdot 2^N = x \, \mathrm{GB} = x\cdot 1024^3$ with $x$ the memory required in GB, which results in $$ N = \log_2(x\,\times 1024^3/16) = \log_2(x)+26\ . $$ For $x=16$ (i.e. 16GB of memory), $\log_2(16)=4$, and this yields exactly $$ N=30 \ \mathrm{qubits}\ , $$ which is the number quoted by Microsoft.

$\endgroup$
-1
$\begingroup$

A simple formula for the number of qubits you can simulate in almost all programs is given by this very well received answer.

After re-arranging the formula given there into a form that's much more relevant to your specific question, and changing 48 to 32 since Q# is written in C++, not python, we have:

$$ N_{\rm{qubits}} = \log_2\left( \frac{\rm{RAM}}{32} \right) $$

When $\rm{RAM} = 32\rm{GB} = 32\times 1024^3$, this formula gives 30, meaning you an simulate 30 qubits.

If you plug the amount of RAM you have, into that formula, it will give a good estimate of how many qubits you can simulate without using a more sophisticated simulator.

$\endgroup$
  • 1
    $\begingroup$ The Q# full state simulator is written in C++, not Python, so it takes only 16 bytes per double-precision number, or 32 bytes per complex number, not 48. Of course, you don't get to fill in every byte of your system's memory with the state vector; there is some overhead for the OS and the rest of the .NET runtime, etc. $\endgroup$ – Alan Geller Aug 15 '18 at 23:14
  • $\begingroup$ Why does python use so much more space for double-precision numbers ?? $\endgroup$ – user1271772 Aug 15 '18 at 23:37
  • 1
    $\begingroup$ @AlanGeller Shouldn't double be 64 bits? This would also fit with the 16GB=30qubits quoted by the asker. $\endgroup$ – Norbert Schuch Aug 16 '18 at 0:10
  • $\begingroup$ @user1271772 In which way would a "more sophisticated simulator" be able to surpass this limitation? $\endgroup$ – Norbert Schuch Aug 16 '18 at 0:11
  • $\begingroup$ @NorbertSchuch Yes, of course; my brain added an extra factor of 2... 8 bytes per double, 16 bytes per complex number and thus 16 bytes per entry in the state vector. $\endgroup$ – Alan Geller Aug 16 '18 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.