Circuit.apply_unitary_effect_to_state(initial_state: Union[int, numpy.ndarray] = 0, qubit_order: Union[cirq.ops.qubit_order.QubitOrder, Iterable[cirq.ops.raw_types.Qid]] = <cirq.ops.qubit_order.QubitOrder object>, qubits_that_should_be_present: Iterable[cirq.ops.raw_types.Qid] = (), ignore_terminal_measurements: bool = True, dtype: Type[numpy.number] = <class 'numpy.complex128'>) → numpy.ndarray[source]

Left-multiplies a state vector by the circuit’s unitary effect.

A circuit’s “unitary effect” is the unitary matrix produced by
multiplying together all of its gates’ unitary matrices. A circuit
with non-unitary gates (such as measurement or parameterized gates) does
not have a well-defined unitary effect, and the method will fail if such
operations are present.
For convenience, terminal measurements are automatically ignored
instead of causing a failure. Set the ignore_terminal_measurements
argument to False to disable this behavior.
This method is equivalent to left-multiplying the input state by
cirq.unitary(circuit) but it’s computed in a more efficient
  • initial_state – The input state for the circuit. This can be an int or a vector. When this is an int, it refers to a computational basis state (e.g. 5 means initialize to |5⟩ = |...000101⟩). If this is a state vector, it directly specifies the initial state’s amplitudes. The vector must be a flat numpy array with a type that can be converted to np.complex128.
  • qubit_order – Determines how qubits are ordered when passing matrices into np.kron.
  • qubits_that_should_be_present – Qubits that may or may not appear in operations within the circuit, but that should be included regardless when generating the matrix.
  • ignore_terminal_measurements – When set, measurements at the end of the circuit are ignored instead of causing the method to fail.
  • dtype – The numpy dtype for the returned unitary. Defaults to np.complex128. Specifying np.complex64 will run faster at the cost of precision. dtype must be a complex np.dtype, unless all operations in the circuit have unitary matrices with exclusively real coefficients (e.g. an H + TOFFOLI circuit).

A (possibly gigantic) numpy array storing the superposition that came out of the circuit for the given input state.

  • ValueError – The circuit contains measurement gates that are not ignored.
  • TypeError – The circuit contains gates that don’t have a known unitary matrix, e.g. gates parameterized by a Symbol.