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

Commit

Permalink
The optimizer now works with both the old and new eigen[ ]solvers
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Dec 8, 2022
1 parent c5c53d3 commit 8d86e18
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions qrao/quantum_random_access_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
from .semideterministic_rounding import SemideterministicRounding


def _get_aux_operators_evaluated(relaxed_results):
try:
# Must the using the new "minimum_eigensolvers"
# https://github.com/Qiskit/qiskit-terra/blob/main/releasenotes/notes/0.22/add-eigensolvers-with-primitives-8b3a9f55f5fd285f.yaml
return relaxed_results.aux_operators_evaluated
except AttributeError:
# Must be using the old (deprecated) "minimum_eigen_solvers"
return relaxed_results.aux_operator_eigenvalues


class QuantumRandomAccessOptimizationResult(OptimizationResult):
"""Result of Quantum Random Access Optimization procedure."""

Expand Down Expand Up @@ -90,7 +100,9 @@ def rounding_results(self) -> RoundingResult:
@property
def trace_values(self):
"""List of expectation values, one corresponding to each decision variable"""
trace_values = [v[0] for v in self._relaxed_results.aux_operators_evaluated]
trace_values = [
v[0] for v in _get_aux_operators_evaluated(self._relaxed_results)
]
return trace_values

@property
Expand Down Expand Up @@ -202,7 +214,7 @@ def solve_relaxed(self) -> Tuple[MinimumEigensolverResult, RoundingContext]:
stop_time_relaxed = time.time()
relaxed_results.time_taken = stop_time_relaxed - start_time_relaxed

trace_values = [v[0] for v in relaxed_results.aux_operators_evaluated]
trace_values = [v[0] for v in _get_aux_operators_evaluated(relaxed_results)]

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

0 comments on commit 8d86e18

Please sign in to comment.