All execution functions should be able to broadcast automatically.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.1k
- Forks
- 456
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 165
Description
Required prerequisites
- Search the issue tracker to check if your feature has already been mentioned or rejected in other issues.
Describe the feature
We have 3 execution functions: sample, observe, get_state.
We also have their async versions.
Currently observe and sample can broadcast across many parameters however get_state cant and neither can any of the async versions.
import cudaq
from cudaq import spin
import numpy as np
cudaq.set_target("nvidia")
qubit_count = 5
sample_count = 10
hamiltonian = spin.z(0)
parameters = np.random.default_rng(13).uniform(low=0,high=1,size=(sample_count, qubit_count))
@cudaq.kernel
def kernel(theta:list[float]):
qubits = cudaq.qvector(qubit_count)
for i in range(qubit_count):
rx(theta[i], qubits)
result = cudaq.observe(kernel, hamiltonian, parameters)
result = cudaq.sample(kernel, parameters)
# result = cudaq.get_state(kernel, parameters)
# result = cudaq.observe_async(kernel, hamiltonian, parameters, qpu_id= 0)
# result = cudaq.sample_async(kernel, parameters, qpu_id= 0)
# result = cudaq.get_state_async(kernel, parameters, qpu_id= 0)
RuntimeError: Cannot pass ndarray with shape != (N,).
Can we enable broadcasting for all execution functions please?
Thanks team.
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 by tracing the execution entry points for sample, observe, get_state, and their async variants, focusing on how parameter arrays are validated. Reproduce the reported ndarray shape error, then verify that all six functions accept broadcast parameter arrays and return results consistently across synchronous and asynchronous execution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, numpy, python
- Domain
- api, quantum-computing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100