Exemplo n.º 1
0
def example_upload(hdawg_kwargs: dict, channels: Set[int],
                   markers: Set[Tuple[int, int]]):
    from qupulse.pulses import TablePT, SequencePT, RepetitionPT
    if isinstance(hdawg_kwargs, dict):
        hdawg = HDAWGRepresentation(**hdawg_kwargs)
    else:
        hdawg = hdawg_kwargs

    assert not set(channels) - set(range(8)), "Channels must be in 0..=7"
    channels = sorted(channels)

    channel_tuples = [
        ct for i, ct in enumerate(hdawg.channel_tuples)
        if i * 2 in channels or i * 2 + 1 in channels
    ]
    assert channel_tuples

    # choose length based on minimal sample rate
    min_sr = min(ct.sample_rate for ct in channel_tuples) / 10**9
    min_t = channel_tuples[0].MIN_WAVEFORM_LEN / min_sr
    quant_t = channel_tuples[0].WAVEFORM_LEN_QUANTUM / min_sr

    assert min_t > 4 * quant_t, "Example not updated"

    entry_list1 = [(0, 0), (quant_t * 2, .2, 'hold'), (min_t, .3, 'linear'),
                   (min_t + 3 * quant_t, 0, 'jump')]
    entry_list2 = [(0, 0), (quant_t * 3, -.2, 'hold'), (min_t, -.3, 'linear'),
                   (min_t + 4 * quant_t, 0, 'jump')]
    entry_list3 = [(0, 0), (quant_t * 1, -.2, 'linear'),
                   (min_t, -.3, 'linear'), (2 * min_t, 0, 'jump')]
    entry_lists = [entry_list1, entry_list2, entry_list3]

    entry_dict1 = {ch: entry_lists[:2][i % 2] for i, ch in enumerate(channels)}
    entry_dict2 = {
        ch: entry_lists[1::-1][i % 2]
        for i, ch in enumerate(channels)
    }
    entry_dict3 = {
        ch: entry_lists[2:0:-1][i % 2]
        for i, ch in enumerate(channels)
    }

    tpt1 = TablePT(entry_dict1, measurements=[('m', 20, 30)])
    tpt2 = TablePT(entry_dict2)
    tpt3 = TablePT(entry_dict3, measurements=[('m', 10, 50)])
    rpt = RepetitionPT(tpt1, 4)
    spt = SequencePT(tpt2, rpt)
    rpt2 = RepetitionPT(spt, 2)
    spt2 = SequencePT(rpt2, tpt3)
    p = spt2.create_program()

    # use HardwareSetup for this
    for ct in channel_tuples:
        i = hdawg.channel_tuples.index(ct)
        ch = tuple(ch if ch in channels else None for ch in (2 * i, 2 * i + 1))
        mk = (None, None, None, None)
        vt = (lambda x: x, lambda x: x)
        ct.upload('pulse_test1', p, ch, mk, vt)

    for ct in channel_tuples:
        ct.arm('pulse_test1')

    # channel_tuples[0].run_current_program()

    if markers:
        markers = sorted(markers)
        assert len(markers) == len(set(markers))

        channel_tuples = []
        for ch, m in markers:
            assert ch in range(8)
            assert m in (0, 1)
            ct = hdawg.channel_tuples[ch // 2]
            if ct not in channel_tuples:
                channel_tuples.append(ct)

        full_on = [(0, 1), (min_t, 1)]
        two_3rd = [(0, 1), (min_t * 2 / 3, 0), (min_t, 0)]
        one_3rd = [(0, 0), (min_t * 2 / 3, 1), (min_t, 1)]

        marker_start = TablePT({'m1': full_on, 'm2': full_on})
        marker_body = TablePT({'m1': two_3rd, 'm2': one_3rd})

        marker_test_pulse = marker_start @ RepetitionPT(marker_body, 10000)

        marker_program = marker_test_pulse.create_program()

        for ct in channel_tuples:
            i = hdawg.channel_tuples.index(ct)
            ch = (None, None)
            mk = ('m1' if (i * 2, 0) in markers else None, 'm2' if
                  (i * 2, 1) in markers else None, 'm1' if
                  (i * 2 + 1, 0) in markers else None, 'm2' if
                  (i * 2 + 1, 1) in markers else None)
            vt = (lambda x: x, lambda x: x)
            ct.upload('marker_test', marker_program, ch, mk, vt)
            ct.arm('marker_test')

        channel_tuples[0].run_current_program()
Exemplo n.º 2
0
def example_upload(hdawg_kwargs: dict, channels: Set[int], markers: Set[Tuple[int, int]]):  # pragma: no cover
    from qupulse.pulses import TablePT, SequencePT, RepetitionPT
    if isinstance(hdawg_kwargs, dict):
        hdawg = HDAWGRepresentation(**hdawg_kwargs)
    else:
        hdawg = hdawg_kwargs

    assert not set(channels) - set(range(8)), "Channels must be in 0..=7"
    channels = sorted(channels)

    required_channels = {*channels, *(ch for ch, _ in markers)}
    channel_group = get_group_for_channels(hdawg, required_channels)
    channel_group_channels = range(channel_group.awg_group_index * channel_group.num_channels,
                                   (channel_group.awg_group_index + 1) * channel_group.num_channels)

    # choose length based on minimal sample rate
    sample_rate = channel_group.sample_rate / 10**9
    min_t = channel_group.MIN_WAVEFORM_LEN / sample_rate
    quant_t = channel_group.WAVEFORM_LEN_QUANTUM / sample_rate

    assert min_t > 4 * quant_t, "Example not updated"

    entry_list1 = [(0, 0), (quant_t * 2, .2, 'hold'),    (min_t,  .3, 'linear'),   (min_t + 3*quant_t, 0, 'jump')]
    entry_list2 = [(0, 0), (quant_t * 3, -.2, 'hold'),   (min_t, -.3, 'linear'),  (min_t + 4*quant_t, 0, 'jump')]
    entry_list3 = [(0, 0), (quant_t * 1, -.2, 'linear'), (min_t, -.3, 'linear'), (2*min_t, 0, 'jump')]
    entry_lists = [entry_list1, entry_list2, entry_list3]

    entry_dict1 = {ch: entry_lists[:2][i % 2] for i, ch in enumerate(channels)}
    entry_dict2 = {ch: entry_lists[1::-1][i % 2] for i, ch in enumerate(channels)}
    entry_dict3 = {ch: entry_lists[2:0:-1][i % 2] for i, ch in enumerate(channels)}

    tpt1 = TablePT(entry_dict1, measurements=[('m', 20, 30)])
    tpt2 = TablePT(entry_dict2)
    tpt3 = TablePT(entry_dict3, measurements=[('m', 10, 50)])
    rpt = RepetitionPT(tpt1, 4)
    spt = SequencePT(tpt2, rpt)
    rpt2 = RepetitionPT(spt, 2)
    spt2 = SequencePT(rpt2, tpt3)
    p = spt2.create_program()

    upload_ch = tuple(ch if ch in channels else None
                      for ch in channel_group_channels)
    upload_mk = (None,) * channel_group.num_markers
    upload_vt = (lambda x: x,) * channel_group.num_channels

    channel_group.upload('pulse_test1', p, upload_ch, upload_mk, upload_vt)

    if markers:
        markers = sorted(markers)
        assert len(markers) == len(set(markers))
        channel_group_markers = tuple((ch, mk)
                                      for ch in channel_group_channels
                                      for mk in (0, 1))

        full_on = [(0, 1), (min_t, 1)]
        two_3rd = [(0, 1), (min_t*2/3, 0), (min_t, 0)]
        one_3rd = [(0, 0), (min_t*2/3, 1), (min_t, 1)]

        marker_start = TablePT({'m0': full_on, 'm1': full_on})
        marker_body = TablePT({'m0': two_3rd, 'm1': one_3rd})

        marker_test_pulse = marker_start @ RepetitionPT(marker_body, 10000)

        marker_program = marker_test_pulse.create_program()

        upload_ch = (None, ) * channel_group.num_channels
        upload_mk = tuple(f"m{mk}" if (ch, mk) in markers else None
                          for (ch, mk) in channel_group_markers)

        channel_group.upload('marker_test', marker_program, upload_ch, upload_mk, upload_vt)

    try:
        while True:
            for program in channel_group.programs:
                print(f'playing {program}')
                channel_group.arm(program)
                channel_group.run_current_program()
                while not channel_group.was_current_program_finished():
                    print(f'waiting for {program} to finish')
                    time.sleep(1e-2)
    finally:
        channel_group.enable(False)
Exemplo n.º 3
0
    tpt1 = TablePT({
        0: entry_list1,
        1: entry_list2
    },
                   measurements=[('m', 20, 30)])
    tpt2 = TablePT({0: entry_list2, 1: entry_list1})
    tpt3 = TablePT({
        0: entry_list3,
        1: entry_list2
    },
                   measurements=[('m', 10, 50)])
    rpt = RepetitionPT(tpt1, 4)
    spt = SequencePT(tpt2, rpt)
    rpt2 = RepetitionPT(spt, 2)
    spt2 = SequencePT(rpt2, tpt3)
    p = spt2.create_program()

    ch = (0, 1)
    mk = (0, None)
    vt = (lambda x: x, lambda x: x)
    hdawg.channel_pair_AB.upload('table_pulse_test1', p, ch, mk, vt)

    entry_list_zero = [(0, 0), (100, 0, 'hold')]
    entry_list_step = [(0, 0), (50, .5, 'hold'), (100, 0, 'hold')]
    marker_start = TablePT({'P1': entry_list_zero, 'marker': entry_list_step})
    tpt1 = TablePT({'P1': entry_list_zero, 'marker': entry_list_zero})
    spt2 = SequencePT(marker_start, tpt1)

    p = spt2.create_program()

    ch = ('P1', None)