NVIDIA/cuda-quantum

Count parameters of circuits

zohimchandani opened this issue · 1 comments

Required prerequisites

  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • If possible, make a PR with a failing test to give us a starting point to work on!

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

  • CUDA Quantum version:
  • Python version:
  • C++ compiler:
  • Operating system:

Suggestions

No response