Required prerequisites
Describe the bug
A @dataclass used as a kernel argument works when its list[int] fields
contain only non-negative values, but launching raises
RuntimeError: std::bad_cast as soon as any list element is negative. The
same list passed as a bare list[int] argument works fine with negative
values, so the defect is specific to the struct-member marshaling path (it
behaves as if elements are cast through an unsigned type during packing).
Observed matrix:
| Case |
Result |
| dataclass, scalar fields only |
OK |
dataclass, list[int]/list[float] fields, non-negative values |
OK (tested 1-5 list fields, mixed lengths) |
dataclass, any list[int] field containing a negative value |
std::bad_cast |
bare list[int] argument containing negative values |
OK |
| captured dataclass with negative list element |
std::bad_cast |
Steps to reproduce the bug
from dataclasses import dataclass
import cudaq
cudaq.set_target("qpp-cpu")
@dataclass(slots=True)
class Args:
values: list[int]
@cudaq.kernel
def kernel(args: Args):
q = cudaq.qvector(1)
if args.values[0] < 0:
x(q[0])
cudaq.sample(kernel, Args([1])) # OK
cudaq.sample(kernel, Args([-1])) # RuntimeError: std::bad_cast
@cudaq.kernel
def bare(values: list[int]):
q = cudaq.qvector(1)
if values[0] < 0:
x(q[0])
cudaq.sample(bare, [-1]) # OK -> '1'
Expected behavior
Negative integers in a dataclass list[int] field marshal identically to
negative integers in a bare list[int] argument.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- CUDA-Q built from source at commit
0be565550f4c23affdcbed9e4eaec38d2d0915e6
- Python 3.11.x, target
qpp-cpu (library mode)
- AlmaLinux 8.10, x86_64
All reproducers below were executed and verified against this build.
Required prerequisites
Describe the bug
A
@dataclassused as a kernel argument works when itslist[int]fieldscontain only non-negative values, but launching raises
RuntimeError: std::bad_castas soon as any list element is negative. Thesame list passed as a bare
list[int]argument works fine with negativevalues, so the defect is specific to the struct-member marshaling path (it
behaves as if elements are cast through an unsigned type during packing).
Observed matrix:
list[int]/list[float]fields, non-negative valueslist[int]field containing a negative valuestd::bad_castlist[int]argument containing negative valuesstd::bad_castSteps to reproduce the bug
Expected behavior
Negative integers in a dataclass
list[int]field marshal identically tonegative integers in a bare
list[int]argument.Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
0be565550f4c23affdcbed9e4eaec38d2d0915e6qpp-cpu(library mode)All reproducers below were executed and verified against this build.