-
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
Use eigh, eigsh in NumPyEigensolver #6987
Conversation
What are the 2 notebooks here in this PR - were they added by mistake? |
Oh... my mistake... Thanks. |
releasenotes/notes/add-opflow-is-hermitian-method-6a461549e3c6b32c.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Jake Lishman <jake@binhbar.com>
@jakelishman Thank you for your review. I made some mistakes. |
def is_hermitian(self) -> bool: | ||
"""Return True if the operator is hermitian. | ||
|
||
Returns: Boolean value | ||
""" | ||
return (self.to_spmatrix() != self.to_spmatrix().getH()).nnz == 0 | ||
|
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.
With floating-point maths, there's always the thorny question of tolerances to consider. I don't really know if it's appropriate for your use-cases, here, though.
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. Personally, I think OperatorBase should inherit TolerancesMixin. However, the OpFlow implementation does not do so. e.g. https://github.com/Qiskit/qiskit-terra/blob/d2013d1812c9229455c1cfb1c79c560fecbc5dfe/qiskit/opflow/primitive_ops/pauli_op.py#L90
The concept of equality is different between Opflow and quantum_info.operators. opflow is exact and qinfo allows errors.
I believe that it should be unified in the future, but this is beyond the scope of this PR, so please leave it for now.
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.
Sounds fine to me, then - definitely best just to follow what's already there in this case!
…b32c.yaml Co-authored-by: Jake Lishman <jake@binhbar.com>
* Use eigh, eigsh * add is_hermitian method * add is_hermitian method to OperatorBase * rm unnecessary files * modify releasenot * Apply suggestions from code review Co-authored-by: Jake Lishman <jake@binhbar.com> * fix test name * Update releasenotes/notes/add-opflow-is-hermitian-method-6a461549e3c6b32c.yaml Co-authored-by: Jake Lishman <jake@binhbar.com> Co-authored-by: Jake Lishman <jake@binhbar.com>
* Use eigh, eigsh * add is_hermitian method * add is_hermitian method to OperatorBase * rm unnecessary files * modify releasenot * Apply suggestions from code review Co-authored-by: Jake Lishman <jake@binhbar.com> * fix test name * Update releasenotes/notes/add-opflow-is-hermitian-method-6a461549e3c6b32c.yaml Co-authored-by: Jake Lishman <jake@binhbar.com> Co-authored-by: Jake Lishman <jake@binhbar.com>
Summary
If NumPyEigensSolver knows that the given operator is hermitian, we should use eigh or eigsh.
The eigenvalue becomes float from complex.
Details and comments