Skip to content

Commit

Permalink
Fix #829 (#834) (#835)
Browse files Browse the repository at this point in the history
Fixes the VQEClient to correctly detect the type of the wrapped
auxiliary operators. Previously, it would always wrap them into a
dictionary and then fail when unwrapping them later, since it did not
preserve the previously wrapped data type.

(cherry picked from commit a8f2919)

Co-authored-by: Max Rossmannek <oss@zurich.ibm.com>
  • Loading branch information
mergify[bot] and mrossinek authored Sep 22, 2022
1 parent 22b34a1 commit 7ebfc8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 11 additions & 5 deletions qiskit_nature/runtime/vqe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def compute_minimum_eigenvalue(

# try to convert the operators to a PauliSumOp, if it isn't already one
operator = _convert_to_paulisumop(operator)
wrapped_type = type(aux_operators)
wrapped_aux_operators = {
str(aux_op_name_or_idx): _convert_to_paulisumop(aux_op)
for aux_op_name_or_idx, aux_op in ListOrDict(aux_operators).items()
Expand Down Expand Up @@ -306,11 +307,16 @@ def compute_minimum_eigenvalue(
vqe_result.eigenstate = result.get("eigenstate", None)
vqe_result.eigenvalue = result.get("eigenvalue", None)
aux_op_eigenvalues = result.get("aux_operator_eigenvalues", None)
if isinstance(aux_operators, dict) and aux_op_eigenvalues is not None:
aux_op_eigenvalues = dict(
zip(wrapped_aux_operators.keys(), aux_op_eigenvalues.values())
)
if not aux_op_eigenvalues: # For consistency set to None for empty dict
if aux_op_eigenvalues is not None:
if wrapped_type == list:
aux_op_eigenvalues = list(
aux_op_eigenvalues.get(str(key), None) for key in range(len(aux_op_eigenvalues))
)
elif wrapped_type == dict:
aux_op_eigenvalues = dict(
zip(wrapped_aux_operators.keys(), aux_op_eigenvalues.values())
)
if not aux_op_eigenvalues: # For consistency set to None for empty dict/list
aux_op_eigenvalues = None
vqe_result.aux_operator_eigenvalues = aux_op_eigenvalues
vqe_result.optimal_parameters = result.get("optimal_parameters", None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
fixes:
- |
Fixes the :class:`qiskit_nature.runtime.VQEClient` to correctly detect the
type of the wrapped auxiliary operators. Previously, it would always wrap
them into a dictionary and then fail when unwrapping them later, since it
did not preserve the previously wrapped data type.

0 comments on commit 7ebfc8c

Please sign in to comment.