cirq.decompose
Recursively decomposes a value into cirq.Operation
s meeting a criteria.
cirq.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, Exception, Callable[['cirq.Operation'], Optional[Exception]]] = _value_error_describing_bad_operation,
preserve_structure: bool = False,
context: Optional[cirq.DecompositionContext
] = None
) -> List['cirq.Operation']
Used in the notebooks
Args |
val
|
The value to decompose into operations.
|
intercepting_decomposer
|
An optional method that is called before the
default decomposer (the value's _decompose_ method). If
intercepting_decomposer is specified and returns a result that
isn't NotImplemented or None , that result is used. Otherwise the
decomposition falls back to the default decomposer.
Note that val will be passed into intercepting_decomposer , even
if val isn't a cirq.Operation .
|
fallback_decomposer
|
An optional decomposition that used after the
intercepting_decomposer and the default decomposer (the value's
_decompose_ method) both fail.
|
keep
|
A predicate that determines if the initial operation or
intermediate decomposed operations should be kept or else need to be
decomposed further. If keep isn't specified, it defaults to "value
can't be decomposed anymore".
|
on_stuck_raise
|
If there is an operation that can't be decomposed and
also can't be kept, on_stuck_raise is used to determine what error
to raise. on_stuck_raise can either directly be an Exception , or
a method that takes the problematic operation and returns an
Exception . If on_stuck_raise is set to None or a method that
returns None , non-decomposable operations are simply silently
kept. on_stuck_raise defaults to a ValueError describing the
unwanted non-decomposable operation.
|
preserve_structure
|
Prevents subcircuits (i.e. CircuitOperation s)
from being decomposed, but decomposes their contents. If this is
True, intercepting_decomposer cannot be specified.
|
context
|
Decomposition context specifying common configurable options for
controlling the behavior of decompose.
|
Returns |
A list of operations that the given value was decomposed into. If
on_stuck_raise isn't set to None, all operations in the list will
satisfy the predicate specified by keep .
|
Raises |
TypeError
|
val isn't a cirq.Operation and can't be decomposed even once.
(So it's not possible to return a list of operations.)
|
ValueError
|
Default type of error raised if there's an non-decomposable
operation that doesn't satisfy the given keep predicate.
|
TError
|
Custom type of error raised if there's an non-decomposable operation
that doesn't satisfy the given keep predicate.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-06-27 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-06-27 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-27 UTC."],[],[]]