-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add cirq.toggle_tags
helper to apply transformers on specific subsets of operations in a circuit
#4973
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.
If the intended use case for this is large circuits, is performance overhead a concern? It seems like an explicit tags_to_apply_on
would be cheaper. (Not super worried about this, just curious)
@@ -426,3 +426,18 @@ def unroll_circuit_op_greedy_frontier( | |||
) | |||
frontier = unrolled_circuit.insert_at_frontier(sub_circuit.all_operations(), idx, frontier) | |||
return _to_target_circuit_type(unrolled_circuit, circuit) | |||
|
|||
|
|||
def xor_ops_with_tags(circuit: CIRCUIT_TYPE, tags: Sequence[Hashable], *, deep: bool = False): |
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.
Please add a function docstring.
Also, I'm not sure about this name - we're not xor'ing ops, we're xor'ing their tags. Maybe (as used in the test) "flip_tags" or "toggle_tags" would be clearer?
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, naming this method is hard. changed to toggle_tags
and added a docstring
cirq.testing.assert_same_circuits( | ||
cirq.xor_ops_with_tags( | ||
cirq.align_left( | ||
cirq.xor_ops_with_tags(c_orig, [tag]), |
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.
What is going on here? Is the xor a necessary step for alignment, or just a test element to verify proper behavior of align_left
?
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.
So in the example here, directly doing an align_left
on the entire circuit would cause both X(q1)
and Y(q2)
in moments 2 & 3 (0-based indexing) to move left. But by adding a tag to X(q1)
and using xor_ops_with_tags
to toggle tags --> do optimization --> toggle tags again, we are able to do the transformation only the subset of operations that are tagged -- therefore only X(q1)
aligns to the left but Y(q2)
stays in-place.
I think the maintenance overhead to modify every individual transformer implementation to support both Addressed other feedback. PTAL. |
xor_ops_with_tags
helper to apply transformers on specific subsets of operations in a circuitcirq.toggle_tags
helper to apply transformers on specific subsets of operations in a circuit
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, the docstring explanation is a great reference.
…ts of operations in a circuit (quantumlib#4973) * Add helper to apply transformers on specific subsets of operations in a circuit * Rename to toggle_tags and address feedback
…ts of operations in a circuit (quantumlib#4973) * Add helper to apply transformers on specific subsets of operations in a circuit * Rename to toggle_tags and address feedback
…ts of operations in a circuit (quantumlib#4973) * Add helper to apply transformers on specific subsets of operations in a circuit * Rename to toggle_tags and address feedback
Adds indirect capability to apply a transformer, that supports ignoring
tags_to_ignore
, on a specific subset of operations in a large circuit.Fixes #4972
A step towards fixing #3144