Improve error messaging when observable is outside the range of qubits defined
Open
Nobody has claimed this yet.
stale-notified
user experience
- 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
The code below throws up an error message as expected as we are running a 2 qubit circuit but have spin.x(2) in the hamiltonian.
However, the error message is not descriptive of the issue and can cause some headache when debugging.
import cudaq
from cudaq import spin
import numpy as np
cudaq.set_target("nvidia")
qubit_count = 2
kernel, parameters = cudaq.make_kernel(list)
qubits = kernel.qalloc(qubit_count)
for i in range(qubit_count):
kernel.rx(parameters[i], qubits[i])
hamiltonian = spin.z(0) + spin.x(1) + spin.x(2)
parameters = np.random.rand(qubit_count)
expectation_value = cudaq.observe(kernel, hamiltonian, parameters).expectation()
expectation_value
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[1], line 20
16 hamiltonian = spin.z(0) + spin.x(1) + spin.x(2)
18 parameters = np.random.rand(qubit_count)
---> 20 expectation_value = cudaq.observe(kernel, hamiltonian, parameters).expectation()
22 expectation_value
RuntimeError: [custatevec] %invalid value in applyGateMatrix (line 172)
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
Run the Python reproducer shown in the issue, starting at cudaq.observe with the two-qubit kernel and the out-of-range spin.x(2) term. Trace where the custatevec error is surfaced and make the resulting message identify that the observable references a qubit outside the circuit range; add coverage if the existing test location is found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- quantum-computing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100