Skip to content

Commit

Permalink
Update AdaptVQE to new, stateless VQE (qiskit-community#222)
Browse files Browse the repository at this point in the history
* fix AdaptVQE

which previously used the (now deleted) internal method _evaluate_energy of the VQE

* add reno

Co-authored-by: Steve Wood <[email protected]>
  • Loading branch information
2 people authored and manoelmarques committed Jul 8, 2021
1 parent fbcfb09 commit 4fe4a5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ def _compute_gradients(self,
self._ansatz.operators = self._excitation_list + [exc]
# set the current ansatz
vqe.ansatz = self._ansatz
ansatz_params = vqe.ansatz._parameter_table.keys()
# construct the expectation operator of the VQE
vqe._expect_op = vqe.construct_expectation(ansatz_params, self._main_operator)
# evaluate energies
parameter_sets = theta + [-self._delta] + theta + [self._delta]
energy_results = vqe._energy_evaluation(np.asarray(parameter_sets))
energy_evaluation = vqe.get_energy_evaluation(self._main_operator)
energy_results = energy_evaluation(np.asarray(parameter_sets))
# compute gradient
gradient = (energy_results[0] - energy_results[1]) / (2 * self._delta)
res.append((np.abs(gradient), exc))
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/fix-adapt-vqe-c9df0c06ea352b91.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fix :class:`~qiskit_nature.algorithms.AdaptVQE` after the update of
:class:`~qiskit.algorithms.VQE` which deleted the internal ``_energy_evaluation``
method that Adapt-VQE was relying on.

0 comments on commit 4fe4a5c

Please sign in to comment.