-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
enable inverse of classically conditioned gate #6829
base: main
Are you sure you want to change the base?
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.
Mostly looks good to me - a couple of minor comments on documentation only. It's difficult to check completeness in a diff (in the sense that it's difficult to see if condition
has been missed anywhere), but it looks like it's gone through all the important files.
num_qubits: int, | ||
params: List, | ||
label: Optional[str] = None, | ||
condition: Optional[Tuple] = None, |
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 new docstring for "condition" needs to be here as well.
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.
added
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.
As a philosophical question, is it necessary to add a condition kwarg to all these gates? Wouldn't it be simpler to set the condition at the Instruction parent level? For example, in x.py,
def inverse(self):
x_inv = XGate()
x_inv.condition = self.condition
return x_inv
This way you're taking care of the issue at the inverse() level and leaving the gate def simpler.
To me, setting parameters after construction is a slightly strange idiom, because you're basically pushing responsibility for initialising an object onto the user, and drawing an arbitrary line between what's passed to the initialiser and what's not (there's also 'label' in the initialiser). There's also a usability concern with this sort of separation: you can't create the object and use it inside another function call any more, because initialisation is two statements. That can be quite an annoyance for people working interactively. Maybe it's me coming from a slightly more immutable-by-default background, though - I've never done large-scale pure OO. |
Currently in qiskit, the |
I still don't like the idea of promoting manually assigning to a parameter, because as it currently stands that elides all error-checking, so it's not what we would want users to do. If we don't want to add to the initialiser, then it might be nice if the inverse functions looked like def inverse(self):
return XGate().c_if(*self.condition) and also the |
Co-authored-by: Jake Lishman <jake@binhbar.com>
Right. Definitely should be all or nothing, but is this the place to do it? Your |
The I agree with @jakelishman about making it possible to set all properties of the instruction through its Also, it was the intention to add this to all gates of the library. I'll add those. Please let me know what I miss. |
|
@jakelishman I'm adding |
ah, a github-comment race condition! I hadn't seen your message beforehand! |
Summary
This PR enables the preservation of the classical condition for the inverse of a classically conditioned gate.
Also added is the ability to initialize the classical condition during instruction instantiation which should help with progress toward issue #2439.
Fixes #6810
Details and comments