Esempio n. 1
0
    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)
Esempio n. 2
0
    def test_default_gates(self):
        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])

        expected = prog.to_circ()
        #result = qlm_to_pyquil(qlm_circuit)
        # print(result)
        result = Prg()
        for op in quil_1qb:
            result += op(0)
        for op in quil_params:
            result += op(3.14, 0)

        result += pg.SWAP(0, 1)
        result += pg.CNOT(0, 1)
        for op in quil_ctrl:
            result += op(1).controlled(0)
        for op in quil_ctrl_prm:
            result += op(3.14, 1).controlled(0)

        result += pg.CCNOT(0, 1, 2)

        qlm_circuit = pyquil_to_qlm(result)
        exp_str = print_aq(expected)
        res_str = print_aq(qlm_circuit)
        self.assertEqual(exp_str, res_str)
Esempio n. 3
0
    def test_separate_measures(self):
        prog = Program()
        qreg = prog.qalloc(3)
        creg = prog.calloc(3)

        prog.apply(H, qreg[0])
        prog.apply(H, qreg[1])
        prog.apply(H, qreg[2])

        expected = prog.to_circ()

        result = Prg()
        cbs = result.declare("ro", "BIT", 3)
        result += pg.H(0)
        result += pg.H(1)
        result += pg.H(2)
        result += pg.MEASURE(0, cbs[0])
        result += pg.MEASURE(1, cbs[1])
        result += pg.MEASURE(2, cbs[2])

        result, to_measure = pyquil_to_qlm(result, True)
        exp_str = print_aq(expected)
        res_str = print_aq(result)
        self.assertEqual(res_str, exp_str)
        self.assertEqual(to_measure, [0, 1, 2])
Esempio n. 4
0
 def test_recursive_ctrl_and_dagger(self):
     prog = Program()
     qreg = prog.qalloc(5)
     prog.apply(Y.ctrl().ctrl().ctrl().ctrl().dag().dag().dag(), *qreg)
     expected = prog.to_circ()
     result = Prg()
     result += (pg.Y(4).controlled(0).controlled(1).controlled(
         2).controlled(3).dagger())
     result = pyquil_to_qlm(result)
     res_str = print_aq(result)
     exp_str = print_aq(expected)
     self.assertEqual(res_str, exp_str)