Skip to content

Commit e564a7a

Browse files
Merge pull request qiskit-community/qiskit-aqua#800 from chriseclectic/fix/snapshot-val-type
Fix weighted_pauli_operator expectation value mode for Aer 0.4 release
2 parents d57accb + c50b30e commit e564a7a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

qiskit/aqua/operators/weighted_pauli_operator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# This code is part of Qiskit.
44
#
5-
# (C) Copyright IBM 2019.
5+
# (C) Copyright IBM 2019, 2020.
66
#
77
# This code is licensed under the Apache License, Version 2.0. You may
88
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -753,8 +753,11 @@ def evaluate_with_result(self, result, statevector_mode, use_simulator_snapshot_
753753
if use_simulator_snapshot_mode:
754754
snapshot_data = result.data(
755755
circuit_name_prefix + 'snapshot_mode')['snapshots']
756-
expval = snapshot_data['expectation_value']['expval'][0]['value']
757-
avg = expval[0] + 1j * expval[1]
756+
avg = snapshot_data['expectation_value']['expval'][0]['value']
757+
if isinstance(avg, (list, tuple)):
758+
# Aer versions before 0.4 use a list snapshot format
759+
# which must be converted to a complex value.
760+
avg = avg[0] + 1j * avg[1]
758761
elif statevector_mode:
759762
quantum_state = np.asarray(result.get_statevector(circuit_name_prefix + 'psi'))
760763
for weight, pauli in self._paulis:

0 commit comments

Comments
 (0)