code: def run_and_measure(self, program: Program, trials: int) -> Dict[int, np.ndarray]:
          
          program = program.copy()
          validate_supported_quil(program)
          ro = program.declare('ro', 'BIT', len(self.qubits()))
          for i, q in enumerate(self.qubits()):
              program.inst(MEASURE(q, ro[i]))
          program.wrap_in_numshots_loop(trials)
          executable = self.compile(program)
          bitstring_array = self.run(executable=executable)
          bitstring_dict = {}
          for i, q in enumerate(self.qubits()):
              bitstring_dict[q] = bitstring_array[:, i]
          return bitstring_dict
docs: Run the provided state preparation program and measure all qubits.
  
          This will measure all the qubits on this QuantumComputer, not just qubits
          that are used in the program.
  
          The returned data is a dictionary keyed by qubit index because qubits for a given
          QuantumComputer may be non-contiguous and non-zero-indexed. To turn this dictionary
          into a 2d numpy array of bitstrings, consider::
  
              bitstrings = qc.run_and_measure(...)
              bitstring_array = np.vstack(bitstrings[q] for q in qc.qubits()).T
              bitstring_array.shape  # (trials, len(qc.qubits()))
  
          .. note::
  
              In contrast to :py:class:`QVMConnection.run_and_measure`, this method simulates
              noise correctly for noisy QVMs. However, this method is slower for ``trials > 1``.
              For faster noise-free simulation, consider
              :py:class:`WavefunctionSimulator.run_and_measure`.
  
          :param program: The state preparation program to run and then measure.
          :param trials: The number of times to run the program.
          :return: A dictionary keyed by qubit index where the corresponding value is a 1D array of
              measured bits.