Skip to content

Commit

Permalink
Added support for non-hermitian operators in AerPauliExpectation
Browse files Browse the repository at this point in the history
Fixes Qiskit#415

QEOM creates a dictionary of operators to evaluate on the groundstate.
When using the noisy simulators (qasm_simulator or aer_simulator), one
could either use PauliExpectation (with noise) or AerPauliExpectation
(without noise). PauliExpectation works with non-hermitian operators
but internal methods of AerPauliExpectation raised an Error.
This is a workaround to this limitation.
Note that using include_custom=True on qasm allows the VQE to use a
local AerPauliExpectation without using the "expectation" input.
This does not apply to QEOM and one should explicitly define the
"expectation" input of the VQE for it to apply globally.
  • Loading branch information
Anthony-Gandon committed Apr 1, 2022
1 parent ceb7ddc commit 01a1d88
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions qiskit/opflow/expectations/aer_pauli_expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,31 @@ def convert(self, operator: OperatorBase) -> OperatorBase:
AerSnapshot-based expectation circuits.
Args:
operator: The operator to convert.
operator: The operator to convert. If it contains non-hermitian terms, apply an additional step.
Returns:
The converted operator.
"""

if isinstance(operator, OperatorStateFn) and operator.is_measurement:
return self._replace_pauli_sums(operator.primitive) * operator.coeff
is_herm = operator.primitive.is_hermitian()
if not is_herm:
pauli_sum_re = (
self._replace_pauli_sums(
1 / 2 * (operator.primitive + operator.primitive.adjoint()).reduce()
)
* operator.coeff
)
pauli_sum_im = (
self._replace_pauli_sums(
1 / 2j * (operator.primitive - operator.primitive.adjoint()).reduce()
)
* operator.coeff
)
pauli_sum = (pauli_sum_re + 1j * pauli_sum_im).reduce()
else:
pauli_sum = self._replace_pauli_sums(operator.primitive) * operator.coeff
return pauli_sum
elif isinstance(operator, ListOp):
return operator.traverse(self.convert)
else:
Expand Down

0 comments on commit 01a1d88

Please sign in to comment.