# cirq.MeasurementGate¶

class cirq.MeasurementGate(num_qubits: Optional[int] = None, key: str = '', invert_mask: Tuple[bool, …] = (), qid_shape: Tuple[int, …] = None)[source]

A gate that measures qubits in the computational basis.

The measurement gate contains a key that is used to identify results
of measurements.
__init__(num_qubits: Optional[int] = None, key: str = '', invert_mask: Tuple[bool, …] = (), qid_shape: Tuple[int, …] = None) → None[source]
Parameters
• num_qubits – The number of qubits to act upon.

• key – The string key of the measurement.

• invert_mask – A list of values indicating whether the corresponding qubits should be flipped. The list’s length must not be longer than the number of qubits, but it is permitted to be shorter. Qubits with indices past the end of the mask are not flipped.

• qid_shape – Specifies the dimension of each qid the measurement applies to. The default is 2 for every qubit.

Raises

ValueError – If the length of invert_mask is greater than num_qubits. or if the length of qid_shape doesn’t equal num_qubits.