cirq.apply_unitaries(unitary_values: Iterable[Any], qubits: Sequence[cirq.Qid], args: Optional[cirq.protocols.apply_unitary_protocol.ApplyUnitaryArgs] = None, default: Any = array([], dtype=float64)) → Optional[numpy.ndarray][source]

Apply a series of unitaries onto a state tensor.

Uses cirq.apply_unitary on each of the unitary values, to apply them to
the state tensor from the args argument.
CAUTION: if one of the given unitary values does not have a unitary effect,
forcing the method to terminate, the method will not rollback changes
from previous unitary values.
  • unitary_values – The values with unitary effects to apply to the target.

  • qubits – The qubits that will be targeted by the unitary values. These qubits match up, index by index, with the indices property of the args argument.

  • args – A mutable cirq.ApplyUnitaryArgs object describing the target tensor, available workspace, and axes to operate on. The attributes of this object will be mutated as part of computing the result. If not specified, this defaults to the zero state of the given qubits with an axis ordering matching the given qubit ordering.

  • default – What should be returned if any of the unitary values actually don’t have a unitary effect. If not specified, a TypeError is raised instead of returning a default value.


If any of the unitary values do not have a unitary effect, the specified default value is returned (or a TypeError is raised). CAUTION: If this occurs, the contents of args.target_tensor and args.available_buffer may have been mutated.

If all of the unitary values had a unitary effect that was successfully applied, this method returns the np.ndarray storing the final result. This np.ndarray may be args.target_tensor, args.available_buffer, or some other instance. The caller is responsible for dealing with this potential aliasing of the inputs and the result.


TypeError – An item from unitary_values doesn’t have a unitary effect and default wasn’t specified.