Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VQD's optimal_values #10279

Merged
merged 7 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 releasenotes/notes/fix-vqd-result-27b26f0a6d49e7c7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed bug in :class:`~qiskit.algorithms.eigensolvers.VQD` where ``result.optimal_values`` was a
copy of ``result.optimal_points``. It now returns the corresponding values.
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