Skip to content

Commit b29e4c4

Browse files
authored
[Testing] Add tests for custom op in nested kernels (#4362)
Adds regression tests for issues reported in #2485, which have since been fixed. Resolved #2485 Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
1 parent 033cab8 commit b29e4c4

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

python/tests/custom/test_custom_operations.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,41 @@ def kernel(n: int):
371371
error)
372372

373373

374+
def test_nested_kernel_single_qubit():
375+
"""Regression test for issue #2485: custom op in a nested kernel on a single qubit."""
376+
cudaq.register_operation("custom_x_nested", np.array([0, 1, 1, 0]))
377+
378+
@cudaq.kernel
379+
def inner(q: cudaq.qubit):
380+
custom_x_nested(q)
381+
382+
@cudaq.kernel
383+
def outer():
384+
q = cudaq.qubit()
385+
inner(q)
386+
387+
counts = cudaq.sample(outer, shots_count=100)
388+
assert counts["1"] == 100
389+
390+
391+
def test_nested_kernel_qview():
392+
"""Regression test for issue #2485: custom op in a nested kernel on a qview."""
393+
cudaq.register_operation("custom_x_qview", np.array([0, 1, 1, 0]))
394+
395+
@cudaq.kernel
396+
def inner(qubits: cudaq.qview):
397+
for i in range(len(qubits)):
398+
custom_x_qview(qubits[i])
399+
400+
@cudaq.kernel
401+
def outer():
402+
qubits = cudaq.qvector(2)
403+
inner(qubits)
404+
405+
counts = cudaq.sample(outer, shots_count=100)
406+
assert counts["11"] == 100
407+
408+
374409
# leave for gdb debugging
375410
if __name__ == "__main__":
376411
loc = os.path.abspath(__file__)

0 commit comments

Comments
 (0)