MPS usage with NetworkState in cuQuantum python produces integer overflow
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- python
- Área
- quantum-computing
Línea de trabajo
Comienza en python/cuquantum/tensornet/experimental/network_state.py alrededor de las líneas 835–840 y ejecuta la reproducción mínima del issue con n=64 y max_extent=2. Traza cómo se combinan los extents antes del cálculo de la expectativa; se considera terminado cuando la reproducción se completa sin el ValueError de extents negativos y devuelve un valor esperado que coincide con el de otras bibliotecas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I am using an MPS simulator in the Python version of cuQuantum to compute expectation values. After defining a NetworkState with a small number of qubits and a small bond dimension (max_extent), and after defining a simple NetworkOperator to measure, the code crashes with ValueError: extents must be non-negative. This crash with small number of qubits, small bond dimension, and simple observables is not expected, and the expectation value should be feasible to compute. The code producing the crash can be found here:
The root cause of this issue is that the bounding of the maximum extent happens after the cumulative product, allowing the cumulative product to grow without any restriction. That results on an integer overflow even when computing, for example, the expectation value of a simple Hamiltonian for a 64-node qubit system, which should be completely feasible using an MPS representation of the state.
The following minimal code gives a way of reproducing the crash. Note that it only applies an H gate to qubit 0, and the observable is a single Pauli Z on such qubit (a simple circuit and a simple observable):
import numpy as np
from cuquantum.tensornet.experimental import (
NetworkState,
NetworkOperator,
MPSConfig,
)
def minimal_repro(n=100, q=0, max_extent=64):
dtype = np.complex128
H = np.array(
[[1, 1],
[1, -1]],
dtype=dtype,
) / np.sqrt(2)
Z = np.array(
[[1, 0],
[0, -1]],
dtype=dtype,
)
state = NetworkState(
[2] * n,
dtype="complex128",
config=MPSConfig(max_extent=max_extent),
)
try:
state.apply_tensor_operator(
(q,),
H,
unitary=True,
)
op = NetworkOperator([2] * n, dtype="complex128")
op.append_product(
1.0,
((q,),),
(Z,),
)
value = state.compute_expectation(
op,
release_workspace=True,
)
print(f"SUCCESS: n={n}, q={q}, value={value}")
finally:
state.free()
if __name__ == "__main__":
minimal_repro(n=64, q=0, max_extent=2)
The crash only happens for values of n greater or equal than 64, reinforcing the integer overflow idea (which makes the resulting number really big and negative).
I have solved this bug locally via the following code:
cap = EXACT_MPS_EXTENT_LIMIT
if max_extent is not None:
cap = min(cap, int(max_extent))
def bounded_cumprod(extents, cap):
values = []
product = 1
for extent in extents:
product *= int(extent)
if product > cap:
product = cap
values.append(product)
return values
combined_extents_left = bounded_cumprod(self.state_mode_extents[:-1], cap)
combined_extents_right = bounded_cumprod(self.state_mode_extents[::-1], cap)[::-1][1:]
which works and returns expectation values matching other libraries
- Lenguaje dominante
- Jupyter Notebook
- Estrellas
- 502
- Forks
- 102
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de NVIDIA/cuQuantum
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 94/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 8/100
-
CUDA 12 cuquantum-appliance image ships a UCX `libucm_cuda.so.0` linked against `libcudart.so.13`Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
-
`cutensornetTensorSVD` returns `CUTENSORNET_STATUS_INTERNAL_ERROR` with missing host workspaceAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Todos los issues de NVIDIA/cuQuantum
Issues similares
-
content 📄
Dificultad 1/5 1-3 horas Aptitud para principiantes 68/100
Qiskit/documentation#5808 ·
Los mantenedores suelen responder en 1 día
-
[Bug] Reusing a parameter name on two gates fails on Qiskit only (name conflict adding parameter)Posiblemente ocupada @Imad2702 la tomó hoy. Abiertobug enhancement good-first-issue qumat
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
apache/mahout#1509 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
qiskit_to_tk converts PauliEvolutionGate with half the evolution time and reversed qubit orderAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Quantinuum/pytket-qiskit#557 ·
-
bug needs triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
dwavesystems/dwave-gate#93 · 1 comentario ·
Los mantenedores suelen responder en 1 día