Skip to content

Allow intercepting decomposer while preserving structure. #4343

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

Merged
merged 2 commits into from
Jul 21, 2021

Conversation

95-martin-orion
Copy link
Collaborator

This allows users to specify an intercepting decomposer (i.e. one that runs before default decomposition behavior) and use structure-preserving behavior (i.e. keeping CircuitOperations but decomposing their contents) in the same decompose call.

This is a prerequisite for allowing CircuitOperations in cirq.optimized_for_sycamore.

@95-martin-orion 95-martin-orion requested review from cduck, vtomole and a team as code owners July 21, 2021 14:06
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Jul 21, 2021
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines -123 to -143
@overload
def decompose(
val: Any,
*,
intercepting_decomposer: Optional[OpDecomposer] = None,
fallback_decomposer: Optional[OpDecomposer] = None,
keep: Optional[Callable[['cirq.Operation'], bool]] = None,
) -> List['cirq.Operation']:
pass


@overload
def decompose(
val: Any,
*,
intercepting_decomposer: Optional[OpDecomposer] = None,
fallback_decomposer: Optional[OpDecomposer] = None,
keep: Optional[Callable[['cirq.Operation'], bool]] = None,
on_stuck_raise: Union[None, TError, Callable[['cirq.Operation'], Optional[TError]]],
) -> List['cirq.Operation']:
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious why exactly are these definitions getting nuked ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Official answer: they're 100% redundant with the method they're overloading - if anything was calling one of these, it could instead call the remaining decompose method with no change in behavior.

Actual answer: mypy was complaining about these methods, and I realized they weren't necessary 😛

Comment on lines +241 to +243
# pylint: disable=function-redefined


Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: this looks like it's no longer needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is still needed for the other overloaded methods in this file.

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jul 21, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jul 21, 2021
@CirqBot CirqBot merged commit 055db68 into quantumlib:master Jul 21, 2021
@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 Jul 21, 2021
@95-martin-orion 95-martin-orion deleted the cirq-enable-cop-serial-0 branch July 21, 2021 17:42
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…#4343)

This allows users to specify an intercepting decomposer (i.e. one that runs before default decomposition behavior) and use structure-preserving behavior (i.e. keeping `CircuitOperation`s but decomposing their contents) in the same `decompose` call.

This is a prerequisite for allowing `CircuitOperation`s in `cirq.optimized_for_sycamore`.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
…#4343)

This allows users to specify an intercepting decomposer (i.e. one that runs before default decomposition behavior) and use structure-preserving behavior (i.e. keeping `CircuitOperation`s but decomposing their contents) in the same `decompose` call.

This is a prerequisite for allowing `CircuitOperation`s in `cirq.optimized_for_sycamore`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants