Ejemplo n.º 1
0
    def _cut_job(self, qJob: QuantumExecutionJob) -> List[QuantumExecutionJob]:
        """Partitions the quantum circuit of a QuantumExecutionJob

        Args:
            qJob (QuantumExecutionJob): the job to partition

        Returns:
            List[QuantumExecutionJob]: List of QuantumExecutionJobs containing the sub-circuits that result from the partition
        """
        subcircuit_max_qubits, max_separate_circuits, max_cuts = self._get_cutting_parameters(
            qJob)
        cut_solution, circ_dict, all_indexed_combinations = self._cut(
            qJob.circuit.remove_final_measurements(inplace=False),
            subcircuit_max_qubits, max_separate_circuits, max_cuts)
        self._log.debug(
            f"Cut contains {len(circ_dict)} different sub-circuits")
        sub_jobs = []
        for key, circ_info in circ_dict.items():
            circ = circ_info["circuit"]
            shots = circ_info["shots"]
            qc = apply_measurement(circuit=circ, qubits=circ.qubits)
            sub_jobs.append(
                QuantumExecutionJob(qc,
                                    type=Execution_Type.partition,
                                    parent=qJob.id,
                                    shots=qJob.shots,
                                    key=key,
                                    backend_data=qJob.backend_data))
        self._partition_dict[qJob.id] = {
            "cut_solution": cut_solution,
            "all_indexed_combinations": all_indexed_combinations,
            "job": qJob,
            "num_sub_jobs": len(sub_jobs)
        }
        return sub_jobs
Ejemplo n.º 2
0
 def run(self) -> None:
     self._log.info("Started Aggregator")
     while True:
         try:
             q_job = self._input.get(timeout=self._timeout)
         except Empty:
             q_job = None
         if q_job:
             # append job
             backend_name = q_job.backend_data.name
             try:
                 self._jobs_to_aggregate[backend_name].append(q_job)
             except KeyError: 
                 self._jobs_to_aggregate[backend_name] = [q_job]
                 self._timers[backend_name] = time.time()
         
         # check timers and the number of waiting jobs
         clear = []
         for backend_name, jobs_to_aggregate in self._jobs_to_aggregate.items():
             if len(jobs_to_aggregate) < 2 and time.time() - self._timers[backend_name] < self._timeout:
                 continue
             clear.append(backend_name)
             if len(jobs_to_aggregate) > 1:
                 agg_circ, agg_info = aggregate([job.circuit for job in jobs_to_aggregate])
                 agg_shots = max([job.shots for job in jobs_to_aggregate])
                 agg_job = QuantumExecutionJob(agg_circ, shots = agg_shots, type=Execution_Type.aggregation, backend_data = jobs_to_aggregate[0].backend_data)
                 self._job_dict[agg_job.id] = {"jobs":copy.deepcopy(jobs_to_aggregate), "agg_info":agg_info}
                 self._output.put(agg_job)
             else:
                 self._output.put(jobs_to_aggregate.pop())
         for backend_name in clear:
             self._jobs_to_aggregate.pop(backend_name)
             self._timers.pop(backend_name)
 def different_length_circuits():
     log.info(f"start differnt length circuit aggregation")
     for backend_data in backend_data_list:
         for rb_seed, rb_circ_seed in enumerate(rb_circs):
             for circ in rb_circ_seed:
                 input_pipeline.put(
                     QuantumExecutionJob(circuit=circ,
                                         shots=shots,
                                         backend_data=backend_data))
Ejemplo n.º 4
0
    input_pipeline = Queue()
    input_exec = Queue()
    output_exec = Queue()
    part_results = Queue()
    all_results_are_available = Queue()
    output_pipline = Queue()
    errors = Queue()

    for backend_data in backend_data_list:
        for circ in circuits:
            input_pipeline.put(
                QuantumExecutionJob(circuit=circ.measure_all(inplace=False),
                                    shots=shots,
                                    backend_data=backend_data,
                                    config={
                                        "partitioner": {
                                            "subcircuit_max_qubits":
                                            subcircuit_max_qubits
                                        }
                                    }))
            input_exec.put(
                QuantumExecutionJob(circuit=circ.measure_all(inplace=False),
                                    shots=shots,
                                    backend_data=backend_data))

    partition_dict = {}

    partitioner = Partitioner(input=input_pipeline,
                              output=input_exec,
                              partition_dict=partition_dict,
                              error_queue=errors,
Ejemplo n.º 5
0
    for type in circuit_types:
        circuits[type] = [circuits[type]] * n_circuits
        sv_results[type] = [sv_results[type]] * n_circuits

    input_pipeline = Queue()
    input_exec = Queue()
    output_exec = Queue()
    agg_results = Queue()
    output_pipline = Queue()

    for backend_data in backend_data_list:
        for type in circuit_types:
            for circ in circuits[type]:
                input_pipeline.put(
                    QuantumExecutionJob(
                        circuit=circ.measure_all(inplace=False),
                        shots=shots,
                        backend_data=backend_data))
                input_exec.put(
                    QuantumExecutionJob(
                        circuit=circ.measure_all(inplace=False),
                        shots=shots,
                        backend_data=backend_data))

    agg_job_dict = {}

    aggregator = Aggregator(input=input_pipeline,
                            output=input_exec,
                            job_dict=agg_job_dict,
                            timeout=10)
    aggregator.start()
    for backend_name in backend_names:
        backend = provider.get_backend(backend_name)
        backend_data = Backend_Data(backend)
        backend_data_list.append(backend_data)
        backends[backend_name] = {
            "backend": backend,
            "backend_data": backend_data
        }

    for backend_data in backend_data_list:
        for length_idx in range(len(rb_opts['length_vector'])):
            for rb_seed, rb_circ_seed in enumerate(rb_circs):
                circ = rb_circ_seed[length_idx]
                input_pipeline.put(
                    QuantumExecutionJob(circuit=circ,
                                        shots=shots,
                                        backend_data=backend_data))
                input_exec.put(
                    QuantumExecutionJob(circuit=circ,
                                        shots=shots,
                                        backend_data=backend_data))

    if different_length:
        log.info(
            f"delay differnt length circuit aggregation by {delay_time_different_length}s"
        )

        def different_length_circuits():
            log.info(f"start differnt length circuit aggregation")
            for backend_data in backend_data_list:
                for rb_seed, rb_circ_seed in enumerate(rb_circs):
Ejemplo n.º 7
0
 def create_qjob(self):
     qjob = QuantumExecutionJob(QuantumCircuit.from_qasm_str(self.qasm),
                                shots=self.shots,
                                config=self.config)
     self.qjob_id = qjob.id
     return qjob