Skip to content

Commit

Permalink
Fix VQD's optimal_values (Qiskit#10279)
Browse files Browse the repository at this point in the history
* Fix optimal values

* Add unittest

* Add reno

* Update unittest

* Revert "Update unittest"

This reverts commit 225cd09e1ae08cd48f5196fd1d3a87a549f0164a.

* Update test

* Make test subtest
  • Loading branch information
ElePT authored Jun 20, 2023
1 parent 5485e85 commit 3089560
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qiskit/algorithms/eigensolvers/vqd.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _update_vqd_result(
else np.array([opt_result.x])
)
result.optimal_parameters.append(dict(zip(ansatz.parameters, opt_result.x)))
result.optimal_values = np.concatenate([result.optimal_points, [opt_result.x]])
result.optimal_values = np.concatenate([result.optimal_values, [opt_result.fun]])
result.cost_function_evals = np.concatenate([result.cost_function_evals, [opt_result.nfev]])
result.optimizer_times = np.concatenate([result.optimizer_times, [eval_time]])
result.eigenvalues.append(opt_result.fun + 0j)
Expand Down
5 changes: 5 additions & 0 deletions test/python/algorithms/eigensolvers/test_vqd.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def test_basic_operator(self, op):
)
np.testing.assert_array_almost_equal(job.result().values, result.eigenvalues, 6)

with self.subTest(msg="assert returned values are eigenvalues"):
np.testing.assert_array_almost_equal(
result.optimal_values, self.h2_energy_excited[:2], decimal=3
)

def test_full_spectrum(self):
"""Test obtaining all eigenvalues."""
vqd = VQD(self.estimator, self.fidelity, self.ryrz_wavefunction, optimizer=L_BFGS_B(), k=4)
Expand Down

0 comments on commit 3089560

Please sign in to comment.