Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 8d86e18

Browse files
committed
The optimizer now works with both the old and new eigen[ ]solvers
1 parent c5c53d3 commit 8d86e18

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

qrao/quantum_random_access_optimizer.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
from .semideterministic_rounding import SemideterministicRounding
3838

3939

40+
def _get_aux_operators_evaluated(relaxed_results):
41+
try:
42+
# Must the using the new "minimum_eigensolvers"
43+
# https://github.com/Qiskit/qiskit-terra/blob/main/releasenotes/notes/0.22/add-eigensolvers-with-primitives-8b3a9f55f5fd285f.yaml
44+
return relaxed_results.aux_operators_evaluated
45+
except AttributeError:
46+
# Must be using the old (deprecated) "minimum_eigen_solvers"
47+
return relaxed_results.aux_operator_eigenvalues
48+
49+
4050
class QuantumRandomAccessOptimizationResult(OptimizationResult):
4151
"""Result of Quantum Random Access Optimization procedure."""
4252

@@ -90,7 +100,9 @@ def rounding_results(self) -> RoundingResult:
90100
@property
91101
def trace_values(self):
92102
"""List of expectation values, one corresponding to each decision variable"""
93-
trace_values = [v[0] for v in self._relaxed_results.aux_operators_evaluated]
103+
trace_values = [
104+
v[0] for v in _get_aux_operators_evaluated(self._relaxed_results)
105+
]
94106
return trace_values
95107

96108
@property
@@ -202,7 +214,7 @@ def solve_relaxed(self) -> Tuple[MinimumEigensolverResult, RoundingContext]:
202214
stop_time_relaxed = time.time()
203215
relaxed_results.time_taken = stop_time_relaxed - start_time_relaxed
204216

205-
trace_values = [v[0] for v in relaxed_results.aux_operators_evaluated]
217+
trace_values = [v[0] for v in _get_aux_operators_evaluated(relaxed_results)]
206218

207219
# Collect inputs for rounding
208220
# double check later that there's no funny business with the

0 commit comments

Comments
 (0)