NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
523 stars 185 forks source link

formatting issue with in an error message #2131

Open mmvandieren opened 2 months ago

mmvandieren commented 2 months ago

Required prerequisites

Describe the bug

There seems to be a typo somewhere in the code that generates the error message below because all the formatting commands are displayed instead of executed. Screenshot 2024-08-22 at 12 36 13 PM

Steps to reproduce the bug


def error_message():
    qubits =qvector(2)
    ctrl.x(qubits[0], qubits[1])

results = cudaq.sample(error_message)

### Expected behavior

shouldn't see the `+ Color.RED` text

### Is this a regression? If it is, put the last known working version (or commit) here.

Not a regression

### Environment

- **CUDA Quantum version**:  0.8.0
- **Python version**: 
- **C++ compiler**: 
- **Operating system**: 

### Suggestions

_No response_
sacpis commented 2 months ago

Don't you need to define the kernel decorator.

@cudaq.kernel
def error_message():
    qubits =qvector(2)
    ctrl.x(qubits[0], qubits[1])

results = cudaq.sample(error_message)
mmvandieren commented 2 months ago

Yeah, the kernel decorator is needed to get the right error message.

The code example is purposefully wrong. What's the issues is that the error message that gets generated has a problem in it.

sacpis commented 2 months ago

I just see this output.

root@6db8d9a389b3:/workspaces/cuda-quantum# python3 examples/python/test.py 
cudaq.kernel.ast_bridge.CompilerError: test.py:6: error: Invalid function call - 'ctrl' is unknown.
         (offending source -> ctrl.x)

Are you running it in Jupyter notebook?

mmvandieren commented 2 months ago

Yep, I'm in a Jupyter notebook in VS Code on my Mac in a container.

sacpis commented 2 months ago

I see the following output when I execute above code to repro the above error message

{
    "name": "NameError",
    "message": "name 'ctrl' is not defined",
    "stack": "---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[5], line 7
      4     qubits = cudaq.qvector(2)
      5     ctrl.x(qubits[0], qubits[1])
----> 7 results = cudaq.sample(error_message)

File /usr/local/cudaq/cudaq/runtime/sample.py:87, in sample(kernel, shots_count, noise_model, *args)
     84             cudaq_runtime.setExecutionContext(ctx)
     85     return counts
---> 87 kernel(*args)
     88 res = ctx.result
     89 cudaq_runtime.resetExecutionContext()

Cell In[5], line 5, in error_message()
      3 def error_message():
      4     qubits = cudaq.qvector(2)
----> 5     ctrl.x(qubits[0], qubits[1])

NameError: name 'ctrl' is not defined"
}