def __init__(self, q_jobs, callback, max_workers=1): """ Args: q_jobs (list(QuantumJob)): List of QuantumJob objects. callback (fn(results)): The function that will be called when all jobs finish. The signature of the function must be: fn(results) results: A list of Result objects. max_workers (int): The maximum number of workers to use. Raises: QISKitError: if any of the job backends could not be found. """ self.q_jobs = q_jobs self.max_workers = max_workers # check whether any jobs are remote self.online = any(qj.backend not in local_backends() for qj in q_jobs) self.futures = {} self.lock = Lock() # Set a default dummy callback just in case the user doesn't want # to pass any callback. self.callback = (lambda rs: ()) if callback is None else callback self.num_jobs = len(self.q_jobs) self.jobs_results = [] if self.online: # verify backends across all jobs for q_job in q_jobs: if q_job.backend not in remote_backends() + local_backends(): raise QISKitError("Backend %s not found!" % q_job.backend) if self.online: # I/O intensive -> use ThreadedPoolExecutor self.executor_class = futures.ThreadPoolExecutor else: # CPU intensive -> use ProcessPoolExecutor self.executor_class = futures.ProcessPoolExecutor
def test_remote_backends(self): self.log.info('The discovered remote devices are: {}'.format( remote_backends()))
def test_remote_backends(self): self.log.info('The discovered remote devices are: %s', remote_backends())
bv.x(tmp[0]) bv.h(q) bv.h(tmp) bv += oracle bv.h(q) bv.h(tmp) bv.measure(q, res) print(bv.qasm()) from qiskit.tools.visualization import circuit_drawer circuit_drawer(bv) from qiskit import QuantumProgram qp = QuantumProgram() qp.add_circuit(quantum_circuit=bv, name='bv') from qiskit import backends print(backends.local_backends()) print(backends.remote_backends()) import Qconfig qp.set_api(Qconfig.APItoken, Qconfig.config['url']) result = qp.execute('bv', backend='ibmqx4', timeout=3600) counts = result.get_counts('bv') print(counts) from qiskit.tools.visualization import plot_histogram plot_histogram(counts)