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

Function test_complex_params

python/tests/kernel/test_kernel_complex.py:21–50  ·  view source on GitHub ↗

Test that we can pass complex lists to kernel functions.

()

Source from the content-addressed store, hash-verified

19
20
21def test_complex_params():
22 """Test that we can pass complex lists to kernel functions."""
23
24 # Pass a list of complex as a parameter
25 c = [.70710678 + 1j, 2j, 0., 0.70710678]
26
27 @cudaq.kernel
28 def complex_vec_param(vec: list[complex], i: int) -> complex:
29 return vec[i]
30
31 for i in range(len(c)):
32 is_close(c[i].real, complex_vec_param(c, i).real)
33 for i in range(len(c)):
34 is_close(c[i].imag, complex_vec_param(c, i).imag)
35
36 @cudaq.kernel
37 def complex_vec_param_real(vec: list[complex], i: int) -> float:
38 v = vec[i]
39 return v.real
40
41 for i in range(len(c)):
42 assert is_close(c[i].real, complex_vec_param_real(c, i))
43
44 @cudaq.kernel
45 def complex_vec_param_imag(vec: list[complex], i: int) -> float:
46 v = vec[i]
47 return v.imag
48
49 for i in range(len(c)):
50 assert is_close(c[i].imag, complex_vec_param_imag(c, i))
51
52
53def test_complex_capture():

Callers

nothing calls this directly

Calls 5

complex_vec_paramFunction · 0.85
complex_vec_param_realFunction · 0.85
complex_vec_param_imagFunction · 0.85
is_closeFunction · 0.70
rangeFunction · 0.50

Tested by

no test coverage detected