|View source on GitHub|
High performance evolution under a mixture of unitaries evolution.
cirq.protocols.apply_mixture( val: Any, args:
cirq.protocols.ApplyMixtureArgs, *, default:
cirq.protocols.apply_mixture_protocol.TDefault= cirq.protocols.apply_mixture_protocol.RaiseTypeErrorIfNotProvided ) -> Union[np.ndarray,
Follows the steps below to attempt to apply a mixture:
A. Try to use
1. If `_apply_mixture_` is not present or returns NotImplemented go to step B. 2. If '_apply_mixture_' is present and returns None conclude that `val` has no effect and return. 3. If '_apply_mixture_' is present and returns a numpy array conclude that the mixture was applied successfully and forward result to caller.
B. Construct an ApplyUnitaryArgs object
args and then
try to use
cirq.apply_unitary(val, uargs, None).
1. If `None` is returned then go to step C. 2. If a numpy array is returned forward this result back to the caller and return.
C. Try to use
1. If '_mixture_' is not present or returns NotImplemented go to step D. 2. If '_mixture_' is present and returns None conclude that `val` has no effect and return. 3. If '_mixture_' returns a list of tuples, loop over the list and examine each tuple. If the tuple is of the form `(probability, np.ndarray)` use matrix multiplication to apply it. If the tuple is of the form `(probability, op)` where op is any op, attempt to use <a href="../../cirq/protocols/apply_unitary"><code>cirq.apply_unitary(op, uargs, None)</code></a>. If this operation returns None go to step D. Otherwise return the resulting state after all of the tuples have been applied.
D. Raise TypeError or return
||The value with a mixture to apply to the target.|
What should be returned if
If the receiving object is not able to apply a mixture,
the specified default value is returned (or a TypeError is raised). If
this occurs, then
If the receiving object was able to work inline, directly
If the receiving object wrote its output over
Note that it is an error for the return object to be either of the auxiliary buffers, and the method will raise an AssertionError if this contract is violated.
The receiving object may also write its output over a new buffer that it created, in which case that new array is returned.
Different left and right shapes of