Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions qsimcirq_tests/qsimcirq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 operation). 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]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't realize op was already a np.array.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. It's true that the 2nd element in the tuples in self._prob_op_pairs are actually NoiseStep objects. Lemme see if I can improve this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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 test_multi_qubit_noise(). Given that this object class is only used in this file and only for that one function, that seems like it would be poor ROI.

I added a comment explaning what is happening. @dstrain115 can you check that it makes sense?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't realize op was already a np.array.

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(
Expand Down Expand Up @@ -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)
)

Expand Down
Loading