Open bebora opened 1 month ago
For Pylance error(s) workaround, can you try adding from cudaq.qis import *
after the import cudaq
statement?
Hi @khalatepradnya, that import does indeed remove the warnings without affecting code execution.
There is only one issue left in the Python examples: type hints.
Take a look at examples/python/bernstein_vazirani.py
:
@cudaq.kernel
def oracle(register: cudaq.qview, auxillary_qubit: cudaq.qubit,
hidden_bits: List[int]):
Pylance does not like those cudaq.qview
and cudaq.qubit
hints: Variable not allowed in type expression
Required prerequisites
Describe the feature
The documentation suggests using VS Code for a seamless development experience. However, the integration between CUDA-Q and VS Code is not perfect. I get warning/error squiggles under code from some example kernels.
Quantum kernel developers could benefit from proper error detection to quickly identify wrong code, instead of having to run the code and see that it does indeed run.
The following section illustrates how to obtain some of the aforementioned linting errors.
Steps
Set up and run a docker image (the nightly one or the 0.8.0 one; both are affected):
Open VS Code, make sure to have the Dev Containers extension installed and connect to the running container using Ctrl+Shift+P -> Dev Containers: Attach to Running Container... Wait for the default extensions to be set up.
C++
Open the file
examples/cpp/basics/cuquantum_backends.cpp
and wait for IntelliSense to complete the scanning process. Hover overh(q[0]);
and the following message appears: Function definition for 'h' not found. Hover overmz(q);
and the following error appears: no instance of "mz" matches the argument list These kind of issues are mostly present in kernels defined asoperator()
of a struct. On the other hand, inline kernels, such as the one inexamples/cpp/basics/noise_bit_flip.cpp
, do not usually cause warnings (counterexample: openexamples/cpp/basics/bernstein_vazirani.cpp
).Python
Open the file
examples/python/cuquantum_backends.py
and wait for Pylance to complete the scanning process. Hover overh(qvector)
/x.ctrl(...)
/mz(qvector)
and the following message appears: "h"/"x"/"mz" is not defined