MPS usage with NetworkState in cuQuantum python produces integer overflow
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- python
- Lĩnh vực
- quantum-computing
Hướng nghiên cứu
Bắt đầu tại python/cuquantum/tensornet/experimental/network_state.py, khoảng các dòng 835–840, và chạy bản tái hiện tối thiểu từ issue với n=64 và max_extent=2. Theo dõi cách các extents được kết hợp trước khi tính giá trị kỳ vọng; hoàn tất khi bản tái hiện chạy xong mà không gặp ValueError về extents âm và trả về một giá trị kỳ vọng khớp với các thư viện khác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Jupyter Notebook
- Star
- 503
- Fork
- 102
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của NVIDIA/cuQuantum
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 94/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 57/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 8/100
-
CUDA 12 cuquantum-appliance image ships a UCX `libucm_cuda.so.0` linked against `libcudart.so.13`Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
-
`cutensornetTensorSVD` returns `CUTENSORNET_STATUS_INTERNAL_ERROR` with missing host workspaceĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Tất cả issue của NVIDIA/cuQuantum
Issue tương tự
-
Built-in QUBO fallback applies bitwise xor to floating binary statesCó thể đã có người làm @iloveeyjafjalla đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
qboson/kaiwu-pytorch-plugin#1702 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
sandialabs/LoQS#166 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
sandialabs/pyGSTi#956 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
NVIDIA/cudaq-algorithms#77 ·
Maintainer thường phản hồi trong vòng 7 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Qiskit/documentation#5839 ·
Maintainer thường phản hồi trong vòng 1 ngày