-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add support for non-hermitian operators in AerPauliExpectation #7857
Conversation
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.
Hi Anthony, could you add a test that checks that the |
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.
… into qeom_commit_aerpauliexpectation # Conflicts: # qiskit/opflow/expectations/aer_pauli_expectation.py
… into qeom_commit_aerpauliexpectation # Conflicts: # qiskit/opflow/expectations/aer_pauli_expectation.py
… into qeom_commit_aerpauliexpectation
… into qeom_commit_aerpauliexpectation # Conflicts: # test/python/opflow/test_aer_pauli_expectation.py
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Use a generator instead of list
I changed the line giving the pylint error (I thought It was only a warning at first). Basically just all(k.is_hermitian() for k in ...) instead of all([k.is_hermitian() for k in ...]) |
Pull Request Test Coverage Report for Build 2115065714
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great feature to support, I left some comments below!
releasenotes/notes/add-support-non-hermitian-op-aerpauliexpectation-653d8e16de4eca07.yaml
Outdated
Show resolved
Hide resolved
"""pauli expect state vector with non hermitian operator test""" | ||
states_op = ListOp([One, Zero, Plus, Minus]) | ||
|
||
op = np.array([[0, 1], [2, 3]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a test for other primitives than MatrixOp
? What about e.g. 1j * Y
as non-hermitian operator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test case was added with the primitive PauliOp (I used 1jX because with 1jY all the expected values for Plus, Minus, 0, 1 were null). The names of the two test cases were adapted consequently.
Co-authored-by: Julien Gacon <gaconju@gmail.com>
…ation-653d8e16de4eca07.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com>
|
||
op = 1j * X | ||
|
||
converted_meas = self.expect.convert(~StateFn(op) @ states_op) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using ~
will complex conjugate the observable, which we don't really want
converted_meas = self.expect.convert(~StateFn(op) @ states_op) | |
converted_meas = self.expect.convert(StateFn(op, is_measurement=True) @ states_op) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the commit and I changed the expected result from [0, 0, -1j, 1j] to [0, 0, 1j, -1j] to match this modification.
op_mat = np.array([[0, 1], [2, 3]]) | ||
op = MatrixOp(op_mat) | ||
|
||
converted_meas = self.expect.convert(~StateFn(op) @ states_op) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
converted_meas = self.expect.convert(~StateFn(op) @ states_op) | |
converted_meas = self.expect.convert(StateFn(op, is_measurement=True) @ states_op) |
Summary
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.