Required prerequisites
Describe the bug
Describe the bug
PR #4173 ("Support qvector arguments in custom operations", fixes #2452) added support for calling a custom operation with a whole qvector:
custom_op(qvec)
custom_op(*qvec)
However, C++ front-end (CUDAQ_REGISTER_OPERATION) was not updated.
Steps to reproduce the bug
C++ (fails)
// repro.cpp
#include <cudaq.h>
// 2-qubit custom operation (SWAP), row-major, {re,im}
CUDAQ_REGISTER_OPERATION(MyGate, 2, 0, {
{1.0,0.0},{0.0,0.0},{0.0,0.0},{0.0,0.0},
{0.0,0.0},{0.0,0.0},{1.0,0.0},{0.0,0.0},
{0.0,0.0},{1.0,0.0},{0.0,0.0},{0.0,0.0},
{0.0,0.0},{0.0,0.0},{0.0,0.0},{1.0,0.0}
});
struct kernel {
void operator()() __qpu__ {
cudaq::qvector q(2);
x(q[0]);
MyGate(q); // <-- whole qvector: FAILS to compile
// MyGate(q[0], q[1]); // <-- explicit qubits: works fine
}
};
int main() { auto c = cudaq::sample(kernel{}); c.dump(); return 0; }
$ nvq++ repro.cpp --target nvidia -o repro
repro.cpp:15:5: error: 'quake.custom_unitary_constant' op Invalid matrix size, required 2^N * 2^N for N-qubit operation
MyGate(q);
^
Using explicit qubit refs MyGate(q[0], q[1]) compiles and runs correctly
({ 01:1000 }, SWAP on |10> -> |01>).
Python (same operation, whole qvector works):
import cudaq, numpy as np
cudaq.register_operation("mygate", np.array(
[1,0,0,0, 0,0,1,0, 0,1,0,0, 0,0,0,1], dtype=complex))
@cudaq.kernel
def kernel():
q = cudaq.qvector(2)
x(q[0])
mygate(q) # whole qvector: works in Python (PR #4173)
print(cudaq.sample(kernel)) # { 01:1000 }
Expected behavior
Work with no error
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- CUDA-Q version: 0.15.0
- Python version:
- C++ compiler: nvq++
- Operating system:
Suggestions
No response
Required prerequisites
Describe the bug
Describe the bug
PR #4173 ("Support qvector arguments in custom operations", fixes #2452) added support for calling a custom operation with a whole
qvector:custom_op(qvec)custom_op(*qvec)However, C++ front-end (
CUDAQ_REGISTER_OPERATION) was not updated.Steps to reproduce the bug
C++ (fails)
Using explicit qubit refs
MyGate(q[0], q[1])compiles and runs correctly(
{ 01:1000 }, SWAP on |10> -> |01>).Python (same operation, whole qvector works):
Expected behavior
Work with no error
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
Suggestions
No response