-
Notifications
You must be signed in to change notification settings - Fork 1.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 qudits in drop_terminal_measurements #6879
Handle qudits in drop_terminal_measurements #6879
Conversation
This allows drop_terminal_measurements to work for qudits, which failed on the `I` application, given invert_mask values are undefined for them anyway.
… qubit was being removed completely if a terminal measurement was the only thing it contained.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6879 +/- ##
==========================================
- Coverage 97.87% 97.86% -0.01%
==========================================
Files 1084 1084
Lines 94420 94447 +27
==========================================
+ Hits 92409 92435 +26
- Misses 2011 2012 +1 ☔ View full report in Codecov by Sentry. |
glitchy test again? It failed on |
Yeah, I get that one too. I opened issue #6906 and will try to get to the bottom of it. |
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's a little ridiculous we don't have a proper qudit X gate, but I suppose that's not the fault of this PR. LGTM.
@dstrain115 X and Z already generalize to qudits: #4919. X on qudits is equivalent to I just remembered I had a PR that adapts gates to a subspace of a qudit: #4783. That would be a generalization of what we'd need here. To swap 0,1, |
@daxfohl Ah, ok. The definition I have seen of a qudit X gate is like X_0,1 which would swap the |0> and |1> subspaces. I am not sure there's a great standard for this since qudit operations are a less trod ground. Thanks for the flurry of changes lately! |
@dstrain115 Yeah, there was some discussion on the original issue #3190, that both approaches were reasonable, but the group seemed to converge on the The (I'm not advocating for pulling in any of those gates; just leaving this as an FYI in case it comes up in the future). |
Explicitly set the dimension of the X's and I's corresponding to the invert_mask in
drop_terminal_measurements
to avoid the ValueError that was raised when the invert_mask was applied to qudits.Fixes #5994
Note the weird MatrixGate swaps the 0 and 1 dimensions on qudits, leaving other dimensions unchanged. This behavior is consistent with the invert_mask implementation at https://github.com/quantumlib/cirq/blob/3fefe2984a1203c0bf647c1ea84f4882b05f8477/cirq-core/cirq/sim/simulator.py#L823, which has been in place since 2020. If there's a
DimensionSwapGate
or something, we could use that here instead, but I didn't see one.