code: def do_measurement(self, qubit: int) -> int:
          
          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?")
          measure_0 = lifted_gate_matrix(matrix=P0, qubit_inds=[qubit], n_qubits=self.n_qubits)
          prob_zero = np.trace(measure_0 @ self.density)
  
          # generate random number to 'roll' for measurement
          if self.rs.uniform() < prob_zero:
              # decohere state using the measure_0 operator
              unitary = measure_0 @ (np.eye(2 ** self.n_qubits) / np.sqrt(prob_zero))
              self.density = unitary.dot(self.density).dot(np.conj(unitary.T))
              return 0
          else:  # measure one
              measure_1 = lifted_gate_matrix(matrix=P1, qubit_inds=[qubit], n_qubits=self.n_qubits)
              unitary = measure_1 @ (np.eye(2 ** self.n_qubits) / np.sqrt(1 - prob_zero))
              self.density = unitary.dot(self.density).dot(np.conj(unitary.T))
              return 1
docs: Measure a qubit and collapse the wavefunction
  
          :return: The measurement result. A 1 or a 0.