-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cirq 1.0 statevector return type requirements for simulators consume more RAM after a qsim run #6107
Comments
Solving this piecewise:
Ideally, the Python buffer should be gone, and we only have 1 buffer in C++, but this is not blocking the quick solution for allocation 3 and 4. This might be sufficient for our use case. |
On 30 qubits, for this circuit, removing the copy operation reduces the elapsed: from memory_profiler import memory_usage
import time
import cirq
import qsimcirq
def f():
num_qubits = 30
qc_cirq = cirq.Circuit()
qubits = cirq.LineQubit.range(num_qubits)
for i in range(num_qubits):
qc_cirq.append(cirq.H(qubits[i]))
sim = qsimcirq.QSimSimulator()
tic = time.time()
# sim = cirq.Simulator()
sim.simulate(qc_cirq)
print("Elapsed", time.time() - tic)
print("Max memory", max(memory_usage(f)))
9 GiB is about 1 GiB more from an array of 2^30 Edit: benchmark was run on cuQuantum Appliance 23.06 (Cirq 1.1.0, qsimcirq 0.15.0) |
The benchmark on cuQuantum Appliance 22.11 (Cirq 0.14.1, qsimcirq 0.12.1), before the large memory usage was introduced:
|
Point no. 3 in the original post is not an allocation. It's just a view, but already has been removed by @NoureldinYosri in quantumlib/qsim@0009bc4. |
The return type of the qsim simulator is if you just want the state vector you can use |
Yeah, I'm aware of |
I suppose the question is whether we want to create a version of StateVectorTrialResult that doesn't use buffers. this will reduce its memory footprint but at the cost of perfomance. StateVectorTrialResult was written with perfomance in mind so creating a version of it that uses less memory will hurt perfomance. feel free to create a feature request for the unbuffered version of StateVectorTrialResult and we can discuss it there. |
Description of the issue
First reported in quantumlib/qsim#612. Cirq
~=1.0
requires qsimcirq to return its simulation output as acirq.StateVectorTrialResult
. In the current implementation, it causes an OOM when running a 32-qubit circuit on an a2-highgpu-1g, with a RAM of 85 GB. But it used to be not the case in qsimcirq 0.13.In the specific case when the statevector is final (no further operations on the statevector are needed after the simulation), this construction is expensive as it requires, at one point, 3x-4x more RAM than is necessary. The allocations are:
scratch
?The simulation output viewed as an array ofnp.complex64
this view has been removed by @NoureldinYosri (https://github.com/quantumlib/qsim/blob/7b921299e53073e1f4e35c9b349dcf9655d76b63/qsimcirq/qsim_simulator.py#L561 in quantumlib/qsim@0009bc4)this shouldn't cause any extra RAM because it's just a viewA quick modification on a live Cirq 1.1.0 install, where I removed the
state_vector = state_vector.copy()
, resulted in the OOM error gone. But it seems that the extra RAM consumption could be further reduced.How to reproduce the issue
Steps to reproduce and the output can be found in quantumlib/qsim#612 (comment).
Cirq version
~= 1.0
cc: @daxfohl @95-martin-orion @sergeisakov
The text was updated successfully, but these errors were encountered: