def submit_job(self, qlm_job): qlm_circuit = qlm_job.circuit pyquil_circuit = qlm_to_pyquil(qlm_circuit) if self.compiler: try: executable = self.qpu.compile(pyquil_circuit) except AttributeError: executable = pyquil_circuit else: executable = pyquil_circuit # qc.run_and_measure(pyquil_circuit, trials=1) result = generate_qlm_result(self.qpu.run(executable)) return result
def _test_qvm_run(self): from qat.interop.pyquil.algorithms import QFT3 from qat.interop.pyquil.providers import PyquilQPU from pyquil.api import QVMConnection qvm = QVMConnection(endpoint="http://localhost:15011") qpu = PyquilQPU(qvm) pyquil_prog = QFT3() expected = qpu.submit(pyquil_to_qlm(pyquil_prog).to_job()) result = qpu.submit( pyquil_to_qlm(qlm_to_pyquil(pyquil_to_qlm(pyquil_prog))).to_job()) print(expected) print(result)
def test_recursive_ctrl_and_dagger(self): # Create qlm program prog = Program() qreg = prog.qalloc(5) prog.apply(Y.ctrl().ctrl().ctrl().ctrl().dag().dag().dag(), *qreg) qlm_circuit = prog.to_circ() result = qlm_to_pyquil(qlm_circuit) # Create pyquil program expected = Prg() expected_creg = expected.declare("ro", "BIT", 5) expected += (pg.Y(4).controlled(0).controlled(1).controlled( 2).controlled(3).dagger()) for qbit, cbit in enumerate(expected_creg): expected += pg.MEASURE(qbit, cbit) self.assertEqual(str(result), str(expected))
def test_measures(self): # Create qlm program prog = Program() qreg = prog.qalloc(3) prog.apply(H, qreg[0]) prog.apply(H, qreg[1]) prog.apply(H, qreg[2]) result = qlm_to_pyquil(prog.to_circ()) # Create pyquil program expected = Prg() cbs = expected.declare("ro", "BIT", 3) expected += pg.H(0) expected += pg.H(1) expected += pg.H(2) expected += pg.MEASURE(0, cbs[0]) expected += pg.MEASURE(1, cbs[1]) expected += pg.MEASURE(2, cbs[2]) self.assertEqual(str(result), str(expected))
def submit_job(self, qlm_job): """ Execute a myQLM jobs Args: qlm_job (:class:`~qat.core.Job`): job to execute Returns: :class:`~qat.core.Result`: result of the execution """ qlm_circuit = qlm_job.circuit pyquil_circuit = qlm_to_pyquil(qlm_circuit) if self.compiler: try: executable = self.qpu.compile(pyquil_circuit) except AttributeError: executable = pyquil_circuit else: executable = pyquil_circuit # qc.run_and_measure(pyquil_circuit, trials=1) result = generate_qlm_result(self.qpu.run(executable)) return result
def test_default_gates(self): # Create qlm program prog = Program() qreg = prog.qalloc(3) for op in pygates_1qb: prog.apply(op, qreg[0]) for op in pygates_2qb: prog.apply(op, qreg[0], qreg[1]) prog.apply(CCNOT, qreg[0], qreg[1], qreg[2]) qlm_circuit = prog.to_circ() result = qlm_to_pyquil(qlm_circuit) # Create pyquil program expected = Prg() expected_creg = expected.declare("ro", "BIT", 3) for op in quil_1qb: expected += op(0) for op in quil_params: expected += op(3.14, 0) expected += pg.SWAP(0, 1) expected += pg.CNOT(0, 1) for op in quil_ctrl: expected += op(1).controlled(0) for op in quil_ctrl_prm: expected += op(3.14, 1).controlled(0) expected += pg.CCNOT(0, 1, 2) expected += pg.MEASURE(0, expected_creg[0]) expected += pg.MEASURE(1, expected_creg[1]) expected += pg.MEASURE(2, expected_creg[2]) self.assertEqual(str(result), str(expected))