cirq.unitary

cirq.unitary(val: Any, default: TDefault = array([], dtype=float64)) → Union[numpy.ndarray, TDefault][source]

Returns a unitary matrix describing the given value.

Parameters:
  • val – The value to describe with a unitary matrix.
  • default – Determines the fallback behavior when val doesn’t have a unitary matrix. If default is not set, a TypeError is raised. If default is set to a value, that value is returned.
Returns:

If val has a _unitary_ method and its result is not NotImplemented, that result is returned. Otherwise, if val is a cirq.Gate or cirq.Operation, decomposition will be attempted and the resulting unitary is returned if unitaries exist for all operations of the decompostion. If the result is still NotImplemented and a default value was specified, the default value is returned.

Raises:

TypeErrorval doesn’t have a _unitary_ method (or that method returned NotImplemented) and also no default value was specified.