def run(self, circuit: Circuit, shots: int, fit_to_constraints=True, seed: int = None) -> np.ndarray: """Run a circuit on Qiskit Aer Qasm simulator. :param circuit: The circuit to run :type circuit: Circuit :param shots: Number of shots (repeats) to run :type shots: int :param fit_to_constraints: Compile the circuit to meet the constraints of the backend, defaults to True :type fit_to_constraints: bool, optional :param seed: random seed to for simulator :type seed: int :return: Table of shot results, each row is a shot, columns are ordered by qubit ordering. Values are 0 or 1, corresponding to qubit basis states. :rtype: numpy.ndarray """ c = circuit.copy() if fit_to_constraints: Transform.RebaseToQiskit().apply(c) dag = tk_to_dagcircuit(c) qc = dag_to_circuit(dag) qobj = assemble(qc, shots=shots, seed_simulator=seed, memory=True) job = self._backend.run(qobj, noise_model=self.noise_model) shot_list = job.result().get_memory(qc) return np.asarray([_convert_bin_str(shot) for shot in shot_list])
def get_counts(self, circuit, shots, fit_to_constraints=True, seed=None) : """ Run the circuit on the backend and accumulate the results into a summary of counts :param circuit: The circuit to run :param shots: Number of shots (repeats) to run :param fit_to_constraints: Compile the circuit to meet the constraints of the backend, defaults to True :param seed: Random seed to for simulator :return: Dictionary mapping bitvectors of results to number of times that result was observed (zero counts are omitted) """ c = circuit.copy() if fit_to_constraints : Transform.RebaseToQiskit().apply(c) qc = tk_to_qiskit(c) qobj = assemble(qc, shots=shots, seed_simulator=seed) job = self._backend.run(qobj, noise_model=self.noise_model) counts = job.result().get_counts(qc) return {tuple(_convert_bin_str(b)) : c for b, c in counts.items()}