def _get_qasm_str_from_qobj(self, qobj): """ convert to format(QASM) that can run on our simulator, we now assume that there is only one experiment(QC) (2020/9/9, YT Lin), can do multi-circuit easily by list comprehension """ original_config = qobj.config assert len( disassemble(qobj)[0] ) == 1, "we now assume that there is only one experiment(QC) (2020/9/9, YT Lin)" qc = disassemble(qobj)[0][0] qasm_str = qc.qasm() # print(qasm_str) return qasm_str
def run(self, circuit, **kwargs): """Submits the given circuit to run on an IonQ target.""" # If the circuit was created using qiskit.assemble, # disassemble into QASM here if isinstance(circuit, QasmQobj) or isinstance(circuit, Qobj): from qiskit.assembler import disassemble circuits, run, _ = disassemble(circuit) circuit = circuits[0] if kwargs.get("shots") is None: # Note that the default number of shots for QObj is 1024 # unless the user specifies the backend. kwargs["shots"] = run["shots"] ionq_circ, _, meas_map = qiskit_circ_to_ionq_circ(circuit) input_data = json.dumps({ "qubits": circuit.num_qubits, "circuit": ionq_circ, }) # Options are mapped to input_params # Take also into consideration options passed in the kwargs, as the take precedence # over default values: input_params = vars(self.options) for opt in kwargs.copy(): if opt in input_params: input_params[opt] = kwargs.pop(opt) logger.info(f"Submitting new job for backend {self.name()}") job = AzureQuantumJob(backend=self, name=circuit.name, target=self.name(), input_data=input_data, blob_name="inputData", content_type="application/json", provider_id="ionq", input_data_format="ionq.circuit.v1", output_data_format="ionq.quantum-results.v1", input_params=input_params, metadata=self._job_metadata(circuit=circuit, meas_map=meas_map), **kwargs) logger.info( f"Submitted job with id '{job.id()}' for circuit '{circuit.name}':" ) logger.info(input_data) return job
def run(self, qobj: QasmQobj) -> TketJob: module = disassemble(qobj) circ_list = [qiskit_to_tk(qc) for qc in module[0]] if self._comp_pass: final_maps = [] compiled_list = [] for c in circ_list: cu = CompilationUnit(c) self._comp_pass.apply(cu) compiled_list.append(cu.circuit) final_maps.append(cu.final_map) circ_list = compiled_list else: final_maps = [None for c in circ_list] handles = self._backend.process_circuits(circ_list, n_shots=qobj.config.shots) return TketJob(self, handles, qobj, final_maps)
def qobj_to_circuits(qobj): """Return a list of QuantumCircuit object(s) from a qobj Args: qobj (Qobj): The Qobj object to convert to QuantumCircuits Returns: list: A list of QuantumCircuit objects from the qobj """ warnings.warn( 'qiskit.converters.qobj_to_circuit() is deprecated and will ' 'be removed in Qiskit Terra 0.9. Please use ' 'qiskit.compiler.disassemble_circuits() to convert a qobj ' 'to list of circuits.', DeprecationWarning) variables = disassemble(qobj) return variables[0]
def run(self, circuit: QuantumCircuit, **kwargs): """Submits the given circuit for execution on an Honeywell target.""" # If the circuit was created using qiskit.assemble, # disassemble into QASM here if isinstance(circuit, QasmQobj) or isinstance(circuit, Qobj): from qiskit.assembler import disassemble circuits, run, _ = disassemble(circuit) circuit = circuits[0] if kwargs.get("count") is None: # Note that the default number of shots for QObj is 1024 # unless the user specifies the backend. kwargs["count"] = run["shots"] input_data = circuit.qasm() # Options are mapped to input_params # Take also into consideration options passed in the kwargs, as the take precedence # over default values: input_params = vars(self.options) for opt in kwargs.copy(): if opt in input_params: input_params[opt] = kwargs.pop(opt) logger.info(f"Submitting new job for backend {self.name()}") job = AzureQuantumJob( backend=self, name=circuit.name, target=self.name(), input_data=input_data, blob_name="inputData", content_type="application/qasm", provider_id="honeywell", input_data_format="honeywell.openqasm.v1", output_data_format="honeywell.quantum-results.v1", input_params=input_params, metadata={"qubits": str(circuit.num_qubits)}, **kwargs) logger.info( f"Submitted job with id '{job.id()}' for circuit '{circuit.name}':" ) logger.info(input_data) return job
def run(self, qobj): """ Convert all the circuits inside qobj into a Batch of QLM jobs before sending them into a QLM qpu. Args: qobj: Qiskit batch of circuits to run Returns: Returns a :class:`~qat.interop.qiskit.providers.QLMJob` object containing the results of the QLM qpu execution after being converted into Qiskit results """ if self._qpu is None: raise NoQpuAttached("No qpu attached to the QLM connector.") headers = [exp.header.to_dict() for exp in qobj.experiments] circuits = disassemble(qobj)[0] nbshots = qobj.config.shots qlm_task = Batch(jobs=[]) for circuit in circuits: qlm_circuit = qiskit_to_qlm(circuit) job = qlm_circuit.to_job(aggregate_data=False) job.nbshots = nbshots job.qubits = list(range(0, qlm_circuit.nbqbits)) qlm_task.jobs.append(job) results = self._qpu.submit(qlm_task) for res in results: for sample in res.raw_data: sample.intermediate_measures = None res = aggregate_data(res) # Creating a job that will contain the results job = QLMJob(self, str(self.id_counter)) self.id_counter += 1 job.set_results(results, qobj.qobj_id, headers) return job
def time_disassemble_circuit(self, _, __, ___): disassemble(self.qobj)
def dict_to_circuit(dict_: dict) -> QuantumCircuit: qobj = QasmQobj.from_dict(dict_) return disassemble(qobj)[0][0]