-
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 label assigned check in SparsePauliOp #8101
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
@@ -636,13 +636,15 @@ def from_sparse_list(obj, num_qubits): | |||
Args: | |||
obj (Iterable[Tuple[str, List[int], complex]]): The list 3-tuples specifying the Paulis. | |||
num_qubits (int): The number of qubits of the operator. | |||
do_checks (bool): The flag of checking if it is already assigned (not I). |
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 think I
should be checked too, otherwise it's unclear how we interpret using an index multiple times 🙂 Could you add that?
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 @Cryoris.
How about not to being allowed input I
instead of checking I
?
I think there seems to be no use case that input I
should be applied.
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.
It is true that there is no reason to pass I
with sparse format, so I don't think we need to allow I
.
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.
Yes that's true, strictly speaking there's not reason to pass I
. But it might be restrictive to explicitly forbid it because (1) if a user happens to have strings with I
in them they would have to clean the string, which can be cumbersome (maybe the string is automatically constructed) and (2) we would have to add a check whether I
is included. I think it would be easier for both users and us if we just allow any Pauli string.
We could of course clean the input strings and only store the non-I
ones, that might be good 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.
Then I feel that it is ok to not check I
for the first version. Personally, I am concerned that it would complicate the implementation. As long as we make errors as long as the output is clearly strange (as issue pointed out), we don't have problems.
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.
There are a few ways to implement it which a not complicating the implementation I think 🙂 For example one of the following 2:
- Just check if
indices
contains duplicated (that might be even simpler than the current code 🙂)
if do_checks and np.unique(indices).size == len(indices):
# raise error
- At the beginning, populate
labels
withNone
and use the check that you currently have. Then at the end replace all leftNone
s with"I"
🙂
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.
Both has extra computational cost, but I'd prefer 1 using set
.
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 fixed the check condition. Could you review it?
Pull Request Test Coverage Report for Build 2494403645
💛 - Coveralls |
Co-authored-by: Ikko Hamamura <[email protected]>
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.
@daiki0623 Thank you. LGTM. I'll wail @Cryoris's review.
releasenotes/notes/add_check_from_sparse_list-97f13fde87c7bcb6.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.
LGTM thanks for the contribution @daiki0623!
Summary
Added a check process discussed in #7916.
Details and comments
.from_sparse_list
raiseQiskitError
.do_check
flag to be able to turn off the check.Note: This is a part of QAMP spring 22