diff --git a/python/tests/kernel/test_kernel_features.py b/python/tests/kernel/test_kernel_features.py index 3b949ccd71..b01532f76d 100644 --- a/python/tests/kernel/test_kernel_features.py +++ b/python/tests/kernel/test_kernel_features.py @@ -852,7 +852,7 @@ def test(): print(test) -def test_bool_list_elements(): +def test_bool_list_element(): @cudaq.kernel def kernel(var: list[bool]): @@ -868,6 +868,33 @@ def kernel(var: list[bool]): assert '0' in counts and len(counts) == 1 +def test_list_bool_elements(): + import cudaq + + @cudaq.kernel + def kernel(n: int, bools: list[bool]): + q = cudaq.qvector(n) + for j in range(n): + b = bools[j] + if b == False: + x(q[j]) + + counts = cudaq.sample(kernel, 2, [True, True]) + assert "00" in counts and len(counts) == 1 + + counts = cudaq.sample(kernel, 2, [False, True]) + assert "10" in counts and len(counts) == 1 + + counts = cudaq.sample(kernel, 2, [True, False]) + assert "01" in counts and len(counts) == 1 + + counts = cudaq.sample(kernel, 2, [False, False]) + assert "11" in counts and len(counts) == 1 + + counts = cudaq.sample(kernel, 5, [True, True, False, True, True]) + assert "00100" in counts and len(counts) == 1 + + def test_list_float_pass_list_int(): @cudaq.kernel @@ -919,12 +946,14 @@ def test2() -> int: def test_empty_lists(): @cudaq.kernel - def empty(var: list[cudaq.pauli_word], varvar: list[float], - varvarvar: list[bool]): + def empty(a: list[cudaq.pauli_word], b: list[bool], c: list[int], + d: list[float], e: list[complex]) -> int: + q = cudaq.qvector(2) x(q[0]) + return len(a) + len(b) + len(c) + len(d) + len(e) - empty([], [], []) + assert empty([], [], [], [], []) == 0 def test_no_valueerror_np_array(): diff --git a/python/utils/OpaqueArguments.h b/python/utils/OpaqueArguments.h index 46afd2fedc..bce99cbf04 100644 --- a/python/utils/OpaqueArguments.h +++ b/python/utils/OpaqueArguments.h @@ -392,11 +392,11 @@ inline void packArgs(OpaqueArguments &argData, py::args args, .Case([&](IntegerType type) { // Handle vec and vec if (type.getIntOrFloatBitWidth() == 1) { - genericVecAllocator.template operator()( + genericVecAllocator.template operator()( [](py::handle element, int index, int elementIndex) { checkListElementType(element, index, elementIndex); - return element.cast(); + return static_cast(element.cast()); }); return; }