-
Notifications
You must be signed in to change notification settings - Fork 201
Fix #855: don't call cirq.unitary() on non-unitary matrices #857
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1057,7 +1057,17 @@ def __init__(self, *args, **kwargs): | |
| super().__init__(*args, **kwargs) | ||
|
|
||
| def _mixture_(self): | ||
| return [(prob, cirq.unitary(op)) for prob, op, in self._prob_op_pairs] | ||
| # Cirq's mixture() function in mixture_protocol.py returns tuples of | ||
| # the form (probability, unitary peration). It does this by applying | ||
| # Cirq's unitary() function to the second elements of the tuples | ||
| # returned from here. Now, the values in self._prob_op_pairs will be | ||
| # tuples of the form (probability, NoiseStep). NoiseStep defines a | ||
| # _unitary_() method that simply returns the array as-is. Thus, when | ||
| # Cirq's mixture() function gets the value returned here and calls | ||
| # unitary() on those NoiseStep objects, the values unitary() returns | ||
| # will not actually be unitary. This is done knowingly. The nonunitary | ||
| # values are eventually normalized in test_multi_qubit_noise(). | ||
| return [(prob, op) for prob, op, in self._prob_op_pairs] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is _mixture a standard protocol for qsim or is this only used for this test? This is changing the return type for this method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I didn't realize op was already a np.array.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. It's true that the 2nd element in the tuples in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, with the way this all routed between different functions, I can't find a way to avoid changing this return type without rewriting I added a comment explaning what is happening. @dstrain115 can you check that it makes sense?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Actuallly, I was wrong about that in my earlier comment (which I deleted too slowly to save you typing that reply -- sorry about that). At this point in the flow of things, it's not an ndarray. The whole flow is a bit more complicated, which hopefully the new comment clarifies. |
||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
|
|
@@ -2025,11 +2035,11 @@ def test_qsimcirq_identity_expectation_value(): | |
| for w, pauli in objs: | ||
| pauli = pauli[::-1] | ||
| hamiltonian += float(w) * cirq.PauliString( | ||
| cirq.I(cirq.LineQubit(i)) | ||
| if p == "I" | ||
| else cirq.Z(cirq.LineQubit(i)) | ||
| if p == "Z" | ||
| else None | ||
| ( | ||
| cirq.I(cirq.LineQubit(i)) | ||
| if p == "I" | ||
| else cirq.Z(cirq.LineQubit(i)) if p == "Z" else None | ||
| ) | ||
| for i, p in enumerate(pauli) | ||
| ) | ||
|
|
||
|
|
||
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.
peration-->operation