Skip to content

Cirq 1.0 statevector return type requirements for simulators consume more RAM after a qsim run #6107

@rht

Description

@rht

Description of the issue
First reported in quantumlib/qsim#612. Cirq ~=1.0 requires qsimcirq to return its simulation output as a cirq.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:

  1. The C++ buffer of the statevector in the qsim layer. Is it scratch?
  2. The Python buffer of the statevector in the Cirq layer
  3. The simulation output viewed as an array of np.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 view
  4. The copy of the simulation output

A 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/performancekind/bug-reportSomething doesn't seem to work.status/needs-agreed-designWe want to do this, but it needs an agreed upon design before implementationtriage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked on

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions