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
422 stars 146 forks source link

Count parameters of circuits #1479

Open zohimchandani opened 2 months ago

zohimchandani commented 2 months ago

Required prerequisites

Describe the bug

The code below should only work with n_params=2 since we have 2 variational parameters in the quantum circuit.

However, it executes without an error for n_params=1 and n_params=3.

When n_params=1, I am not sure what is being inputted to the second variational parameter?

When n_params=3, I am guessing that the extra parameter supplied is ignored.

import cudaq 
from cudaq import spin 
import numpy as np 

n_samples = 5 
n_params = 2 

params = np.random.rand(n_samples, n_params)
print(params)

@cudaq.kernel
def kernel(params: np.ndarray):

    qvector = cudaq.qvector(1)

    rx(params[0], qvector[0])
    ry(params[1], qvector[0])

result = cudaq.observe(kernel, spin.z(0), params)

result
print(cudaq.__version__)
CUDA Quantum Version latest (https://github.com/NVIDIA/cuda-quantum 90611863c4cf296f52e75bccea9ce1679b52d58b)

It would be nice to throw error messages for these cases.

Thanks

Steps to reproduce the bug

NA

Expected behavior

NA

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

Not a regression

Environment

Suggestions

No response

mmvandieren commented 1 week ago

I'll "+1" this. An error message would be good to have especially when writing up a hybrid neural network.