def test_do_while(self):
        self.setUpClass()
        config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
        platform = ql.Platform('seven_qubits_chip', config_fn)
        num_qubits = 5
        num_cregs = 10

        p = ql.Program('test_do_while', platform, num_qubits, num_cregs)
        sweep_points = [1, 2]
        p.set_sweep_points(sweep_points)

        k1 = ql.Kernel('aKernel1', platform, num_qubits, num_cregs)
        k2 = ql.Kernel('aKernel2', platform, num_qubits, num_cregs)

        # create classical registers
        rd = ql.CReg()
        rs1 = ql.CReg()
        rs2 = ql.CReg()

        # quanutm operations
        k1.gate('x', [0])
        k2.gate('y', [0])

        p.add_do_while(k1, ql.Operation(rs1, '<', rs2))
        p.add_kernel(k2)

        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
    def test_classical(self):
        self.setUpClass()
        config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
        platform = ql.Platform('seven_qubits_chip', config_fn)
        num_qubits = 5
        num_cregs = 32

        p = ql.Program('test_classical', platform, num_qubits, num_cregs)
        sweep_points = [1, 2]
        p.set_sweep_points(sweep_points)

        k1 = ql.Kernel('aKernel1', platform, num_qubits, num_cregs)

        # quanutm operations
        k1.gate('x', [0])
        k1.gate('cz', [0, 2])

        # # create classical registers
        rd = ql.CReg()
        rs1 = ql.CReg()
        rs2 = ql.CReg()

        # add/sub/and/or/xor
        k1.classical(rd, ql.Operation(rs1, '+', rs2))

        # not
        k1.classical(rd, ql.Operation('~', rs2))

        # comparison
        k1.classical(rd, ql.Operation(rs1, '==', rs2))

        # initialize (r1 = 2)
        k1.classical(rs1, ql.Operation(2))

        # assign (r1 = r2)
        k1.classical(rs1, ql.Operation(rs2))

        # measure
        k1.gate('measure', [0], rs1)

        # add kernel
        p.add_kernel(k1)
        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
Example #3
0
    def test_stateful_behavior(self):
        self.setUpClass()
        ql.set_option('optimize', 'no')
        ql.set_option('scheduler', 'ALAP')

        config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
        platform = ql.Platform("myPlatform", config_fn)

        sweep_points = [1]
        nqubits = 3
        nregs = 3

        p = ql.Program("statelessProgram", platform, nqubits, nregs)
        p.set_sweep_points(sweep_points)
        k = ql.Kernel("aKernel", platform, nqubits, nregs)

        k.prepz(0)
        k.gate('rx180', [0])
        k.measure(0)

        rd = ql.CReg()
        rs1 = ql.CReg()
        rs2 = ql.CReg()

        k.classical(rs1, ql.Operation(3))
        k.classical(rs1, ql.Operation(4))
        k.classical(rd, ql.Operation(rs1, '+', rs2))

        p.add_kernel(k)

        NCOMPILES = 50
        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        for i in range(NCOMPILES):
            p.compile()
            self.setUpClass()
            QISA_fn_i = os.path.join(output_dir,
                                     p.name + '_' + str(i) + '.qisa')
            os.rename(QISA_fn, QISA_fn_i)

        for i in range(NCOMPILES - 1):
            QISA_fn_1 = os.path.join(output_dir,
                                     p.name + '_' + str(i) + '.qisa')
            QISA_fn_2 = os.path.join(output_dir,
                                     p.name + '_' + str(i + 1) + '.qisa')
            self.assertTrue(file_compare(QISA_fn_1, QISA_fn_2))
Example #4
0
    def test_classical(self):
        platform = ql.Platform(platform_name, config_fn)

        p = ql.Program('test_classical', platform, num_qubits, num_cregs)
        k1 = ql.Kernel('aKernel1', platform, num_qubits, num_cregs)

        # quantum operations
        k1.gate('x', [6])
        k1.gate('cz', [6, 7])

        # create classical registers
        rd = ql.CReg()
        rs1 = ql.CReg()
        rs2 = ql.CReg()

        if 0:
            # add/sub/and/or/xor
            k1.classical(rd, ql.Operation(rs1, '+', rs2))

            # not
            k1.classical(rd, ql.Operation('~', rs2))

            # comparison
            k1.classical(rd, ql.Operation(rs1, '==', rs2))

            # initialize (r1 = 2)
            k1.classical(rs1, ql.Operation(2))

            # assign (r1 = r2)
            k1.classical(rs1, ql.Operation(rs2))

        # measure
        k1.gate('measure', [6], rs1)
        k1.gate('measure', [7], rs2)

        # add kernel
        p.add_kernel(k1)
        p.compile()