def test_mapper_oneNN(self):
        # just check whether mapper works for trivial case
        # parameters
        v = 'oneNN'
        config = os.path.join(rootDir, "test_mapper_s7.json")
        num_qubits = 7

        # create and set platform
        prog_name = "test_mapper_" + v
        kernel_name = "kernel_" + v
        starmon = ql.Platform("starmon", config)
        prog = ql.Program(prog_name, starmon, num_qubits, 0)
        k = ql.Kernel(kernel_name, starmon, num_qubits, 0)

        k.gate("x", [0])
        k.gate("y", [1])
        k.gate("cnot", [2, 5])

        prog.add_kernel(k)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #2
0
    def test_adriaan(self):
        self.setUp()
        # parameters
        v = 'adriaan'
        scheduler = self._SCHEDULER

        # create and set platform
        prog_name = "test_" + v + '_' + scheduler
        kernel_name = "kernel_" + v + '_' + scheduler

        starmon = ql.Platform("starmon", self.config)
        prog = ql.Program(prog_name, starmon, 7, 0)
        k = ql.Kernel(kernel_name, starmon, 7, 0)

        k.gate("prepz", [0])
        k.gate("prepz", [2])
        for _ in range(10):
            k.gate("x", [0])

        for _ in range(6):
            k.gate("rx90", [2])
        k.gate("measure", [2])
        k.gate("measure", [0])

        prog.add_kernel(k)
        ql.set_option("scheduler", scheduler)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #3
0
    def test_qasm_seq_butterfly(self):
        nqubits = 1
        p = Program("Butterfly", platf, nqubits)

        k = Kernel('0', platf, nqubits)
        k.prepz(0)
        k.measure(0)
        k.measure(0)
        # what does the measurement tell us it is?
        k.measure(0)
        # what is the post measuremnet state
        p.add_kernel(k)

        k = Kernel('1', platf, nqubits)
        k.prepz(0)
        k.measure(0)
        k.x(0)
        k.measure(0)
        k.measure(0)
        p.add_kernel(k)
        p.compile()

        # Test that the generated code is valid
        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
Exemple #4
0
    def test_measure_busy(self):

        config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
        platform = ql.Platform('seven_qubits_chip', config_fn)
        sweep_points = [1, 2]
        num_qubits = 7
        p = ql.Program('aProgram', platform, num_qubits)
        p.set_sweep_points(sweep_points)

        # populate kernel using default gates
        k = ql.Kernel('aKernel', platform, num_qubits)

        # following should not be packed together as measurement is starting on same
        # meas unit which is busy
        k.measure(0)
        k.wait([2], 20)
        k.measure(2)

        # add the kernel to the program
        p.add_kernel(k)

        # compile the program
        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
Exemple #5
0
    def test_fast_feedback(self):

        # You can specify a config location, here we use a default config
        config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
        platform = ql.Platform('seven_qubits_chip', config_fn)
        sweep_points = [1, 2]
        num_qubits = platform.get_qubit_number()
        p = ql.Program('aProgram', platform, num_qubits)
        p.set_sweep_points(sweep_points)

        # populate kernel using default gates
        k = ql.Kernel('aKernel', platform, num_qubits)
        k.prepz(0)
        k.gate('cprepz', [1])
        k.measure(0)
        k.measure(1)

        # add the kernel to the program
        p.add_kernel(k)

        # compile the program
        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
    def test_do_while_nested_for(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_nested_for', platform, num_qubits,
                       num_cregs)
        sweep_points = [1, 2]
        p.set_sweep_points(sweep_points)

        sp1 = ql.Program('subprogram1', platform, num_qubits, num_cregs)
        sp2 = ql.Program('subprogram2', platform, num_qubits, num_cregs)

        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])

        sp1.add_do_while(k1, ql.Operation(rs1, '>=', rs2))
        sp2.add_for(sp1, 100)
        p.add_program(sp2)

        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
    def test_mapper_oneD4(self):
        # one cnot with operands that are at distance 4 in s7
        # initial placement should find this
        # otherwise ...
        # there are 4 alternative paths
        # in each path there are 4 alternative places to put the cnot
        # this introduces 3 swaps/moves
        # parameters
        v = 'oneD4'
        config = os.path.join(rootDir, "test_mapper_s7.json")
        num_qubits = 7

        # create and set platform
        prog_name = "test_mapper_" + v
        kernel_name = "kernel_" + v
        starmon = ql.Platform("starmon", config)
        prog = ql.Program(prog_name, starmon, num_qubits, 0)
        k = ql.Kernel(kernel_name, starmon, num_qubits, 0)

        k.gate("x", [2])
        k.gate("x", [4])
        k.gate("cnot", [2, 4])
        k.gate("x", [2])
        k.gate("x", [4])

        prog.add_kernel(k)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #8
0
    def test_qwg2(self):
        self.setUp()
        # parameters
        v = 'qwg2'
        scheduler = self._SCHEDULER

        # create and set platform
        prog_name = "test_" + v + "_" + scheduler
        kernel_name = "kernel_" + v + "_" + scheduler

        starmon = ql.Platform("starmon", self.config)
        prog = ql.Program(prog_name, starmon, 7, 0)
        k = ql.Kernel(kernel_name, starmon, 7, 0)

        for j in range(7):
            k.gate("x", [j])
        k.gate("x", [0])
        k.gate("y", [1])
        k.gate("y", [2])
        k.gate("x", [3])
        k.gate("y", [4])
        k.gate("x", [5])
        k.gate("y", [6])
        for j in range(7):
            k.gate("y", [j])

        prog.add_kernel(k)
        ql.set_option("scheduler", scheduler)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #9
0
    def test_smit_all_bundled(self):

        # You can specify a config location, here we use a default config
        config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
        platform = ql.Platform('seven_qubits_chip', config_fn)
        sweep_points = [1, 2]
        num_qubits = platform.get_qubit_number()
        p = ql.Program('test_smit_all_bundled', platform, num_qubits)
        p.set_sweep_points(sweep_points)

        # populate kernel using default gates
        k = ql.Kernel('aKernel', platform, num_qubits)

        for i in range(7):
            k.prepz(i)

        k.gate('cz', [2, 0])
        k.gate('cz', [3, 5])
        k.gate('cz', [1, 4])
        k.gate('cz', [4, 6])
        k.gate('cz', [2, 5])
        k.gate('cz', [3, 0])

        # add the kernel to the program
        p.add_kernel(k)

        # compile the program
        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        GOLD_fn = rootDir + '/golden/test_smit_all_bundled.qisa'

        assemble(QISA_fn)

        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #10
0
    def test_qasm_seq_echo(self):
        nqubits = 1
        p = Program("Echo", platf, nqubits)
        times = np.linspace(0, 20e3, 61)  # in ns
        # To prevent superslow workaround
        times = np.linspace(0, 60, 61)  # in ns
        # this should be implicit
        p.set_sweep_points(times)
        for tau in times:
            # this is an invalid kernel name (contains '.')
            # and will produce and invalid qasm
            n = 'echo_tau_{}ns'.format(tau)
            n = n.replace(".", "_")
            k = Kernel(n, platf, nqubits)
            k.prepz(0)
            k.rx90(0)
            # This is a dirty hack that repeats the I gate
            for j in range(int(tau / 2)):
                k.gate('i', [0])
            k.rx180(0)
            for j in range(int(tau / 2)):
                k.gate('i', [0])
            k.rx90(0)
            k.measure(0)
            p.add_kernel(k)

        p.compile()

        # Test that the generated code is valid
        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
Exemple #11
0
    def test_detuned2(self):
        self.setUp()
        # parameters
        v = 'detuned2'
        scheduler = self._SCHEDULER

        # create and set platform
        prog_name = "test_" + v + '_' + scheduler
        kernel_name = "kernel_" + v + '_' + scheduler

        starmon = ql.Platform("starmon", self.config)
        prog = ql.Program(prog_name, starmon, 7, 0)
        k = ql.Kernel(kernel_name, starmon, 7, 0)

        # preferably cz's parallel, but not with x 3
        k.gate("cz", [0, 2])
        k.gate("cz", [1, 4])
        k.gate("x", [3])

        # likewise, while y 3, no cz on 0,2 or 1,4
        k.gate("y", [3])
        k.gate("cz", [2, 5])
        k.gate("cz", [4, 6])

        prog.add_kernel(k)
        ql.set_option("scheduler", scheduler)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #12
0
    def test_qwg(self):
        self.setUp()
        # parameters
        v = 'qwg'

        # create and set platform
        prog_name = "test_" + v + "_" + self._SCHEDULER
        kernel_name = "kernel_" + v + "_" + self._SCHEDULER

        starmon = ql.Platform("starmon", self.config)
        prog = ql.Program(prog_name, starmon, 7, 0)
        k = ql.Kernel(kernel_name, starmon, 7, 0)

        # no dependency, only a conflict in qwg resource
        k.gate("x", [0])
        k.gate("y", [1])

        prog.add_kernel(k)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #13
0
    def test_edge(self):
        self.setUp()
        # parameters
        v = 'edge'
        scheduler = self._SCHEDULER

        # create and set platform
        prog_name = "test_" + v + '_' + scheduler
        kernel_name = "kernel_" + v + '_' + scheduler

        starmon = ql.Platform("starmon", self.config)
        prog = ql.Program(prog_name, starmon, 7, 0)
        k = ql.Kernel(kernel_name, starmon, 7, 0)

        # no dependency, only a conflict in edge resource between the first two czs
        k.gate("cz", [1, 4])
        k.gate("cz", [0, 3])
        k.gate("cz", [2, 5])

        prog.add_kernel(k)
        ql.set_option("scheduler", scheduler)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #14
0
    def test_smis_with_custom_gates(self):

        # You can specify a config location, here we use a default config
        config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
        platform = ql.Platform('seven_qubits_chip', config_fn)
        sweep_points = [1, 2]
        num_qubits = 7
        p = ql.Program('aProgram', platform, num_qubits)
        p.set_sweep_points(sweep_points)

        # populate the second kernel using both custom and default gates
        k = ql.Kernel('aKernel', platform, num_qubits)
        k.gate('prepz', [0])
        k.gate('x', [0])
        k.y(1)
        k.z(5)
        k.gate('rx90', [0])
        k.gate('cnot', [0, 3])
        k.gate('measure', [0])

        # add the kernel to the program
        p.add_kernel(k)

        # compile the program
        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
    def test_mapper_allD(self):
        # all possible cnots in s7, in lexicographic order
        # there is no initial mapping that maps this right so initial placement cannot find it
        # so the heuristics must act and insert swaps/moves
        # parameters
        v = 'allD'
        config = os.path.join(rootDir, "test_mapper_s7.json")
        num_qubits = 7

        # create and set platform
        prog_name = "test_mapper_" + v
        kernel_name = "kernel_" + v
        starmon = ql.Platform("starmon", config)
        prog = ql.Program(prog_name, starmon, num_qubits, 0)
        k = ql.Kernel(kernel_name, starmon, num_qubits, 0)

        for j in range(7):
            k.gate("x", [j])

        for i in range(7):
            for j in range(7):
                if (i != j):
                    k.gate("cnot", [i, j])

        for j in range(7):
            k.gate("x", [j])

        prog.add_kernel(k)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #16
0
    def test_allxy(self):
        p = Program("AllXY", platf, 1)
        # uppercase lowercase problems

        allXY = [['i', 'i'], ['rx180', 'rx180'], ['ry180', 'ry180'],
                 ['rx180', 'ry180'], ['ry180', 'rx180'], ['rx90', 'i'],
                 ['ry90', 'i'], ['rx90', 'ry90'], ['ry90', 'rx90'],
                 ['rx90', 'ry180'], ['ry90', 'rx180'], ['rx180', 'ry90'],
                 ['ry180', 'rx90'], ['rx90', 'rx180'], ['rx180', 'rx90'],
                 ['ry90', 'ry180'], ['ry180', 'ry90'], ['rx180', 'i'],
                 ['ry180', 'i'], ['rx90', 'rx90'], ['ry90', 'ry90']]
        # this should be implicit
        p.set_sweep_points(np.arange(len(allXY), dtype=float))

        for i, xy in enumerate(allXY):
            k = Kernel("allXY" + str(i), platf, 1)
            k.prepz(0)
            k.gate(xy[0], [0])
            k.gate(xy[1], [0])
            k.measure(0)
            p.add_kernel(k)

        p.compile()

        # Test that the generated code is valid
        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
Exemple #17
0
    def test_if_else(self):
        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_if_else', 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])

        # simple if
        p.add_if_else(k1, k2, ql.Operation(rs1, '==', rs2))

        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
Exemple #18
0
    def test_7(self):
        self.setUp()
        # parameters
        v = '7'
        scheduler = self._SCHEDULER

        # create and set platform
        prog_name = "test_" + v + '_' + scheduler
        kernel_name = "kernel_" + v + '_' + scheduler

        starmon = ql.Platform("starmon", self.config)
        prog = ql.Program(prog_name, starmon, 7, 0)
        k = ql.Kernel(kernel_name, starmon, 7, 0)

        k.gate("prepz", [0])
        k.gate("prepz", [1])
        k.gate("prepz", [2])
        k.gate("prepz", [3])
        k.gate("prepz", [4])
        k.gate("prepz", [5])
        k.gate("prepz", [6])
        # preps all end at same time, is the base of ASAP

        # rotations on q0, q2 and q5, mutually independent, also wrt resource use
        k.gate("h", [0])  # qubit 0 in qwg0 10 cycles rotations
        k.gate("t", [0])
        k.gate("h", [0])
        k.gate("t", [0])

        k.gate("h", [2])  # qubit 2 in qwg1 5 cycles rotations
        k.gate("t", [2])

        k.gate("h", [5])  # qubit 4 in qwg2 2 cycles rotations

        # measures all start at same time, is the horizon for ALAP
        k.gate("measure", [0])
        k.gate("measure", [1])
        k.gate("measure", [2])
        k.gate("measure", [3])
        k.gate("measure", [4])
        k.gate("measure", [5])
        k.gate("measure", [6])

        prog.add_kernel(k)

        ql.set_option("scheduler", scheduler)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #19
0
    def test_ccl_buffers(self):

        tests = [
            # mw - mw buffer (same qubit and of course same awg channel is involved)
            (0, [("x", [0]), ("y", [0])]),
            # mw - mw buffer (different qubit but same awg channel is involved)
            (1, [("x", [0]), ("y", [1])]),
            # mw - mw buffer (different qubit and different awg channel)
            (2, [("x", [0]), ("y", [2])]),
            # mw - flux
            (3, [("x", [2]), ("cnot", [0, 2])]),
            # mw - readout
            (4, [("x", [0]), ("measure", [0])]),
            # flux - flux
            (5, [("cnot", [0, 2]), ("cnot", [0, 2])]),
            # flux - mw
            (6, [("cnot", [0, 2]), ("x", [2])]),
            # flux - readout
            (7, [("cnot", [0, 2]), ("measure", [2])]),
            # readout - readout
            (8, [("measure", [0]), ("measure", [0])]),
            # readout - mw
            (9, [("measure", [0]), ("x", [0])]),
            # readout - flux
            (10, [("measure", [0]), ("cnot", [0, 2])])
        ]

        for testNo, testKernel in tests:
            print('Running test_ccl_buffers No: {}'.format(testNo))
            config_fn = os.path.join(
                curdir, 'test_cfg_cc_light_buffers_latencies.json')
            platform = ql.Platform('seven_qubits_chip', config_fn)
            sweep_points = [1, 2]
            num_qubits = 7
            p = ql.Program('test_ccl_buffers' + str(testNo), platform,
                           num_qubits)
            p.set_sweep_points(sweep_points)
            k = ql.Kernel('aKernel', platform, num_qubits)

            for gate, qubits in testKernel:
                k.gate(gate, qubits)

            p.add_kernel(k)
            p.compile()

            QISA_fn = os.path.join(output_dir, p.name + '.qisa')
            gold_fn = rootDir + '/golden/test_ccl_buffers_' + str(
                testNo) + '.qisa'

            assemble(QISA_fn)

            self.assertTrue(file_compare(QISA_fn, gold_fn))
Exemple #20
0
    def test_bug(self):
        p = Program("bug", platf, 1)

        k = Kernel("bugKernel", platform=platf, qubit_count=1)
        k.gate('rx180', [0])
        k.gate('measure', [0])

        p.add_kernel(k)
        p.compile()

        # Test that the generated code is valid
        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
    def test_mapper_allNN(self):
        # a list of all cnots that are NN in trivial/natural mapping (as in test_mapper_s7.json)
        #   (s7 is 3 rows: 2 data qubits (0 and 1), 3 ancillas (2 to 4), and 2 data qubits (5 and 6))
        # so no swaps are inserted and map is not changed
        # also tests commutation of cnots in mapper and postscheduler
        # parameters
        v = 'allNN'
        config = os.path.join(rootDir, "test_mapper_s7.json")
        num_qubits = 7

        # create and set platform
        prog_name = "test_mapper_" + v
        kernel_name = "kernel_" + v
        starmon = ql.Platform("starmon", config)
        prog = ql.Program(prog_name, starmon, num_qubits, 0)
        k = ql.Kernel(kernel_name, starmon, num_qubits, 0)

        for j in range(7):
            k.gate("x", [j])
        k.gate("cnot", [0, 2])
        k.gate("cnot", [0, 3])
        k.gate("cnot", [1, 3])
        k.gate("cnot", [1, 4])
        k.gate("cnot", [2, 0])
        k.gate("cnot", [2, 5])
        k.gate("cnot", [3, 0])
        k.gate("cnot", [3, 1])
        k.gate("cnot", [3, 5])
        k.gate("cnot", [3, 6])
        k.gate("cnot", [4, 1])
        k.gate("cnot", [4, 6])
        k.gate("cnot", [5, 2])
        k.gate("cnot", [5, 3])
        k.gate("cnot", [6, 3])
        k.gate("cnot", [6, 4])
        for j in range(7):
            k.gate("x", [j])

        prog.add_kernel(k)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_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)
Exemple #23
0
    def test_1(self):
        self.setUp()
        # parameters
        v = '1'
        scheduler = self._SCHEDULER

        # create and set platform
        prog_name = "test_" + v + '_' + scheduler
        kernel_name = "kernel_" + v + '_' + scheduler

        starmon = ql.Platform("starmon", self.config)
        prog = ql.Program(prog_name, starmon, 7, 0)
        k = ql.Kernel(kernel_name, starmon, 7, 0)

        for j in range(7):
            k.gate("x", [j])

        # a list of all cnots that are ok in trivial mapping
        k.gate("cnot", [0, 2])
        k.gate("cnot", [0, 3])
        k.gate("cnot", [1, 3])
        k.gate("cnot", [1, 4])
        k.gate("cnot", [2, 0])
        k.gate("cnot", [2, 5])
        k.gate("cnot", [3, 0])
        k.gate("cnot", [3, 1])
        k.gate("cnot", [3, 5])
        k.gate("cnot", [3, 6])
        k.gate("cnot", [4, 1])
        k.gate("cnot", [4, 6])
        k.gate("cnot", [5, 2])
        k.gate("cnot", [5, 3])
        k.gate("cnot", [6, 3])
        k.gate("cnot", [6, 4])

        prog.add_kernel(k)

        ql.set_option("scheduler", scheduler)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #24
0
    def test_AllXY(self):
        """
        Single qubit AllXY sequence.
        Writes output files to the directory specified in openql.
        Output directory is set as an attribute to the program for convenience.

        Input pars:
            qubit_idx:      int specifying the target qubit (starting at 0)
            platf_cfg:      filename of the platform config file
            double_points:  if true repeats every element twice
        Returns:
            p:              OpenQL Program object containing


        """
        config_fn = os.path.join(curdir, 'test_cfg_CCL_long_duration.json')
        platf = ql.Platform('seven_qubits_chip', config_fn)
        p = ql.Program("AllXYLongDuration", platf, platf.get_qubit_number())

        allXY = [['i', 'i'], ['rx180', 'ry180'], ['ry180', 'rx180']]
        # ,
        #  ['rx180', 'ry180'], ['ry180', 'rx180'],
        #  ['rx90', 'i'], ['ry90', 'i'], ['rx90', 'ry90'],
        #  ['ry90', 'rx90'], ['rx90', 'ry180'], ['ry90', 'rx180'],
        #  ['rx180', 'ry90'], ['ry180', 'rx90'], ['rx90', 'rx180'],
        #  ['rx180', 'rx90'], ['ry90', 'ry180'], ['ry180', 'ry90'],
        #  ['rx180', 'i'], ['ry180', 'i'], ['rx90', 'rx90'],
        #  ['ry90', 'ry90']]

        # this should be implicit
        p.set_sweep_points(np.arange(len(allXY), dtype=float))
        qubit_idx = 0
        for i, xy in enumerate(allXY):
            k = ql.Kernel("AllXY_" + str(i), platf, platf.get_qubit_number())
            k.prepz(qubit_idx)
            k.gate(xy[0], [qubit_idx])
            k.gate(xy[1], [qubit_idx])
            k.measure(qubit_idx)
            p.add_kernel(k)

        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
Exemple #25
0
    def test_smis_multi_kernel(self):

        # You can specify a config location, here we use a default config
        config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
        platform = ql.Platform('seven_qubits_chip', config_fn)
        sweep_points = [1, 2]
        num_qubits = 7
        p = ql.Program('aProgram', platform, num_qubits)
        p.set_sweep_points(sweep_points)

        # populate the first kernel using default gates
        k = ql.Kernel('aKernel01', platform, num_qubits)
        k.prepz(0)
        k.x(2)
        k.y(3)
        k.z(5)
        k.rx90(0)
        # k.cphase(0,1)  # when uncommented this should raise 'operation not supported' exception.
        # k.cphase(0,3)
        k.cnot(0, 3)
        k.measure(0)

        # add the kernel to the program
        p.add_kernel(k)

        # populate the second kernel using both custom and default gates
        k = ql.Kernel('aKernel02', platform, num_qubits)
        k.gate('prepz', [0])  # this line is equivalent to the previous
        k.gate('x', [0])
        k.y(1)
        k.z(5)
        k.gate('rx90', [0])
        # k.gate('cz', [0, 3])
        k.gate('cnot', [0, 3])
        k.gate('measure', [0])

        # add the kernel to the program
        p.add_kernel(k)

        # compile the program
        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
Exemple #26
0
    def test_ccl_latencies(self):

        tests = [
            # 'y q3' has a latency of 0 ns
            (0, [("x", [0]), ("y", [3])]),
            # 'y q4' has a latency of +20 ns
            (1, [("x", [0]), ("y", [4])]),
            # 'y q5' has a latency of -20 ns
            (2, [("x", [0]), ("y", [5])]),
            # qubit dependence and 'y q3' has a latency of 0 ns
            (3, [("x", [3]), ("y", [3])]),
            # qubit dependence and 'y q4' has a latency of +20 ns
            (4, [("x", [4]), ("y", [4])]),
            # qubit dependence and 'y q5' has a latency of -20 ns
            (5, [("x", [5]), ("y", [5])])
        ]

        for testNo, testKernel in tests:
            print('Running test_ccl_latencies No: {}'.format(testNo))
            config_fn = os.path.join(
                curdir, 'test_cfg_cc_light_buffers_latencies.json')
            platform = ql.Platform('seven_qubits_chip', config_fn)
            sweep_points = [1, 2]
            num_qubits = 7
            p = ql.Program('test_ccl_latencies' + str(testNo), platform,
                           num_qubits)
            p.set_sweep_points(sweep_points)
            k = ql.Kernel('aKernel', platform, num_qubits)

            for gate, qubits in testKernel:
                k.gate(gate, qubits)

            p.add_kernel(k)
            p.compile()

            QISA_fn = os.path.join(output_dir, p.name + '.qisa')
            gold_fn = rootDir + '/golden/test_ccl_latencies_' + str(
                testNo) + '.qisa'

            assemble(QISA_fn)

            self.assertTrue(file_compare(QISA_fn, gold_fn))
    def test_skip_yes(self):
        self.setUp()
        # just check whether skip works for trivial case
        # parameters
        ql.set_option('issue_skip_319', 'yes')
        v = 'yes'
        config = os.path.join(rootDir, "test_mapper_s7.json")
        num_qubits = 7

        # create and set platform
        prog_name = "test_skip_" + v
        kernel_name = "kernel_" + v
        starmon = ql.Platform("starmon", config)
        prog = ql.Program(prog_name, starmon, num_qubits, 0)

        qasm_rdr = ql.cQasmReader(starmon, prog)
        qasm_str = """version 1.0
            qubits 7
            .{kernel_name}
            cnot q[2],q[5]
            skip 2
            {{ x q[0] | y q[1] }}
            """.format(kernel_name=kernel_name)

        qasm_rdr.string2circuit(qasm_str)

        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden',
                               prog.name + '_scheduled.qasm')
        QASM_fn = os.path.join(output_dir,
                               prog.name + '_scheduledqasmwriter_out.qasm')

        assemble(QASM_fn)
        self.assertTrue(file_compare(QASM_fn, GOLD_fn))

        ql.set_option('write_qasm_files', 'no')
        ql.set_option('write_report_files', 'no')
        ql.set_option('unique_output', 'no')
        ql.set_option('mapper', 'no')

        ql.set_option('issue_skip_319', 'no')
    def test_mapper_allIP(self):
        # longest string of cnots with operands that could be at distance 1 in s7
        # matches intel NISQ application
        # initial placement should find this
        # and then no swaps are inserted
        # otherwise ...
        # the heuristics must act and insert swaps/moves
        # parameters
        v = 'allIP'
        config = os.path.join(rootDir, "test_mapper_s7.json")
        num_qubits = 7

        # create and set platform
        prog_name = "test_mapper_" + v
        kernel_name = "kernel_" + v
        starmon = ql.Platform("starmon", config)
        prog = ql.Program(prog_name, starmon, num_qubits, 0)
        k = ql.Kernel(kernel_name, starmon, num_qubits, 0)

        for j in range(7):
            k.gate("x", [j])
        k.gate("cnot", [0, 1])
        k.gate("cnot", [1, 2])
        k.gate("cnot", [2, 3])
        k.gate("cnot", [3, 4])
        k.gate("cnot", [4, 5])
        k.gate("cnot", [5, 6])
        for j in range(7):
            k.gate("x", [j])

        prog.add_kernel(k)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))
Exemple #29
0
    def test_edge_busy(self):

        config_fn = os.path.join(curdir, 'hardware_config_cc_light.json')
        platform = ql.Platform('seven_qubits_chip', config_fn)
        sweep_points = [1, 2]
        num_qubits = 7
        p = ql.Program('aProgram', platform, num_qubits)
        p.set_sweep_points(sweep_points)

        # populate kernel using default gates
        k = ql.Kernel('aKernel', platform, num_qubits)

        k.gate('cz', [0, 2])
        k.gate('cz', [1, 3])

        # add the kernel to the program
        p.add_kernel(k)

        # compile the program
        p.compile()

        QISA_fn = os.path.join(output_dir, p.name + '.qisa')
        assemble(QISA_fn)
Exemple #30
0
    def test_issue179(self):
        self.setUp()
        # parameters
        v = 'issue179'
        scheduler = self._SCHEDULER

        # create and set platform
        prog_name = "test_" + v + '_' + scheduler
        kernel_name = "kernel_" + v + '_' + scheduler

        starmon = ql.Platform("starmon", self.config)
        prog = ql.Program(prog_name, starmon, 7, 0)
        k = ql.Kernel(kernel_name, starmon, 7, 0)

        # independent gates but stacking qwg unit use
        # in s7, q2, q3 and q4 all use qwg1
        # the y q3 must be in an other cycle than the x's because x conflicts with y in qwg1
        # the x q2 and x q4 can be in parallel but the y q3 in between prohibits this
        # because the qwg1 resource in single dimensional:
        # after x q2 it is busy on x in cycle 0,
        # then it only looks at the y q3, which requires to go to cycle 1,
        # and then the x q4 only looks at the current cycle (cycle 1),
        # in which qwg1 is busy with the y, so for the x it is busy,
        # and the only option is to go for cycle 2
        k.gate("x", [2])
        k.gate("y", [3])
        k.gate("x", [4])

        prog.add_kernel(k)
        ql.set_option("scheduler", scheduler)
        prog.compile()

        GOLD_fn = os.path.join(rootDir, 'golden', prog.name + '.qisa')
        QISA_fn = os.path.join(output_dir, prog.name + '.qisa')

        assemble(QISA_fn)
        self.assertTrue(file_compare(QISA_fn, GOLD_fn))