Measure a qubit, collapse the wavefunction, and return the measurement result.

        :param qubit: Index of the qubit to measure.
        :return: measured bit

def do_measurement(self, qubit: int) -> int:
        """
        Measure a qubit, collapse the wavefunction, and return the measurement result.

        :param qubit: Index of the qubit to measure.
        :return: measured bit
        """
        if self.rs is None:
            raise ValueError("You have tried to perform a stochastic operation without setting the "
                             "random state of the simulator. Might I suggest using a PyQVM object?")

        # Get probabilities
        measurement_probs = get_measure_probabilities(self.wf, qubit)

        # Flip a coin and record the result
        measured_bit = int(np.argmax(self.rs.uniform() < np.cumsum(measurement_probs)))

        # Zero out amplitudes corresponding to non-measured bistrings
        other_bit = (measured_bit + 1) % 2
        other_bit_indices = (slice(None),) * qubit + \
                            (other_bit,) + \
                            (slice(None),) * (self.n_qubits - qubit - 1)
        self.wf[other_bit_indices] = 0

        # Re-normalize amplitudes corresponding to measured bistrings
        meas_bit_indices = (slice(None),) * qubit + \
                           (measured_bit,) + \
                           (slice(None),) * (self.n_qubits - qubit - 1)
        self.wf[meas_bit_indices] /= np.sqrt(measurement_probs[measured_bit])
        return measured_bit