-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Allow intercepting decomposer while preserving structure. #4343
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.
LGTM
@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 |
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.
Just curious why exactly are these definitions getting nuked ?
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.
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 😛
# pylint: disable=function-redefined | ||
|
||
|
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.
Nit: this looks like it's no longer needed.
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.
This is still needed for the other overloaded methods in this file.
…#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`.
…#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`.
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 samedecompose
call.This is a prerequisite for allowing
CircuitOperation
s incirq.optimized_for_sycamore
.