-
Notifications
You must be signed in to change notification settings - Fork 1.2k
GateFamily: tag validation #5101
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
GateFamily: tag validation #5101
Conversation
1b45095 to
49683b1
Compare
dstrain115
left a comment
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.
Looks good to me aside from the JSON test failures.
49683b1 to
7ef0296
Compare
d068423 to
67e884b
Compare
3c91da5 to
346ea2e
Compare
346ea2e to
4564e37
Compare
|
This PR is ready for review again! |
tanujkhattar
left a comment
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 % nits
cirq-core/cirq/ops/gateset.py
Outdated
| description: Human readable description of the gate family. | ||
| ignore_global_phase: If True, value equality is checked via | ||
| `cirq.equal_up_to_global_phase`. | ||
| tags_to_accept: If non-empty, only `Operations` containing at least one tag in this |
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.
| tags_to_accept: If non-empty, only `Operations` containing at least one tag in this | |
| tags_to_accept: If non-empty, only `cirq.Operation` containing at least one tag in this |
cirq-core/cirq/ops/gateset.py
Outdated
| >>> assert cirq.Rx(rads=np.pi) in gate_family | ||
| >>> assert cirq.X ** sympy.Symbol("theta") in gate_family | ||
| Tags can be used to add further constraints on containment checks using `tags_to_accept` and |
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.
In the docstring, let's try to be consistent with how we use backticks. In general, the reference docs will automatically create a hyperlink to the reference page of an object if it's a public object. Eg: cirq.Operation will hyperlink but Operation and Operations will not.
It would also be nice if we can make the docstring slightly more concise. For example:
As seen in the examples above, `GateFamily` supports containment checks for instances of both `cirq.Operation` and `cirq.Gate`. By default, a `cirq.Operation` instance `op` is accepted if the underlying `op.gate` is accepted.
Further constraints can be added on containment checks for `cirq.Operation` objects by setting `tags_to_accept` and / or `tags_to_ignore` in the `GateFamily` constructor. For a tagged operation, the underlying gate `op.gate` will be checked for containment only if:
*`op.tags` has no intersection with `tags_to_ignore` and
* if `tags_to_accept` is non-empty, then `op.tags` should have a non-zero intersection with `tags_to_accept`.
For example:
.... (copy examples from below) ....
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.
Sounds good. I will remove the code block explaining the semantics and replace it with your bullet list suggestion, but I will keep "If an Operation contains tags..." and "For the purpose of tag comparisons..." since they explain additional behaviors not covered by the above.
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'm omitting ticks around "GateFamily" to be consistent with the docstring before this section, but let me know if you prefer including them. Will hyperlinking work properly in this case since it's referring to the class for which the docstring is defined?
39e0279 to
9dee385
Compare
9dee385 to
bde310e
Compare
Adding general validation of gate tags to GateFamily, as described in quantumlib#5063 (comment) Replaces quantumlib#5063 @tanujkhattar
Adding general validation of gate tags to GateFamily, as described in quantumlib#5063 (comment) Replaces quantumlib#5063 @tanujkhattar
Adding general validation of gate tags to GateFamily, as described in #5063 (comment)
Replaces #5063
@tanujkhattar