Skip to content

Provide a way to avoid copying state vector from Cirq #893

Description

@mhucka

What is your request or suggestion?

An internal user reported getting the following error with a 40 qubit simulation:

Traceback (most recent call last):
  File "/tmp/test/exact_sim.py", line 23, in <module>
    psi = qsim.simulate(circuit, qubit_order=qubits).state_vector()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib64/python3.12/site-packages/cirq/sim/simulator.py", line 496, in simulate
    return self.simulate_sweep(
           ^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib64/python3.12/site-packages/cirq/sim/simulator.py", line 511, in simulate_sweep
    return list(self.simulate_sweep_iter(program, params, qubit_order, initial_state))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib64/python3.12/site-packages/qsimcirq/qsim_simulator.py", line 560, in simulate_sweep_iter
    final_state = cirq.StateVectorSimulationState(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib64/python3.12/site-packages/cirq/sim/state_vector_simulation_state.py", line 351, in __init__
    state = _BufferedStateVector.create(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib64/python3.12/site-packages/cirq/sim/state_vector_simulation_state.py", line 84, in create
    state_vector = state_vector.copy()
                   ^^^^^^^^^^^^^^^^^^^
numpy._core._exceptions._ArrayMemoryError: Unable to allocate 8.00 TiB for an array with shape (2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2) and data type complex64

They were able to work around the problem by calling QSimSimulator()._simulate_impl() directly.

What solution or approach do you envision?

We should investigate whether the copy can be handled in a more user-friendly way.

How urgent is this for you?

P2 – needed within two quarters

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Priority: medium prioritya: performanceInvolves performance problems or improvementsa: pythonInvolves the Python code in qsima: qsimcirqInvolves the qsim-Cirq integration layercontributors welcomeHelp with this would be appreciatedno QC knowledge neededDoes not require knowledge of quantum computing

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions