# Finding the maximum number of Q# simulatable qubits

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.

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.

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.

• 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. Aug 15, 2018 at 23:14
• Why does python use so much more space for double-precision numbers ?? Aug 15, 2018 at 23:37
• @AlanGeller Shouldn't double be 64 bits? This would also fit with the 16GB=30qubits quoted by the asker. Aug 16, 2018 at 0:10
• @user1271772 In which way would a "more sophisticated simulator" be able to surpass this limitation? Aug 16, 2018 at 0:11
• @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. Aug 16, 2018 at 15:42