`MPSStateSpace::SampleOnce` crashes for two-qubit states

Aperta
#1,129 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@aadityarshah ci sta già lavorando.

Dal 15/10/2026.

  • #1130 di @aadityarshah — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Start at the reduced-density-matrix contraction inside MPSStateSpace::SampleOnce in lib/mps_statespace.h, near line 536, where the Eigen resize assertion fires. Build the reproducer from the issue with a two-qubit, bond-dimension-4 zero state and confirm the 4x2 versus 2x2 shape mismatch. Done means the call returns a two-bit sample without aborting, and the matrix shapes agree with the bond dimensions of the MPS tensors.

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

Descrizione

Describe the issue

MPSStateSpace::SampleOnce() aborts with an Eigen dimension assertion when sampling a two-qubit MPS state.

Tell us how to reproduce the issue

To reproduce the issue, create a two-qubit MPS with bond dimension 4, initialize it to the zero state, allocate two scratch states of the same dimensions, and call SampleOnce():

auto ss = MPSStateSpace<For, float>(1);
auto mps = ss.Create(2, 4);
auto scratch = ss.Create(2, 4);
auto scratch2 = ss.Create(2, 4);
std::mt19937 rand_source(1234);
std::vector<bool> results;

ss.SetStateZero(mps);
ss.SampleOnce(mps, scratch, scratch2, &rand_source, &results);

The call aborts with an Eigen assertion:

Eigen::DenseBase<...>::resize(...)
Assertion `rows == this->rows() && cols == this->cols()
&& "DenseBase::resize() does not actually allow to resize."' failed.

The failure occurs at lib/mps_statespace.h:536, during the final reduced-density-matrix contraction.

GDB reports that the destination matrix is mapped as 4 x 2, whereas the multiplication produces a 2 x 2 result.

The expectation is that SampleOnce() should return a two-bit sample for a valid two-qubit MPS state without aborting.

Tell us the version of qsim or qsimcirq (if relevant)

No response

Tell us the computing environment (if relevant)

Ubuntu 26.04.1 LTS, GCC 15.2.0, C++17.

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.