def test_run_job_processor_local_parallel(self): def job_done_callback(results): try: self.log.info(pprint.pformat(results)) for result in results: self.assertTrue(result.get_status() == 'COMPLETED') except Exception as e: self.job_processor_exception = e finally: self.job_processor_finished = True njobs = 20 job_list = [] backend = QasmSimulator() for _ in range(njobs): compiled_circuit = compile_circuit(self.qc) quantum_job = QuantumJob(compiled_circuit, backend=backend) job_list.append(quantum_job) self.job_processor_finished = False self.job_processor_exception = None jp = jobprocessor.JobProcessor(job_list, max_workers=None, callback=job_done_callback) jp.submit() while not self.job_processor_finished: # Wait until the job_done_callback is invoked and completed. pass if self.job_processor_exception: raise self.job_processor_exception
def test_mix_local_remote_jobs(self, QE_TOKEN, QE_URL): """test mixing local and remote jobs Internally local jobs execute in seperate processes since they are CPU bound and remote jobs execute in seperate threads since they are I/O bound. The module gets results from potentially both kinds in one list. Test that this works. """ provider = IBMQProvider(QE_TOKEN, QE_URL) remote_backend = provider.get_backend('ibmqx_qasm_simulator') local_backend = QasmSimulator() njobs = 6 job_list = [] backend_type = [local_backend, remote_backend] i = 0 for circuit in self.rqg.get_circuits(format_='QuantumCircuit')[:njobs]: compiled_circuit = compile_circuit(circuit) backend = backend_type[i % len(backend_type)] self.log.info(backend) quantum_job = QuantumJob(compiled_circuit, backend=backend) job_list.append(quantum_job) i += 1 jp = jobprocessor.JobProcessor(job_list, max_workers=None, callback=None) jp.submit()
def test_compile_job(self): """Test compilation as part of job""" backend = QasmSimulator() quantum_job = QuantumJob(self.qasm_circ, do_compile=True, backend=backend) jp = jobprocessor.JobProcessor([quantum_job], callback=None) jp.submit()
def test_run_local_backend_qasm(self): backend = QasmSimulator() dag_circuit = compile_circuit(self.qc) quantum_job = QuantumJob(dag_circuit, do_compile=False, backend=backend) jobprocessor.run_backend(quantum_job)
def test_init_job_processor(self): njobs = 5 job_list = [] backend = QasmSimulator() for _ in range(njobs): quantum_job = QuantumJob(self.qc, backend, do_compile=False) job_list.append(quantum_job) _ = jobprocessor.JobProcessor(job_list, callback=None)
def test_compile_run(self): """Test Compiler and run. If all correct some should exists. """ my_backend = QasmSimulator() qubit_reg = qiskit.QuantumRegister(2, name='q') clbit_reg = qiskit.ClassicalRegister(2, name='c') qc = qiskit.QuantumCircuit(qubit_reg, clbit_reg, name="bell") qc.h(qubit_reg[0]) qc.cx(qubit_reg[0], qubit_reg[1]) qc.measure(qubit_reg, clbit_reg) qobj = qiskit._compiler.compile(qc, my_backend) result = my_backend.run(qiskit.QuantumJob(qobj, preformatted=True)) self.assertIsInstance(result, Result)
def test_random_local(self): """test randomly generated circuits on local_qasm_simulator""" njobs = 5 job_list = [] backend = QasmSimulator() for circuit in self.rqg.get_circuits(format_='QuantumCircuit')[:njobs]: compiled_circuit = compile_circuit(circuit) quantum_job = QuantumJob(compiled_circuit, backend=backend) job_list.append(quantum_job) jp = jobprocessor.JobProcessor(job_list, max_workers=1, callback=None) jp.submit()
def test_run_job_processor_local(self): njobs = 5 job_list = [] backend = QasmSimulator() for _ in range(njobs): compiled_circuit = compile_circuit(self.qc) quantum_job = QuantumJob(compiled_circuit, backend=backend, do_compile=False) job_list.append(quantum_job) jp = jobprocessor.JobProcessor(job_list, callback=None) jp.submit()
def test_init_quantum_job_qobj(self): formatted_circuit = self.qasm_text backend = QasmSimulator() qobj = {'id': 'qobj_init', 'config': { 'max_credits': 3, 'shots': 1024, 'seed': None, 'backend': backend}, 'circuits': [ {'name': 'example', 'compiled_circuit': formatted_circuit, 'layout': None, 'seed': None} ]} _ = QuantumJob(qobj, preformatted=True)
def test_execute(self): """Test Execute. If all correct some should exists. """ my_backend = QasmSimulator() qubit_reg = qiskit.QuantumRegister(2) clbit_reg = qiskit.ClassicalRegister(2) qc = qiskit.QuantumCircuit(qubit_reg, clbit_reg) qc.h(qubit_reg[0]) qc.cx(qubit_reg[0], qubit_reg[1]) qc.measure(qubit_reg, clbit_reg) results = qiskit._compiler.execute(qc, my_backend) self.assertIsInstance(results, Result)
def test_compile(self): """Test Compiler. If all correct some should exists. """ my_backend = QasmSimulator() qubit_reg = qiskit.QuantumRegister(2, name='q') clbit_reg = qiskit.ClassicalRegister(2, name='c') qc = qiskit.QuantumCircuit(qubit_reg, clbit_reg, name="bell") qc.h(qubit_reg[0]) qc.cx(qubit_reg[0], qubit_reg[1]) qc.measure(qubit_reg, clbit_reg) qobj = qiskit._compiler.compile(qc, my_backend) # FIXME should test against the qobj when defined self.assertEqual(len(qobj), 3)
def test_run_local_backend_compile(self): backend = QasmSimulator() quantum_job = QuantumJob(self.qasm_circ, do_compile=True, backend=backend) jobprocessor.run_backend(quantum_job)
def test_init_quantum_job(self): backend = QasmSimulator() _ = QuantumJob(self.qc, backend)