-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Remove axes from ActOnArgs, pass qubits explicitly to act_on #4089
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
Conversation
I'm committing to reviewing this PR this week. |
Cool, one thing I've been thinking about since submitting this is, there's three different ways to do this. They're only stylistic differences, but we should choose the style we like before merging.
I'm not hugely in favor of any one versus any of the others. I could write up an RFC but I don't think there's much to add beyond the above. |
Actually I lied. I think I'm slightly in favor of the third option if it comes down to it. And given this would be a breaking change for anyone currently using |
I also like the reduced ambiguity of the third option listed. That said, you're right about this being a breaking change - and by extension, unless we're really confident that there are no external users for this, we'll need to go through the appropriate deprecation steps (likely involving Let's bring this up in the Cirq sync to check - I've marked this with |
An RFC shouldn't be necessary, unless you think it would make presenting this decision clearer. |
SGTM, though my availability for cynq is still limited. If we do end up deciding to go with the full safe deprecation path, this is definitely going to add some complexity. Just marking the |
Changed to the third option. I like it better. |
Added a deprecation path as mentioned in the above comment. |
This should be ready to go. |
From @cduck at the Cirq sync: prefer not having a separate dunder method for the new protocol. |
i.e., if we have a separate |
Pretty sure that could be done with a global find/replace, so no problem accommodating that request if we decide to go that way. |
If we do, I kind of feel like we should also go back to the original way of having the optional qubits parameter in the original act_on protocol, rather than creating a separate act_on_qubits protocol. My Java/C# self prefers the explicitness of having distinct protocols, but perhaps it's more pythonic to have a single function that can be used for both cases. ...In fact as I reflect further on it, I'm pretty sure it is. Shall I change it back to a single protocol then? |
I think that's reasonable. The only counterexample to this I can find in Cirq is |
gtg now |
…lib#4089) * Remove axes from ActOnArgs, pass qubits explicitly * split protocols * require ActOnArgs to implement fallback * lint * Split the protocols * Fix tests and coverage * coverage * format * make param order consistent * format * add deprecation for axes * v0.13 * lint * readd axes with mypy ignore * safe * deprecate * fix args len * tests * lint * lint * cover * Change _act_on_qubits_ dunder back to _act_on_ * format * unify act_on * lint * exception * test * format * SupportsActOnQubits
…lib#4089) * Remove axes from ActOnArgs, pass qubits explicitly * split protocols * require ActOnArgs to implement fallback * lint * Split the protocols * Fix tests and coverage * coverage * format * make param order consistent * format * add deprecation for axes * v0.13 * lint * readd axes with mypy ignore * safe * deprecate * fix args len * tests * lint * lint * cover * Change _act_on_qubits_ dunder back to _act_on_ * format * unify act_on * lint * exception * test * format * SupportsActOnQubits
The current implementation of ActOnArgs requires two steps to "act on" an operation. First you have to manually set the axes, then you call the act_on protocol. This is confusing and creates opportunities for bugs to slip in when users forget to set the axes, and it shouldn't be necessary because the
Operation
that's being passed toact_on
contains all the necessary information.This PR fixes that problem by requiring qubits to be passed explicitly to the
act_on
protocol, either by passing as theaction
parameter anOperation
that contains the qubits, or by explicitly passing thequbits
parameter if theaction
is a gate or similar. Note there's a check, you cannot pass both anOperation
and assign thequbits
parameter; it has to be one or the other.It touches a lot of files and lines, but it's mostly just adding the explicit parameter passing, and updating lots of unit tests to do so. The core changes are in
act_on_args
andact_on_protocol
.