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

Function test_np_complex128_params

python/tests/kernel/test_kernel_complex.py:229–263  ·  view source on GitHub ↗

Test that we can pass complex lists to kernel functions.

()

Source from the content-addressed store, hash-verified

227
228
229def test_np_complex128_params():
230 """Test that we can pass complex lists to kernel functions."""
231
232 # Pass a list of complex as a parameter
233 c = [
234 np.complex128(.70710678 + 1j),
235 np.complex128(0. + 2j),
236 np.complex128(0.),
237 np.complex128(0.70710678)
238 ]
239
240 @cudaq.kernel
241 def complex_vec_param(vec: list[np.complex128], i: int) -> complex:
242 return vec[i]
243
244 for i in range(len(c)):
245 is_close(c[i].real, complex_vec_param(c, i).real)
246 for i in range(len(c)):
247 is_close(c[i].imag, complex_vec_param(c, i).imag)
248
249 @cudaq.kernel
250 def complex_vec_param_real(vec: list[np.complex128], i: int) -> float:
251 v = vec[i]
252 return v.real
253
254 for i in range(len(c)):
255 assert is_close(c[i].real, complex_vec_param_real(c, i))
256
257 @cudaq.kernel
258 def complex_vec_param_imag(vec: list[np.complex128], i: int) -> float:
259 v = vec[i]
260 return v.imag
261
262 for i in range(len(c)):
263 assert is_close(c[i].imag, complex_vec_param_imag(c, i))
264
265
266def test_np_complex128_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