def test_split_expList(self):
        dataset_filename = os.path.join(gst_exp_filepath,
                                        'std1Q_XYI_lite_maxL256.txt')
        explist = pygsti_expList_from_dataset(
            dataset_filename=dataset_filename)

        splitted_lists = split_expList(explist, verbose=True)
        recombined_list = list(itertools.chain.from_iterable(splitted_lists))

        self.assertListEqual(explist, recombined_list)
Exemple #2
0
def single_qubit_gst(q0: int,
                     platf_cfg: str,
                     maxL: int = 256,
                     lite_germs: bool = True,
                     recompile=True,
                     verbose: bool = True):
    """
    Generates the QISA and QASM programs for full 2Q GST.

    Args:
        q0 (int)        : target qubit
        platf_cfg (str) : string specifying config filename
        maxL (int)      : specifies the maximum germ length,
                          must be power of 2.
        lite_germs(bool): if True uses "lite" germs
        recompile:      True -> compiles the program,
                        'as needed' -> compares program to timestamp of config
                            and existence, if required recompile.
                        False -> compares program to timestamp of config.
                            if compilation is required raises a ValueError

                        If the program is more recent than the config
                        it returns an empty OpenQL program object with
                        the intended filename that can be used to upload the
                        previously compiled file.
        verbose (bool)  : if True prints extra debug info


    Returns:
        programs (list) : list of OpenQL program objects

    """
    # grab the experiment list file
    if lite_germs:
        exp_list_fn = 'std1Q_XYI_lite_maxL{}.txt'.format(maxL)
    else:
        exp_list_fn = 'std1Q_XYI_maxL{}.txt'.format(maxL)
    exp_list_fp = join(gst_exp_filepath, exp_list_fn)

    if verbose:
        print('Converting dataset to expList')
    t0 = time.time()
    expList = pygsti_expList_from_dataset(exp_list_fp)
    if verbose:
        print("Converted dataset to expList in {:.2f}s".format(time.time() -
                                                               t0))
    # divide into smaller experiment lists
    programs = []

    t0 = time.time()
    if verbose:
        print('Generating GST programs')

    expSubLists = split_expList(expList, verbose=verbose)

    start_idx = 0
    for exp_num, expSubList in enumerate(expSubLists):
        stop_idx = start_idx + len(expSubList)

        # turn into openql program
        p = openql_program_from_pygsti_expList(
            expSubList,
            'std1Q_XYI q{} {} {} {}-{}'.format(q0, lite_germs, maxL, start_idx,
                                               stop_idx),
            qubits=[q0],
            start_idx=start_idx,
            platf_cfg=platf_cfg,
            recompile=recompile)
        # append to list of programs
        programs.append(p)
        start_idx += len(expSubList)
        if verbose:
            print('Generated {} GST programs in {:.1f}s'.format(
                exp_num + 1,
                time.time() - t0),
                  end='\r')

    print('Generated {} GST programs in {:.1f}s'.format(
        exp_num + 1,
        time.time() - t0))

    return programs, exp_list_fn