Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for non-hermitian operators in AerPauliExpectation #7857

Merged
merged 17 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
01a1d88
Added support for non-hermitian operators in AerPauliExpectation
Anthony-Gandon Mar 31, 2022
4d883a4
Added support for non-hermitian operators in AerPauliExpectation
Anthony-Gandon Mar 31, 2022
a60dcd8
Merge remote-tracking branch 'origin/qeom_commit_aerpauliexpectation'…
Anthony-Gandon Apr 1, 2022
d7cd270
Merge remote-tracking branch 'origin/qeom_commit_aerpauliexpectation'…
Anthony-Gandon Apr 1, 2022
71bafc0
Merge remote-tracking branch 'origin/qeom_commit_aerpauliexpectation'…
Anthony-Gandon Apr 1, 2022
663b483
Add a test case for non-hermitian operators.
Anthony-Gandon Apr 1, 2022
2cfc5a4
Add a test case for non-hermitian operators.
Anthony-Gandon Apr 1, 2022
474ca18
Merge remote-tracking branch 'origin/qeom_commit_aerpauliexpectation'…
Anthony-Gandon Apr 1, 2022
8311c27
Add a test case for non-hermitian operators.
Anthony-Gandon Apr 1, 2022
b7fc978
Update test/python/opflow/test_aer_pauli_expectation.py
Anthony-Gandon Apr 4, 2022
3d875cb
Update aer_pauli_expectation.py
Anthony-Gandon Apr 4, 2022
479bdbb
Update qiskit/opflow/expectations/aer_pauli_expectation.py
Anthony-Gandon Apr 7, 2022
3d4b0e9
Update releasenotes/notes/add-support-non-hermitian-op-aerpauliexpect…
Anthony-Gandon Apr 7, 2022
3a69dc9
Add a test case for PauliOp
Anthony-Gandon Apr 7, 2022
7f121cb
Change the test cases from using ~StateFn() to using StateFn(, is_mea…
Anthony-Gandon Apr 8, 2022
0a40bfd
Fix the formatting
Anthony-Gandon Apr 8, 2022
21ad50f
Merge branch 'main' into qeom_commit_aerpauliexpectation
mergify[bot] Apr 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 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,36 @@ 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.
Anthony-Gandon marked this conversation as resolved.
Show resolved Hide resolved

Returns:
The converted operator.
"""

if isinstance(operator, OperatorStateFn) and operator.is_measurement:
return self._replace_pauli_sums(operator.primitive) * operator.coeff
if isinstance(operator.primitive, ListOp):
is_herm = all([op.is_hermitian() for op in operator.primitive.oplist])
else:
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
17 changes: 17 additions & 0 deletions test/python/opflow/test_aer_pauli_expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
Y,
Z,
Zero,
MatrixOp
)
from qiskit.utils import QuantumInstance

Expand Down Expand Up @@ -120,6 +121,22 @@ def test_pauli_expect_state_vector(self):

np.testing.assert_array_almost_equal(sampled.eval(), [0, 0, 1, -1], decimal=1)

def test_pauli_expect_non_hermitian_state_vector(self):
"""pauli expect state vector with non hermitian operator test"""
states_op = ListOp([One, Zero, Plus, Minus])

op = np.zeros((2, 2))
op[0, 0] = 0
op[0, 1] = 1
op[1, 0] = 2
op[1, 1] = 3
Anthony-Gandon marked this conversation as resolved.
Show resolved Hide resolved
op_mat = MatrixOp(op)

converted_meas = self.expect.convert(~StateFn(op_mat) @ states_op)
sampled = self.sampler.convert(converted_meas)

np.testing.assert_array_almost_equal(sampled.eval(), [3, 0, 3, 0], decimal=1)

def test_pauli_expect_op_vector_state_vector(self):
"""pauli expect op vector state vector test"""
paulis_op = ListOp([X, Y, Z, I])
Expand Down