cirq.act_on
Applies an action to a state argument.
cirq.act_on(
action: Any,
sim_state: 'cirq.SimulationStateBase',
qubits: Optional[Sequence['cirq.Qid']] = None,
*,
allow_decompose: bool = True
)
For example, the action may be a cirq.Operation
and the state argument may
represent the internal state of a state vector simulator (a
cirq.StateVectorSimulationState
).
For non-operations, the qubits
argument must be explicitly supplied.
The action is applied by first checking if action._act_on_
exists and
returns True
(instead of NotImplemented
) for the given object. Then
fallback strategies specified by the state argument via _act_on_fallback_
are attempted. If those also fail, the method fails with a TypeError
.
Args |
action
|
The operation, gate, or other to apply to the state tensor.
|
sim_state
|
A mutable state object that should be modified by the
action. May specify an _act_on_fallback_ method to use in case
the action doesn't recognize it.
|
qubits
|
The sequence of qubits to use when applying the action.
|
allow_decompose
|
Defaults to True. Forwarded into the
_act_on_fallback_ method of sim_state . Determines if
decomposition should be used or avoided when attempting to act
action on sim_state . Used by internal methods to avoid
redundant decompositions.
|
Returns |
Nothing. Results are communicated by editing sim_state .
|
Raises |
ValueError
|
If called on an operation and supplied qubits, if not called
on an operation and no qubits are supplied, or if _act_on_ or
_act_on_fallback_ returned something other than True or
NotImplemented .
|
TypeError
|
Failed to act action on sim_state .
|
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.
[[["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."],[],[]]