Skip to content

Commit

Permalink
Adds a unittest for SparsePauliOp support in AdaptVQE
Browse files Browse the repository at this point in the history
  • Loading branch information
mrossinek committed Apr 12, 2023
1 parent 0d62eb2 commit 1a2a38f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qiskit/algorithms/minimum_eigensolvers/adapt_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def supports_aux_operators(cls) -> bool:
def _compute_gradients(
self,
theta: list[float],
operator: OperatorBase,
operator: BaseOperator | OperatorBase,
) -> list[tuple[complex, dict[str, Any]]]:
"""
Computes the gradients for all available excitation operators.
Expand Down
15 changes: 15 additions & 0 deletions test/python/algorithms/minimum_eigensolvers/test_adapt_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ def test_default(self):
self.assertAlmostEqual(res.eigenvalue, expected_eigenvalue, places=6)
np.testing.assert_allclose(res.eigenvalue_history, [expected_eigenvalue], rtol=1e-6)

def test_with_quantum_info(self):
"""Test behavior with quantum_info-based operators."""
ansatz = EvolvedOperatorAnsatz(
[op.primitive for op in self.excitation_pool],
initial_state=self.initial_state,
)

calc = AdaptVQE(VQE(Estimator(), ansatz, self.optimizer))
res = calc.compute_minimum_eigenvalue(operator=self.h2_op.primitive)

expected_eigenvalue = -1.85727503

self.assertAlmostEqual(res.eigenvalue, expected_eigenvalue, places=6)
np.testing.assert_allclose(res.eigenvalue_history, [expected_eigenvalue], rtol=1e-6)

def test_converged(self):
"""Test to check termination criteria"""
calc = AdaptVQE(
Expand Down

0 comments on commit 1a2a38f

Please sign in to comment.