I'm trying to work out how much memory is used for simulations of different sizes using the Aer simulator.

Here are my calculations:

$$ \text{Number of Qubits} = n $$ $$ \text{Number of Amplitudes} = 2^{n} $$ $$ \text{Array Size } = {2^n}^2 = 2^{2n} $$ $$ \text{ Memory in Bytes needed for double precision complex number } = 16 $$ $$ \text{ Memory needed (Bytes)} = 16 *2^{2n} $$


(I'm a bit confused at the exact definition of a GB of ram whether it's in powers of ten or two)

From this, simulations of circuits with over 18 qubits are rather difficult.

My questions are these:

  1. Are these calculations correct ?
  2. Does this stand true for both the shot based 'qasm-simulator' and 'statevector' simulator?
  3. AER is well coded: does it have simplifications like those described in the solution to this answer (How much memory is required to simulate a 48-qubit circuit?)?

I realise that my calculations are the worse case scenario. I think the statevector matrix would be upper triangular and so at least half of the amplitudes would be 0, meaning there would be at least some memory gained through sparse matrices ! Thank-You !


1 Answer 1

  1. Your calculations section looks correct but I think your spreadsheet is incorrect. For example if you do 16 bytes * (2^21) that's 33554432 bytes or.0336 GB or 33.6 MB. Things go quickly though for a 32 qubit simulation 16 bytes * (2^32) is 68.72 GB. You can also look at the aer source code it's using this calculation for the required memory for a statevector: https://github.com/Qiskit/qiskit-aer/blob/1a6d5df89a2e016afbb33a2d7088e6100348a7c4/src/simulators/statevector/qubitvector.hpp#L813-L819
  2. The difference between the qasm-simulator and statevector-simulator are primarily in return type. The statevector simulator and the qasm simulator (when using the statevector simulation method) work in the same way the only difference is that the statevector simulator returns the statevector instead of computing the measurement counts. However, the qasm simulator offers multiple simulation methods (see: https://qiskit.org/documentation/stubs/qiskit.providers.aer.QasmSimulator.html#qiskit.providers.aer.QasmSimulator for a list) which will have different memory and resource requirements. For example, if your circuit is made up of cliffords you can use the stabilizer simulation method and the memory requirements are much lower.
  3. That specific method is not implemented in qiskit aer to my knowledge (since it's very application specific)
  • $\begingroup$ Hi ! Are you sure about the spreadsheet being wrong? When I did a simulation of N <15 (I think it was 14, not certain) qubits, I was forced to access virtual ram on my machine which has 8 GB: it definitely wasn't 33 MB ! $\endgroup$
    – jolene
    Commented Mar 11, 2021 at 10:24
  • 2
    $\begingroup$ Yeah, I'm pretty sure. The arithmetic is fairly straightforward the issue is that extra 2*n in the exponent (I missed that before in your calculations section). It's 16 bytes * (2^n) not 16 bytes * (2^(2*n)). You can see that in the source link I put in the answer. If you're simulation was using that much memory did you profile it to see when/where it was consuming a lot of RAM? There are some known issues about memory consumption in other parts of qiskit (for example: github.com/Qiskit/qiskit-terra/issues/5895 ) $\endgroup$ Commented Mar 11, 2021 at 15:01
  • $\begingroup$ No I didn't, I mistakenly assumed it would just be the size of the simulation. That error you linked seems to be about transpilation; I know very little of the inner workings of qiskit: could this kick in when using the QAOAvariationalform function ? Thanks so much ! $\endgroup$
    – jolene
    Commented Mar 15, 2021 at 12:15
  • $\begingroup$ Yes it could be, transpile() will be used under the covers when you go to execute a QAOAVarForm circuit. The transpiler is what takes a virtual user circuit and optimizes it and converts it to something that a backend (either a real device or a simulator) can run given the constraints of that backend. So it could be transpile() or it could also be something else in Qiskit. It's hard to know exactly where the most memory is being used without profiling your example. If you want to open an issue on github for this with the example you were running we can work through it together. $\endgroup$ Commented Mar 15, 2021 at 14:36
  • $\begingroup$ Thank-you that's very kind but I've updated my qiskit version and the problem seems to have gone away .... for now ! $\endgroup$
    – jolene
    Commented Mar 16, 2021 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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