PauliLCU accepts finite coefficients whose normalization overflows, producing incorrect PREPARE weights

Aperta Adatta ai principianti
#110 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 8 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
numpy, python
Ambito
backend

Direzione di ricerca

Inizia in python/cudaq_algorithms/pauli_lcu.py nel costruttore intorno alla riga 510, dove i termini di identità vengono accumulati e alpha viene derivato prima che vengano costruiti kernel_args/angoli. Esegui il reproducer fornito contro qpp-cpu per confermare l'alpha infinito e l'alpha finito con constant_term infinito; poi controlla i test PauliLCU esistenti per lo stile di validazione atteso del costruttore. Fatto significa che una normalizzazione accumulata non finita o un offset di identità genera un'eccezione chiara, mentre i coefficienti zero, con segno e negativi validi mantengono il loro comportamento attuale.

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

Descrizione

Describe the bug

The default exact backend accepts two equal, finite coefficients whose sum of absolute values overflows. It constructs alpha == inf and angles == [0.0]. Running the resulting PREPARE returns [1, 0], although the normalized weights of two equal positive coefficients are [1/sqrt(2), 1/sqrt(2)].

The state error is approximately 0.7653668647301795. This uses the public constructor with its default coefficient threshold; no NaN or infinity is supplied by the caller.

This is an extreme-magnitude input-validation/numerical-domain defect. If the public normalization cannot be represented, rejecting the input explicitly is a valid repair; the API need not support an unrepresentable normalization.

Steps to reproduce

Install cudaq==0.17.0 and cudaq-algorithms==0.2.0, save the following as a Python file, and run it:

import cudaq
import numpy as np
from cudaq_algorithms import PauliLCU
from cudaq_algorithms.pauli_lcu import prepare

cudaq.set_target("qpp-cpu")


@cudaq.kernel
def prepare_one(angles: list[float]):
    q = cudaq.qvector(1)
    prepare(q, angles)


maximum = float.fromhex("0x1.fffffffffffffp+1023")
enc = PauliLCU([(maximum, "X"), (maximum, "Z")])
angles = enc.kernel_args[0]
actual = np.asarray(cudaq.get_state(prepare_one, angles))
print("alpha:", enc.alpha)
print("angles:", angles)
print("prepared state:", actual)
print("error:", np.linalg.norm(actual - np.array([1, 1]) / np.sqrt(2)))

offset = PauliLCU([(maximum, "I"), (maximum, "I"), (1., "X")],
                  include_identity=False)
print("excluded identity offset:", offset.constant_term, "alpha:", offset.alpha)

Observed:

alpha: inf
angles: [0.0]
prepared state: [1.+0.j 0.+0.j]
error: 0.7653668647301795
excluded identity offset: inf alpha: 1.0

The last example shows that checking alpha alone is insufficient: summing excluded identity terms can overflow constant_term even when alpha remains finite. As a positive control, coefficients [(1.0, "X"), (1.0, "Z")] prepare the equal superposition with state error 1.11e-16.

Expected behavior

Reject nonfinite accumulated normalization or identity offsets with a clear exception, or use a documented rescaled representation that preserves the encoded operator. Do not return an apparently usable object with infinite normalization and silently changed weights.

Environment

  • CUDA-Q Algorithms: 0.2.0, installed wheel.
  • CUDA-Q: 0.17.0, reported build 1750574c92c613ff76c52fdbaa9289d864a3d640.
  • Target: qpp-cpu; Python 3.11.4; macOS 26.7.2, arm64.
  • Rechecked 2026-11-24. The installed pauli_lcu.py and common_kernels.py are byte-identical to Algorithms main at 87f8d0fe938439041bca6fc13691d89a11775e66.
  • No source/package patch was applied. No known last working version; also observed in our earlier 0.15.1-era tests.

Source and suggested repair

The constructor accumulates identity coefficients and computes sum(abs(c) ...) before dividing the masses. Validate the accumulated values before building angles: positive finite normalization and finite identity offset. Zero coefficients and signed coefficients need separate, explicit treatment; negative Hamiltonian coefficients themselves are valid.

This report concerns finite input whose accumulation overflows. Already-nonfinite coefficients are outside its scope. No matching issue was found in the public tracker search on 2026-11-24; that search is not proof that no related discussion exists.

Lingua principale
Python
Stelle
19
Fork
18
Merge medio
5g 18h
PR unite (30g)
14

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 NVIDIA/cudaq-algorithms

Tutte le issue di NVIDIA/cudaq-algorithms

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.