You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AerSimulator(method='matrix_product_state') aborts with an error message if the number of qubits of the circuit is greater than the maximum memory / 32 MB, regardless of the size of a generated MPS. With 16 GB RAM the number of qubits is limited to 504, which is in any case not necessary with a moderate bond dimension.
The simulation of the circuit above works fine in 1-2 sec for 504 qubits. So it should not abort with 505 qubits. Furthermore the required memory for the MPS is only about 0.3 MB and not $505 \cdot 32 = 16160$ MB!
Suggested solutions
You should keep track of the size of the generated MPS, which is bounded above by approximately $N (32 d^2 + 8 d)$ bytes, where $N$ is the number of qubits and $d$ is the maximum bond dimension. There is some overhead for list, tuple, and Ndarray structures that can be neglected for larger $d$. In my own simulation, run in Numpy, I get $N (32 d^2 + 8 d + 440)$ and which, interestingly, is several seconds faster than the qiskit simulation for larger $d.$ So one should be able to comfortably simulate 1000 qubit circuits with d = 64 (correspond to 6 entanglement blocks in a VQE ansatz) and even more so with d=2 on a 16 GB RAM device.
Another remark
You should adapt your matrix product state simulation method tutorial in qiskit: We can handle more qubits than this, but execution may take a few minutes. Try running a similar circuit with 500 qubits! Or maybe even 1000 (you can get a cup of coffee while waiting).
This is definitly not true! With constant bond dimension the matrix product state algorithm scales linearly with the number of qubits and the number of shots (as long shots $\gg d$). So if it takes about 0.1 seconds for 50 qubits, it takes about one second for 500 qubits and two seconds for 1000 qubits. That's not a few minutes and certainly not time to drink a coffee! And this is not only theoretical, I checked the linearity practically on my as well as on Aer Simulation.
The text was updated successfully, but these errors were encountered:
smiserman
changed the title
Matrix product Simulator aborts with wrong error messa
Matrix product Simulator aborts with wrong error message
Aug 29, 2023
smiserman
changed the title
Matrix product Simulator aborts with wrong error message
Matrix product state simulator aborts with wrong error message
Aug 29, 2023
// Initially, each tensor contains 2 matrices with a single complex double
// Depending on the number of 2-qubit gates,
// these matrices may double their size
// for now - compute only initial size
// later - FIXME
size_t mem_mb = 16 * 2 * num_qubits;
return mem_mb;
}
I think this function returns required memory size in byte not in MB, but by dividing this by 1000000 it returns 0.
Comment in this code says FIXME, so this should be fixed
Ok, but if you just divide this by 1000000, this is a very optimistic assumption without any information ;-). And in my opinion, the size of the MPS is not determined by the number of 2-qubit gates, but by the number of entanglement blocks (you can add any number of CNOT gates for the above EPR state without changing the bond dimension from 2) . However, you don't know this in advance, so you have to keep the maximum bond dimension tracked while calculating the MPS from the circuit, as I suggested.
Informations
What is the current behavior?
The
AerSimulator(method='matrix_product_state')
aborts with an error message if the number of qubits of the circuit is greater than the maximum memory / 32 MB, regardless of the size of a generated MPS. With 16 GB RAM the number of qubits is limited to 504, which is in any case not necessary with a moderate bond dimension.Steps to reproduce the problem
gives
What is the expected behavior?
The simulation of the circuit above works fine in 1-2 sec for 504 qubits. So it should not abort with 505 qubits. Furthermore the required memory for the MPS is only about 0.3 MB and not$505 \cdot 32 = 16160$ MB!
Suggested solutions
You should keep track of the size of the generated MPS, which is bounded above by approximately$N (32 d^2 + 8 d)$ bytes, where $N$ is the number of qubits and $d$ is the maximum bond dimension. There is some overhead for list, tuple, and Ndarray structures that can be neglected for larger $d$ . In my own simulation, run in Numpy, I get $N (32 d^2 + 8 d + 440)$ and which, interestingly, is several seconds faster than the qiskit simulation for larger $d.$ So one should be able to comfortably simulate 1000 qubit circuits with d = 64 (correspond to 6 entanglement blocks in a VQE ansatz) and even more so with d=2 on a 16 GB RAM device.
Another remark$\gg d$ ). So if it takes about 0.1 seconds for 50 qubits, it takes about one second for 500 qubits and two seconds for 1000 qubits. That's not a few minutes and certainly not time to drink a coffee! And this is not only theoretical, I checked the linearity practically on my as well as on Aer Simulation.
You should adapt your matrix product state simulation method tutorial in qiskit: We can handle more qubits than this, but execution may take a few minutes. Try running a similar circuit with 500 qubits! Or maybe even 1000 (you can get a cup of coffee while waiting).
This is definitly not true! With constant bond dimension the matrix product state algorithm scales linearly with the number of qubits and the number of shots (as long shots
The text was updated successfully, but these errors were encountered: