Skip to content

Commit

Permalink
fix: overwrite AdaptVQE.supports_aux_operators (#9142) (#9166)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit e4ea067)

Co-authored-by: Max Rossmannek <oss@zurich.ibm.com>
  • Loading branch information
mergify[bot] and mrossinek committed Nov 22, 2022
1 parent 775ac1e commit 3caa782
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion qiskit/algorithms/minimum_eigensolvers/adapt_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from qiskit.circuit.library import EvolvedOperatorAnsatz
from qiskit.utils.validation import validate_min

from .minimum_eigensolver import MinimumEigensolver
from .vqe import VQE, VQEResult
from ..observables_evaluator import estimate_observables
from ..variational_algorithm import VariationalAlgorithm
Expand All @@ -45,7 +46,7 @@ class TerminationCriterion(Enum):
MAXIMUM = "Maximum number of iterations reached"


class AdaptVQE(VariationalAlgorithm):
class AdaptVQE(VariationalAlgorithm, MinimumEigensolver):
"""The Adaptive Variational Quantum Eigensolver algorithm.
`AdaptVQE <https://arxiv.org/abs/1812.11173>`__ is a quantum algorithm which creates a compact
Expand Down Expand Up @@ -126,6 +127,10 @@ def initial_point(self, value: Sequence[float] | None) -> None:
"""Sets the initial point of the internal :class:`~.VQE` solver."""
self.solver.initial_point = value

@classmethod
def supports_aux_operators(cls) -> bool:
return True

def _compute_gradients(
self,
theta: list[float],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
:class:`~qiskit.algorithms.minimum_eigensolver.AdaptVQE` now correctly
indicates that it supports auxiliary operators.
10 changes: 10 additions & 0 deletions test/python/algorithms/minimum_eigensolvers/test_adapt_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ def test_gradient_calculation(self):
# compare with manually computed reference value
self.assertAlmostEqual(res[0][0], 2.0)

def test_supports_aux_operators(self):
"""Test that auxiliary operators are supported"""
calc = AdaptVQE(VQE(Estimator(), self.ansatz, self.optimizer))
res = calc.compute_minimum_eigenvalue(operator=self.h2_op, aux_operators=[self.h2_op])

expected_eigenvalue = -1.85727503

self.assertAlmostEqual(res.eigenvalue, expected_eigenvalue, places=6)
self.assertAlmostEqual(res.aux_operators_evaluated[0][0], expected_eigenvalue, places=6)


if __name__ == "__main__":
unittest.main()

0 comments on commit 3caa782

Please sign in to comment.