Skip to content

Commit

Permalink
fix vqe test
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoRobbiati committed Dec 13, 2023
1 parent c61bfca commit 600b208
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions tests/test_models_variational.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def test_vqe(backend, method, options, compile, filename):
if filename is not None:
assert_regression_fixture(backend, params, filename)

# test energy fluctuation
state = np.ones(2**nqubits) / np.sqrt(2**nqubits)
energy_fluctuation = v.energy_fluctuation(state)
assert energy_fluctuation >= 0


@pytest.mark.parametrize(
"solver,dense",
Expand Down Expand Up @@ -345,10 +350,3 @@ def test_custom_loss(test_input, test_param, expected):
initial_p, loss_func=test_input, loss_func_param=test_param
)
assert abs(best - expected) <= 0.01

def test_energy_fluctuations(backend):
h0 = np.array([[1, 0], [0, -1]])
state = np.array([1, 0])
dbf = DoubleBracketIteration(Hamiltonian(1, matrix=h0, backend=backend))
energy_fluctuation = dbf.energy_fluctuation(state=state)
assert energy_fluctuation == 0

0 comments on commit 600b208

Please sign in to comment.