()
| 385 | |
| 386 | |
| 387 | def 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 | |
| 428 | def test_exp_pauli(): |
nothing calls this directly
no test coverage detected