cirq.MatrixGate

class cirq.MatrixGate(matrix: numpy.ndarray, *, qid_shape: Optional[Iterable[int]] = None)[source]

A unitary qubit or qudit gate defined entirely by its matrix.

__init__(matrix: numpy.ndarray, *, qid_shape: Optional[Iterable[int]] = None) → None[source]

Initializes a matrix gate.

Parameters
  • matrix – The matrix that defines the gate.

  • qid_shape – The shape of state tensor that the matrix applies to. If not specified, this value is inferred by assuming that the matrix is supposed to apply to qubits.

Methods

controlled([num_controls, control_values, …])

Returns a controlled version of this gate. If no arguments are

num_qubits()

The number of qubits this gate acts on.

on(*qubits)

Returns an application of this gate to the given qubits.

validate_args(qubits)

Checks if this gate can be applied to the given qubits.

wrap_in_linear_combination([coefficient])