def measure(
        self,
        qubits: Sequence[cirq.Qid],
        key: str,
        invert_mask: Sequence[bool],
        confusion_map: dict[tuple[int, ...], np.ndarray],
    ):
        """Measures the qubits and records to `log_of_measurement_results`.

        Any bitmasks will be applied to the measurement record.

        Args:
            qubits: The qubits to measure.
            key: The key the measurement result should be logged under. Note
                that operations should only store results under keys they have
                declared in a `_measurement_key_names_` method.
            invert_mask: The invert mask for the measurement.
            confusion_map: The confusion matrices for the measurement.

        Raises:
            ValueError: If a measurement key has already been logged to a key.
        """
        bits = self._perform_measurement(qubits)
        confused = self._confuse_result(bits, qubits, confusion_map)
        corrected = [bit ^ (bit < 2 and mask) for bit, mask in zip(confused, invert_mask)]
        self._classical_data.record_measurement(
            value.MeasurementKey.parse_serialized(key), corrected, qubits
        )
Measures the qubits and records to `log_of_measurement_results`.

        Any bitmasks will be applied to the measurement record.

        Args:
            qubits: The qubits to measure.
            key: The key the measurement result should be logged under. Note
                that operations should only store results under keys they have
                declared in a `_measurement_key_names_` method.
            invert_mask: The invert mask for the measurement.
            confusion_map: The confusion matrices for the measurement.

        Raises:
            ValueError: If a measurement key has already been logged to a key.
        
cirq-core/cirq/sim/simulation_state.py