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

Abierto
#1,129 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@aadityarshah ya está trabajando en esto.

Desde el 15/10/2026.

  • #1130 de @aadityarshah — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cpp
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C++
Estrellas
702
Forks
219
Merge medio
1 d 2 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de quantumlib/qsim

Todos los issues de quantumlib/qsim

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.