MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / test_list_creation

Function test_list_creation

python/tests/kernel/test_kernel_features.py:816–860  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

814
815
816def test_list_creation():
817
818 N = 10
819
820 @cudaq.kernel
821 def kernel(N: int, idx: int) -> int:
822 myList = [i + 1 for i in range(N - 1)]
823 return myList[idx]
824
825 for i in range(N - 1):
826 assert kernel(N, i) == i + 1
827
828 @cudaq.kernel
829 def kernel2(N: int, i: int, j: int) -> int:
830 myList = [[k, k] for k in range(N)]
831 l = myList[i]
832 return l[j]
833
834 print(kernel2(5, 0, 0))
835 for i in range(N):
836 for j in range(2):
837 print(i, j, kernel2(N, i, j))
838 assert kernel2(N, i, j) == i
839
840 @cudaq.kernel
841 def kernel3(N: int):
842 myList = list(range(N))
843 q = cudaq.qvector(N)
844 for i in myList:
845 x(q[i])
846
847 counts = cudaq.sample(kernel3, 5)
848 assert len(counts) == 1
849 assert '1' * 5 in counts
850
851 @cudaq.kernel
852 def kernel4(myList: List[int]):
853 q = cudaq.qvector(len(myList))
854 casted = list(myList)
855 for i in casted:
856 x(q[i])
857
858 counts = cudaq.sample(kernel4, list(range(5)))
859 assert len(counts) == 1
860 assert '1' * 5 in counts
861
862
863def test_string_argument_error():

Callers

nothing calls this directly

Calls 5

kernelFunction · 0.70
kernel2Function · 0.70
rangeFunction · 0.50
printFunction · 0.50
sampleMethod · 0.45

Tested by

no test coverage detected