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

Function test_pauli_word_input

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

Source from the content-addressed store, hash-verified

385
386
387def test_pauli_word_input():
388
389 h = h2_hamiltonian_4q()
390
391 @cudaq.kernel
392 def kernel(theta: float, var: cudaq.pauli_word):
393 q = cudaq.qvector(4)
394 x(q[0])
395 x(q[1])
396 exp_pauli(theta, q, var)
397
398 print(kernel)
399 kernel(.11, 'XXXY')
400
401 want_exp = cudaq.observe(kernel, h, .11, 'XXXY').expectation()
402 assert np.isclose(want_exp, -1.13, atol=1e-2)
403
404 want_exp = cudaq.observe(kernel, h, .11,
405 cudaq.pauli_word('XXXY')).expectation()
406 assert np.isclose(want_exp, -1.13, atol=1e-2)
407
408 @cudaq.kernel
409 def test(theta: float, paulis: list[cudaq.pauli_word]):
410 q = cudaq.qvector(4)
411 x(q[0])
412 x(q[1])
413 for p in paulis:
414 exp_pauli(theta, q, p)
415
416 print(test)
417 want_exp = cudaq.observe(test, h, .11, ['XXXY']).expectation()
418 assert np.isclose(want_exp, -1.13, atol=1e-2)
419
420 words = [cudaq.pauli_word('XXXY')]
421 want_exp = cudaq.observe(test, h, .11, words).expectation()
422 assert np.isclose(want_exp, -1.13, atol=1e-2)
423
424 with pytest.raises(RuntimeError) as e:
425 kernel(.11, 'HELLOBADTERM')
426
427
428def test_exp_pauli():

Callers

nothing calls this directly

Calls 6

h2_hamiltonian_4qFunction · 0.90
pauli_wordMethod · 0.80
kernelFunction · 0.70
printFunction · 0.50
expectationMethod · 0.45
observeMethod · 0.45

Tested by

no test coverage detected