|
15 | 15 | import unittest |
16 | 16 | from test.python.algorithms import QiskitAlgorithmsTestCase |
17 | 17 |
|
| 18 | +from ddt import ddt, data, unpack |
| 19 | + |
18 | 20 | from qiskit.algorithms.minimum_eigensolvers import VQE |
19 | 21 | from qiskit.algorithms.minimum_eigensolvers.adapt_vqe import AdaptVQE, TerminationCriterion |
20 | 22 | from qiskit.algorithms.optimizers import SLSQP |
|
26 | 28 | from qiskit.utils import algorithm_globals |
27 | 29 |
|
28 | 30 |
|
| 31 | +@ddt |
29 | 32 | class TestAdaptVQE(QiskitAlgorithmsTestCase): |
30 | 33 | """Test of the AdaptVQE minimum eigensolver""" |
31 | 34 |
|
@@ -110,16 +113,37 @@ def test_maximum(self): |
110 | 113 |
|
111 | 114 | self.assertEqual(res.termination_criterion, TerminationCriterion.MAXIMUM) |
112 | 115 |
|
113 | | - def test_cyclicity(self): |
114 | | - """Test to check termination criteria""" |
115 | | - calc = AdaptVQE( |
116 | | - VQE(Estimator(), self.ansatz, self.optimizer), |
117 | | - max_iterations=100, |
118 | | - threshold=1e-15, |
119 | | - ) |
120 | | - res = calc.compute_minimum_eigenvalue(operator=self.h2_op) |
121 | | - |
122 | | - self.assertEqual(res.termination_criterion, TerminationCriterion.CYCLICITY) |
| 116 | + @data( |
| 117 | + ([1, 1], True), |
| 118 | + ([1, 11], False), |
| 119 | + ([11, 1], False), |
| 120 | + ([1, 12], False), |
| 121 | + ([12, 2], False), |
| 122 | + ([1, 1, 1], True), |
| 123 | + ([1, 2, 1], False), |
| 124 | + ([1, 2, 2], True), |
| 125 | + ([1, 2, 21], False), |
| 126 | + ([1, 12, 2], False), |
| 127 | + ([11, 1, 2], False), |
| 128 | + ([1, 2, 1, 1], True), |
| 129 | + ([1, 2, 1, 2], True), |
| 130 | + ([1, 2, 1, 21], False), |
| 131 | + ([11, 2, 1, 2], False), |
| 132 | + ([1, 11, 1, 111], False), |
| 133 | + ([11, 1, 111, 1], False), |
| 134 | + ([1, 2, 3, 1, 2, 3], True), |
| 135 | + ([1, 2, 3, 4, 1, 2, 3], False), |
| 136 | + ([11, 2, 3, 1, 2, 3], False), |
| 137 | + ([1, 2, 3, 1, 2, 31], False), |
| 138 | + ([1, 2, 3, 4, 1, 2, 3, 4], True), |
| 139 | + ([11, 2, 3, 4, 1, 2, 3, 4], False), |
| 140 | + ([1, 2, 3, 4, 1, 2, 3, 41], False), |
| 141 | + ([1, 2, 3, 4, 5, 1, 2, 3, 4], False), |
| 142 | + ) |
| 143 | + @unpack |
| 144 | + def test_cyclicity(self, seq, is_cycle): |
| 145 | + """Test AdaptVQE index cycle detection""" |
| 146 | + self.assertEqual(is_cycle, AdaptVQE._check_cyclicity(seq)) |
123 | 147 |
|
124 | 148 | def test_vqe_solver(self): |
125 | 149 | """Test to check if the VQE solver remains the same or not""" |
|
0 commit comments