Exemple #1
0
def full_2q_gst(q0: int, q1: int, platf_cfg: str, recompile=True):
    """
    Generates the QISA and QASM programs for full 2Q GST.
    """

    logging.warning("DEPRECATION WARNING full_2q_gst")

    MAX_EXPLIST_SIZE = 3000  # UHFQC shot limit
    DBG = True  # debugging

    # grab the experiment list file
    fp = join(gst_exp_filepath, 'Explist_2Q_XYCphase.txt')
    # parse the file into expList object
    print('Converting dataset to expLit')
    t0 = time.time()
    expList = pygsti_expList_from_dataset(fp)
    print("converting to expList took {:.2f}".format(time.time()-t0))
    # divide into smaller experiment lists
    programs = []

    cutting_indices = [0, 3000, 5500, 7000, 9000]
    t0 = time.time()
    print('Generating {} GST programs'.format(len(cutting_indices)-1))

    for exp_num, start_idx in enumerate(cutting_indices[:-1]):
        stop_idx = cutting_indices[exp_num+1]
        el = expList[start_idx:stop_idx]

    # exp_num = int(np.ceil(len(expList)/MAX_EXPLIST_SIZE))# amount of experiments
    # for exp_i in range(exp_num-1): # loop over the experiments except the last one
        # make smaller experiment list
        # el = expList[exp_i*MAX_EXPLIST_SIZE:(exp_i+1)*MAX_EXPLIST_SIZE]
        # if DBG: print('dbg {}, {}'.format(exp_i*MAX_EXPLIST_SIZE,(exp_i+1)*MAX_EXPLIST_SIZE)) # dbg

        # turn into openql program
        p = openql_program_from_pygsti_expList(
            el, 'full 2Q GST exp {}-{}'.format(start_idx, stop_idx),
            qubits=[2, 0],
            start_idx=start_idx,
            platf_cfg=platf_cfg, recompile=recompile)
        # append to list of programs
        programs.append(p)
        print('Generated {} GST programs in {:.1f}s'.format(
              exp_num+1, time.time()-t0), end='\r')

    print('Succesfully generated {} GST programs in {:.1f}s'.format(
        len(cutting_indices)-1, time.time()-t0))

    # last experiment
    # el = expList[(exp_num-1)*MAX_EXPLIST_SIZE:] # grab experiment list
    # if DBG: print('dbg {}, end'.format((exp_num-1)*MAX_EXPLIST_SIZE)) # dbg
    # # turn into openql program
    # p = openql_program_from_pygsti_expList(
    #     el, 'full 2Q GST index {}'.format(exp_num-1),
    #     [2, 0], platf_cfg=platf_cfg,  recompile=recompile)
    # # append to list of programs
    # programs.append(p)

    return programs
    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 #3
0
def poor_mans_2q_gst(q0: int, q1: int, platf_cfg: str,):
    """
    Generates the QISA and QASM programs for poor_mans_GST, this is 2Q GST
    without the repetitions of any gate.
    """
    logging.warning("DEPRECATION WARNING poor_mans_2q_gst")
    fp = join(gst_exp_filepath, 'PoorMans_2Q_GST.txt')
    expList = pygsti_expList_from_dataset(fp)
    p = openql_program_from_pygsti_expList(
        expList, 'PoorMans_GST', [2, 0], platf_cfg=platf_cfg)
    return p
    def test_pygsti_expList_from_dataset(self):
        dataset_filename = os.path.join(gst_exp_filepath,
                                        'std1Q_XYI_lite_maxL256.txt')
        explist = pygsti_expList_from_dataset(
            dataset_filename=dataset_filename)

        expected_firstpart = ['{}', 'Gx', 'Gy', 'GxGx', 'GxGxGx',
                              'GyGyGy', 'GxGy', 'GxGxGxGx', 'GxGyGyGy', 'GyGx']
        for i, gs in enumerate(explist[0:10]):
            self.assertEqual(gs.str, expected_firstpart[i])

        expected_finalpart = [
            'GxGxGx(GxGxGy)^85Gy', 'GxGxGx(GxGxGy)^85GxGx',
            'GxGxGx(GxGxGy)^85GxGxGx', 'GxGxGx(GxGxGy)^85GyGyGy',
            'GyGyGy(GxGxGy)^85', 'GyGyGy(GxGxGy)^85Gx', 'GyGyGy(GxGxGy)^85Gy',
            'GyGyGy(GxGxGy)^85GxGx', 'GyGyGy(GxGxGy)^85GxGxGx',
            'GyGyGy(GxGxGy)^85GyGyGy']
        for i, gs in enumerate(explist[-10:]):
            self.assertEqual(gs.str, expected_finalpart[i])
Exemple #5
0
    def extract_data(self):
        self.raw_data_dict = OrderedDict()

        self.timestamps = a_tools.get_timestamps_in_range(self.t_start,
                                                          self.t_stop,
                                                          label=self.labels)
        self.raw_data_dict['timestamps'] = self.timestamps

        self.timestamp = self.timestamps[0]
        a = ma_old.MeasurementAnalysis(timestamp=self.timestamp,
                                       auto=False,
                                       close_file=False)
        a.get_naming_and_values()

        self.raw_data_dict['xvals'] = a.sweep_points
        self.raw_data_dict['xlabel'] = a.parameter_names[0]
        self.raw_data_dict['xunit'] = a.parameter_units[0]

        self.raw_data_dict['bins'] = a.data_file['Experimental Data'][
            'Experimental Metadata']['bins'].value

        if self.gst_exp_list_filepath == None:
            gst_exp_list_filename = a.data_file['Experimental Data'][
                'Experimental Metadata'].attrs['gst_exp_list_filename']

            self.raw_data_dict['gst_exp_list_filepath'] = os.path.join(
                gst_exp_filepath, gst_exp_list_filename)
        else:
            self.raw_data_dict['gst_exp_list_filepath'] = \
                self.gst_exp_list_filepath

        self.raw_data_dict['expList'] = pygsti_expList_from_dataset(
            self.raw_data_dict['gst_exp_list_filepath'])

        self.raw_data_dict['measured_values'] = a.measured_values
        self.raw_data_dict['value_names'] = a.value_names
        self.raw_data_dict['value_units'] = a.value_units
        self.raw_data_dict['measurementstring'] = a.measurementstring
        self.measurementstring = a.measurementstring
        self.raw_data_dict['folder'] = a.folder
        a.finish()
Exemple #6
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