Skip to content

Commit

Permalink
add energy_fluctuation test into hamiltonian tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoRobbiati committed Dec 13, 2023
1 parent 7e34beb commit f9b066e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_hamiltonians.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,18 @@ def construct_hamiltonian():

backend.assert_allclose(H.exp(0.5), target_matrix)
backend.assert_allclose(H1.exp(0.5), target_matrix)


def test_hamiltonian_energy_fluctuation(backend):
"""Test energy fluctuation."""
# define hamiltonian
ham = hamiltonians.XXZ(nqubits=2, backend=backend)
# take ground state and zero state
ground_state = ham.ground_state()
zero_state = np.ones(2**2) / np.sqrt(2**2)
# collect energy fluctuations
gs_energy_fluctuation = ham.energy_fluctuation(ground_state)
zs_energy_fluctuation = ham.energy_fluctuation(zero_state)

assert np.isclose(gs_energy_fluctuation, 0, atol=1e-5)
assert gs_energy_fluctuation < zs_energy_fluctuation

0 comments on commit f9b066e

Please sign in to comment.