Provide a way to avoid copying state vector from Cirq

Aperta
#893 14 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
18/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
cpp, python
Ambito
api

Direzione di ricerca

The failing call path runs through qsimcirq/qsim_simulator.py in simulate_sweep_iter, which builds a cirq.StateVectorSimulationState; the copy itself happens inside Cirq's state_vector_simulation_state.py, outside this repo. Read how QSimSimulator passes initial_state and what _simulate_impl returns, then decide what a user-facing option would look like. Done means a proposal agreed with maintainers, since the thread has no decision and the request is open-ended.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

a: performance a: python a: qsimcirq contributors welcome no QC knowledge needed P2
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

Lingua principale
C++
Stelle
702
Fork
219
Merge medio
1g 2h
PR unite (30g)
8

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di quantumlib/qsim

Tutte le issue di quantumlib/qsim

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.