[python] cudaq.sample API assumes broadcast on nested list arguments
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.1k
- Forks
- 456
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 165
Description
Should cudaq.sample be changed to accept an explicit broadcast parameter?
Details:
cudaq.sample checks if the first argument is a 2-d array and broadcasts by passing elements of the array to the kernel.
This leads to confusion for a non-broadcasting sample that expects a nested list, for example:
@cudaq.kernel
def test_list_list(a: list[list[int]]):
qc = cudaq.qvector(3)
j = 0
for i in a:
if i[0] == 1:
x(qc[j])
j += 1
mz(qc)
print(cudaq.sample(test_list_list, [[0,1],[1,0],[1,0]]))
As a workaround, we can make kernel take a non-list first parameter:
@cudaq.kernel
def test_list_list(n: int, a: list[list[int]]):
qc = cudaq.qvector(3)
j = 0
for i in a:
if i[0] == 1:
x(qc[j])
j += 1
mz(qc)
print(cudaq.sample(test_list_list, 2, [[0,1],[1,0],[1,0]]))
Related: https://github.com/NVIDIA/cuda-quantum/issues/1809
Related: https://github.com/NVIDIA/cuda-quantum/issues/2627
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the cudaq.sample entry point and reproduce the provided test_list_list example, comparing it with the workaround that adds a leading integer parameter. Trace how nested-list arguments are classified for broadcasting. Done means the intended broadcast behavior is explicit and the nested-list case is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, quantum-computing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100