-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Optimize standard gate library equality #11370
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
Changes from all commits
a993f95
18620a0
7f863e5
d46cf05
069184f
9262341
0092376
5a27017
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,3 +112,6 @@ def _define(self): | |
| def inverse(self): | ||
| """Return inverse ECR gate (itself).""" | ||
| return ECRGate() # self-inverse | ||
|
|
||
| def __eq__(self, other): | ||
| return isinstance(other, ECRGate) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone were to extend def __eq__(self, other):
return isinstance(other, type(self))
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That wouldn't actually be correct for singleton gates, where the singleton instance is a separate part of the inheritance tree to the non-singleton versions. I'm not super convinced that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I forgot about that nuance with the class hierarchy. It seems to me like |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,6 +101,9 @@ def inverse(self): | |
| r"""Return inverted H gate (itself).""" | ||
| return HGate() # self-inverse | ||
|
|
||
| def __eq__(self, other): | ||
| return isinstance(other, HGate) | ||
|
|
||
|
|
||
| @with_controlled_gate_array(_H_ARRAY, num_ctrl_qubits=1) | ||
| class CHGate(SingletonControlledGate): | ||
|
|
@@ -222,3 +225,6 @@ def _define(self): | |
| def inverse(self): | ||
| """Return inverted CH gate (itself).""" | ||
| return CHGate(ctrl_state=self.ctrl_state) # self-inverse | ||
|
|
||
| def __eq__(self, other): | ||
| return isinstance(other, CHGate) and self.ctrl_state == other.ctrl_state | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment. Perhaps a shared implementation is possible for all |
||
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.
I guess specifically this is stdlib-gate parameters, but that's fine.
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.
Yeah it's why I made it private, I can add a comment or docstring for it. Or were you propoposing I rename it
_compare_stdlib_gate_parameters()?