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

Open Beginner friendly
#110 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 8 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python
Domain
backend

Research direction

Start in python/cudaq_algorithms/pauli_lcu.py at the constructor around line 510, where identity terms are accumulated and alpha is derived before kernel_args/angles are built. Run the provided reproducer against qpp-cpu to confirm the infinite alpha and finite alpha with infinite constant_term; then check the existing PauliLCU tests for the constructor's expected validation style. Done means nonfinite accumulated normalization or identity offset raises a clear exception, while zero, signed, and valid negative coefficients keep their current behavior.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
19
Forks
18
Avg merge
5d 18h
Merged PRs (30d)
14

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/cudaq-algorithms

All issues in NVIDIA/cudaq-algorithms

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.