Skip to content

Conversation

@verult
Copy link
Collaborator

@verult verult commented Mar 18, 2022

Adding general validation of gate tags to GateFamily, as described in #5063 (comment)

Replaces #5063

@tanujkhattar

@verult verult requested a review from tanujkhattar March 18, 2022 23:04
@verult verult requested review from a team, cduck and vtomole as code owners March 18, 2022 23:04
@CirqBot CirqBot added the size: M 50< lines changed <250 label Mar 18, 2022
@verult verult force-pushed the cg-device-refactor/gatefamily-tags branch 4 times, most recently from 1b45095 to 49683b1 Compare March 22, 2022 01:48
Copy link
Collaborator

@dstrain115 dstrain115 left a 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.

@verult verult force-pushed the cg-device-refactor/gatefamily-tags branch from 49683b1 to 7ef0296 Compare March 22, 2022 18:46
@verult verult requested a review from tanujkhattar March 22, 2022 23:45
@verult verult force-pushed the cg-device-refactor/gatefamily-tags branch 2 times, most recently from d068423 to 67e884b Compare March 23, 2022 01:05
@tanujkhattar tanujkhattar self-assigned this Mar 24, 2022
@verult verult force-pushed the cg-device-refactor/gatefamily-tags branch from 3c91da5 to 346ea2e Compare March 30, 2022 02:08
@verult verult requested a review from tanujkhattar March 30, 2022 05:39
@verult verult force-pushed the cg-device-refactor/gatefamily-tags branch from 346ea2e to 4564e37 Compare March 30, 2022 21:50
@verult
Copy link
Collaborator Author

verult commented Apr 4, 2022

This PR is ready for review again!

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % nits

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

>>> 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
Copy link
Collaborator

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) ....

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

@verult verult force-pushed the cg-device-refactor/gatefamily-tags branch 4 times, most recently from 39e0279 to 9dee385 Compare April 26, 2022 21:45
@verult verult force-pushed the cg-device-refactor/gatefamily-tags branch from 9dee385 to bde310e Compare April 26, 2022 22:03
@verult verult added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Apr 26, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Apr 26, 2022
@CirqBot CirqBot merged commit 13d87d1 into quantumlib:master Apr 26, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Apr 26, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Adding general validation of gate tags to GateFamily, as described in quantumlib#5063 (comment)

Replaces quantumlib#5063

@tanujkhattar
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Adding general validation of gate tags to GateFamily, as described in quantumlib#5063 (comment)

Replaces quantumlib#5063

@tanujkhattar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants