Beispiel #1
0
def flipping(qubit_idx: int,
             number_of_flips,
             platf_cfg: str,
             equator: bool = False,
             cal_points: bool = True):
    """
    Generates a flipping sequence that performs multiple pi-pulses
    Basic sequence:
        - (X)^n - RO

    Input pars:
        qubit_idx:      int specifying the target qubit (starting at 0)
        number_of_flips: array of ints specifying the sweep points
        platf_cfg:      filename of the platform config file
        equator:        if True add an extra pi/2 pulse at the end to
                        make the state end at the equator.
        cal_points:     replaces last 4 points by calibration points

    Returns:
        p:              OpenQL Program object
    """
    platf = Platform('OpenQL_Platform', platf_cfg)
    p = Program(pname="Flipping", nqubits=platf.get_qubit_number(), p=platf)

    for i, n in enumerate(number_of_flips):
        k = Kernel("Flipping_" + str(i), p=platf)
        k.prepz(qubit_idx)
        if cal_points and (i == (len(number_of_flips) - 4)
                           or i == (len(number_of_flips) - 3)):
            k.measure(qubit_idx)
        elif cal_points and (i == (len(number_of_flips) - 2)
                             or i == (len(number_of_flips) - 1)):
            k.x(qubit_idx)
            k.measure(qubit_idx)
        else:
            if equator:
                k.gate('rx90', qubit_idx)
            for j in range(n):
                k.x(qubit_idx)
            k.measure(qubit_idx)
        p.add_kernel(k)

    with suppress_stdout():
        p.compile(verbose=False)
    # attribute get's added to program to help finding the output files
    p.output_dir = ql.get_output_dir()
    p.filename = join(p.output_dir, p.name + '.qisa')
    return p
Beispiel #2
0
def single_elt_on(qubit_idx: int, platf_cfg: str):
    platf = Platform('OpenQL_Platform', platf_cfg)
    p = Program(pname="Single_elt_on",
                nqubits=platf.get_qubit_number(),
                p=platf)
    k = Kernel("main", p=platf)
    k.prepz(qubit_idx)
    k.x(qubit_idx)
    k.measure(qubit_idx)
    p.add_kernel(k)

    with suppress_stdout():
        p.compile(verbose=False)
    # attribute get's added to program to help finding the output files
    p.output_dir = ql.get_output_dir()
    p.filename = join(p.output_dir, p.name + '.qisa')
    return p
Beispiel #3
0
def butterfly(qubit_idx: int, initialize: bool, platf_cfg: str):
    """
    Performs a 'butterfly' sequence on the qubit specified.
        0:  prepz (RO) -      - RO - RO
        1:  prepz (RO) - x180 - RO - RO

    Args:
        qubit_idx (int)  : index of the qubit
        initialize (bool): if True does an extra initial measurement to
            post select data.
        platf_cfg (str)  : openql config used for setup.

    """
    platf = Platform('OpenQL_Platform', platf_cfg)
    p = Program(pname="Butterfly", nqubits=platf.get_qubit_number(), p=platf)

    k = Kernel('0', p=platf)
    k.prepz(qubit_idx)
    if initialize:
        k.measure(qubit_idx)
    k.measure(qubit_idx)
    k.measure(qubit_idx)
    p.add_kernel(k)

    k = Kernel('1', p=platf)
    k.prepz(qubit_idx)
    if initialize:
        k.measure(qubit_idx)
    k.x(qubit_idx)
    k.measure(qubit_idx)
    k.measure(qubit_idx)
    p.add_kernel(k)

    with suppress_stdout():
        p.compile(verbose=False)
    # attribute get's added to program to help finding the output files
    p.output_dir = ql.get_output_dir()
    p.filename = join(p.output_dir, p.name + '.qisa')
    return p
Beispiel #4
0
def randomized_benchmarking(qubit_idx: int,
                            platf_cfg: str,
                            nr_cliffords,
                            nr_seeds: int,
                            net_clifford: int = 0,
                            restless: bool = False,
                            program_name: str = 'randomized_benchmarking',
                            cal_points: bool = True,
                            double_curves: bool = False):
    '''
    Input pars:
        qubit_idx:      int specifying the target qubit (starting at 0)
        platf_cfg:      filename of the platform config file
        nr_cliffords:   list nr_cliffords for which to generate RB seqs
        nr_seeds:       int  nr_seeds for which to generate RB seqs
        net_clifford:   int index of net clifford the sequence should perform
                            0 -> Idx
                            3 -> rx180
        restless:       bool, does not initialize if restless is True
        program_name:           some string that can be used as a label.
        cal_points:     bool whether to replace the last two elements with
                        calibration points, set to False if you want
                        to measure a single element (for e.g. optimization)

        double_curves: Alternates between net clifford 0 and 3

    Returns:
        p:              OpenQL Program object

    generates a program for single qubit Clifford based randomized
    benchmarking.
    '''
    net_cliffords = [0, 3]  # Exists purely for the double curves mode
    platf = Platform('OpenQL_Platform', platf_cfg)
    p = Program(pname=program_name, nqubits=platf.get_qubit_number(), p=platf)

    i = 0
    for seed in range(nr_seeds):
        for j, n_cl in enumerate(nr_cliffords):
            k = Kernel('RB_{}Cl_s{}'.format(n_cl, seed), p=platf)
            if not restless:
                k.prepz(qubit_idx)
            if cal_points and (j == (len(nr_cliffords) - 4)
                               or j == (len(nr_cliffords) - 3)):
                k.measure(qubit_idx)

            elif cal_points and (j == (len(nr_cliffords) - 2)
                                 or j == (len(nr_cliffords) - 1)):
                k.x(qubit_idx)
                k.measure(qubit_idx)
            else:
                if double_curves:
                    net_clifford = net_cliffords[i % 2]
                    i += 1
                cl_seq = rb.randomized_benchmarking_sequence(
                    n_cl, desired_net_cl=net_clifford)
                # pulse_keys = rb.decompose_clifford_seq(cl_seq)
                for cl in cl_seq:
                    k.gate('cl_{}'.format(cl), qubit_idx)
                k.measure(qubit_idx)
            p.add_kernel(k)
    with suppress_stdout():
        p.compile(verbose=False)
    # attribute get's added to program to help finding the output files
    p.output_dir = ql.get_output_dir()
    p.filename = join(p.output_dir, p.name + '.qisa')
    return p