-
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
Expose cutoff tolerances in Z2Symmetries
#7598
Conversation
Pull Request Test Coverage Report for Build 1860181076
💛 - Coveralls |
Z2Symmetries
Z2Symmetries
releasenotes/notes/expose-tolerances-z2symmetries-9c444a7b1237252e.yaml
Outdated
Show resolved
Hide resolved
After discussions with @ikkoham and @jakelishman I updated the PR to do the following now: Leave def chop(self, tol: float = 1e-14) -> SparsePauliOp: which chops real and imaginary parts of coefficients that are within an (absolute) tolerance >>> from qiskit.quantum_info import SparsePauliOp
>>> op = SparsePauliOp(["X", "Y", "Z"], coeffs=[1+1e-17j, 1e-17+1j, 1e-17])
>>> op.simplify()
SparsePauliOp(['X', 'Y'], coeffs=[1.e+00+1.e-17j, 1.e-17+1.e+00j])
>>> op.chop()
SparsePauliOp(['X', 'Y'], coeffs=[1.+0.j, 0.+1.j]) I chose the default This method is a bit parallel to I ran the failing Nature tests locally and with this PR they run again as desired. 🙂 |
releasenotes/notes/expose-tolerances-z2symmetries-9c444a7b1237252e.yaml
Outdated
Show resolved
Hide resolved
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.
Thank you. I think this method is what we want. If we need different tolerance for real and imag, we can add them at that time. I can't think of any use cases at the moment. LGTM
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.
Basically lgtm, just some minor observations 👍
releasenotes/notes/expose-tolerances-z2symmetries-9c444a7b1237252e.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch>
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 like the new SparsePauliOp.chop
- to me, it's definitely a good solution to the general problem, and it's nicely composable for you guys downstream, which hopefully should lead to easier maintenance for everyone. Thanks for sticking with it.
self._tol = tol | ||
|
||
@property | ||
def tol(self): | ||
"""Tolerance threshold for ignoring real and complex parts of a coefficient.""" | ||
return self._tol | ||
|
||
@tol.setter | ||
def tol(self, value): | ||
"""Set the tolerance threshold for ignoring real and complex parts of a coefficient.""" | ||
self._tol = value |
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.
What's the reason for adding a property to wrap the normal behaviour? It doesn't seem to be doing anything except adding overhead.
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 added it for consistency with tapering_values
which is the only other attribute that is settable. Personally I'd also prefer to just have it as public attribute (just self.tol
in the init) 🙂
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.
From the user's perspective there wouldn't be any inconsistency unless they're in the habit of requiring del x.tol
to raise an error or other weird stuff. But also, I don't really care haha.
releasenotes/notes/expose-tolerances-z2symmetries-9c444a7b1237252e.yaml
Outdated
Show resolved
Hide resolved
test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py
Outdated
Show resolved
Hide resolved
... and other review comments!
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.
Looks good to me! Ikko already approved a slightly earlier version of this, so I'll assume he's fine with the minor performance tweaks, and set this to merge now.
Summary
Allow setting the cutoff tolerances of the tapered operator in
Z2Symmetries
. This fixes Qiskit Nature CI, where some workflows pass the tapered operator into the Pauli evolution gate. This fails since #7551 since the tapering creates some spurious complex coefficients from roundoff errors but the Pauli evolution gate does not allow any complex parts at all.Details and comments
This PR also add a new method the
SparsePauliOp.chop
to truncate real and imaginary parts of a coefficients individually. That means that coefficients likeare truncated to
This is different to
SparsePauliOp.simplify
which would simplify the above coefficient toThis fix could be part of another PR but it's required to properly remove the imaginary parts of the tapered operator so I included it here.
WIP as it misses a test.