-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Handle confusion matrices in deferred measurements #5851
Conversation
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.
The idea behind this PR is sound. The step that might make one uneasy is the confusion-matrix channel since it assumes the input density matrix is diagonal. This step is correct, because measurement may be thought to entail the application of the completely dephasing channel which kills all off-diagonal elements.
However, I have some comments about the implementation.
Thanks for the review! I'll clean up these items. Nit on the review: these channel don't require the DM to be diagonal a priori. They just ignore anything not in the diagonal. |
Re nit on the review: Well, if you call it a "channel" then you should insist that the input density matrix be diagonal. Otherwise it fails to be a channel. By definition, channels map positive semi-definite matrices to positive semi-definite matrices. This property is lost when you apply a confusion matrix to the diagonal entries while leaving the off-diagonal entries alone. For example, the result of applying the confusion matrix that maps both 0 and 1 to 0 to the diagonal of is which is not positive semi-definite (since its determinant is negative). I suppose an alternative would be to use something like the Generalized Amplitude Damping Channel, but this seems like an overkill for your use-case (and it would make it harder to fix #5901, so let's not do this). |
Consolidating a few threads since they kind of lead into each other:
|
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
Below are replies to your larger comment. For clarity, I'll use a few ad hoc definitions:
CMC = Confusion Matrix Channel, acts on diagonal, assumes all other elements are zero (IOW, it's not a quantum channel, but a map acting on classical probability distributions encoded in the computational basis)
CDC = Completely Dephasing Channel, zeroes out off-diagonal elements (it's a quantum channel that outputs the classical probability distribution associated with the computational basis measurement on the input state).
CC = Confusion Channel, CDC followed by CMC.
- Yes, CC is a valid quantum channel (CMC is not).
- Yes, the input is typically not diagonal, but the output is (block) diagonal. In other words, your CC channel entails an implicit CDC. I agree that you don't have to dephase, but at present, you actually do dephase! :-) Either way is correct because phase-flip channels such as CDC don't affect measurement and commute with the operations that may appear on the ancilla (control of other gates and bit-flip channel due to inversion mask). A benefit of the fact that you apply the CDC is that it creates opportunities for performance optimization since CDC zeroes out a bunch of entries in the density matrix. As agreed, this optimization is out-of-scope for this PR. A downside of CDC is that your CC channel will indeed block the Clifford simulator.
- No. Your CC is guaranteed to output a (block) diagonal matrix since all Kraus operators have the form
$\sqrt{p_{ij}}|j\rangle\langle i|$ where$p_{ij}$ is an appropriate entry from the confusion matrix. Therefore, every term in$\mathcal{E}(\rho)$ looks like$p_{ij}\cdot \langle i|\rho|i\rangle \cdot |j\rangle\langle j|$ . This means that we could implement_ConfusionChannel
very simply without ever computing Kraus operators. Instead, we'd compute$j$ th diagonal block as$\sum_i p_{ij} \cdot \langle i|\rho|i\rangle$ . I'd expect this algorithm to be pretty fast since it avoids matrix multiplications entirely. Note that we should be able to extract the matrix$\langle i|\rho|i\rangle$ from$\rho$ with clever indexing. This is the optimization I have in mind for Use_apply_channel_
when appropriate #5901. In any case, it's fine to do it in a follow-up.
Is https://github.com/quantumlib/Cirq/pull/5905/files is the "clever indexing" you refer to in (3)? That solution is generic and works for any one-hot multiplier, but I closed the PR because it's slower for the normal case. For confusion and reset channels specifically, we could improve further on that by (1) we already know each component is one-hot, so no need to check, (2) we already know the index so there's no need to unravel, and (3) the linked code still does each Kraus component in two steps: left multiply and right multiply; we should be able to do it in a single step. Does this sound correct? Thanks for the thorough review! |
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.
Not exactly. I meant to specialize the application of a specific channel type (here _ConfusionChannel
and also others like reset) rather than modifying a general utility method like targeted_left_multiply
. In other words, I meant to do for channels what we already do for many unitary gates such as X and SWAP (e.g. here). This avoids the need for a check (such as the one using np.flatnonzero
in #5905) and hence has absolutely no impact on operations other than the one being optimized.
Matrix multiplication is very general, but also expensive. Many interesting quantum operations can be viewed in terms of a simple recipe for constructing the output (e.g. swap some input elements; change some signs; set off-diagonal elements to zero then apply confusion matrix to the diagonal etc) rather than as matrix algebra. This view inspired _apply_unitary_
and I think we should pursue it for channels, too.
Handles measurement confusion matrices by substituting with a confusion channel. These channels are derived as described in the `_ConfusionChannel` docstring, and evolve the diagonal of the density matrix in the same way that the confusion matrix operates on the classical state distribution. I hadn't really thought of it before, but when writing the test I realized this is _great_ for sampling circuits with classical controls. Way better performance than having to simulate that same number of iterations due to classical logic.
Handles measurement confusion matrices by substituting with a confusion channel. These channels are derived as described in the `_ConfusionChannel` docstring, and evolve the diagonal of the density matrix in the same way that the confusion matrix operates on the classical state distribution. I hadn't really thought of it before, but when writing the test I realized this is _great_ for sampling circuits with classical controls. Way better performance than having to simulate that same number of iterations due to classical logic.
Handles measurement confusion matrices by substituting with a confusion channel.
These channels are derived as described in the
_ConfusionChannel
docstring, and evolve the diagonal of the density matrix in the same way that the confusion matrix operates on the classical state distribution.I hadn't really thought of it before, but when writing the test I realized this is great for sampling circuits with classical controls. Way better performance than having to simulate that same number of iterations due to classical logic.