Exemplo n.º 1
0
    def test_remove_program(self):
        loop1, loop2, _ = self.get_test_loops()

        awg1 = DummyAWG()
        awg2 = DummyAWG()
        awg3 = DummyAWG()

        dac1 = DummyDAC()
        dac2 = DummyDAC()

        setup = HardwareSetup()

        setup.set_channel('A', PlaybackChannel(awg1, 0))
        setup.set_channel('B', MarkerChannel(awg2, 0))
        setup.set_channel('C', MarkerChannel(awg3, 0))

        setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1'))
        setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2'))

        setup.register_program('test_1', loop1)

        setup.register_program('test_2', loop2)

        setup.arm_program('test_1')

        setup.remove_program('test_1')

        self.assertEqual(setup.registered_programs.keys(), {'test_2'})

        self.assertIsNone(awg1._armed)
        self.assertIsNone(awg2._armed)
    def initialize_hardware_setup(self):
        self.simulator_manager = TaborSimulatorManager()

        try:
            self.simulator_manager.start_simulator()
        except RuntimeError as err:
            raise unittest.SkipTest(*err.args) from err

        self.awg = self.simulator_manager.connect()
        if self.preparation_commands:
            for cmd in self.preparation_commands:
                self.awg.send_cmd(cmd)

        self.dac = DummyDAC()
        self.hardware_setup = HardwareSetup()

        self.hardware_setup.set_channel('TABOR_A', PlaybackChannel(self.awg.channel_pair_AB, 0))
        self.hardware_setup.set_channel('TABOR_B', PlaybackChannel(self.awg.channel_pair_AB, 1))
        self.hardware_setup.set_channel('TABOR_A_MARKER', MarkerChannel(self.awg.channel_pair_AB, 0))
        self.hardware_setup.set_channel('TABOR_B_MARKER', MarkerChannel(self.awg.channel_pair_AB, 1))

        self.hardware_setup.set_channel('TABOR_C', PlaybackChannel(self.awg.channel_pair_CD, 0))
        self.hardware_setup.set_channel('TABOR_D', PlaybackChannel(self.awg.channel_pair_CD, 1))
        self.hardware_setup.set_channel('TABOR_C_MARKER', MarkerChannel(self.awg.channel_pair_CD, 0))
        self.hardware_setup.set_channel('TABOR_D_MARKER', MarkerChannel(self.awg.channel_pair_CD, 1))

        self.hardware_setup.set_measurement("MEAS_A", MeasurementMask(self.dac, "MASK_A"))
        self.hardware_setup.set_measurement("MEAS_B", MeasurementMask(self.dac, "MASK_B"))
        self.hardware_setup.set_measurement("MEAS_C", MeasurementMask(self.dac, "MASK_C"))
        self.hardware_setup.set_measurement("MEAS_D", MeasurementMask(self.dac, "MASK_D"))
Exemplo n.º 3
0
    def initialize_hardware_setup(self):
        self.awg = get_test_hdawg()

        if self.preparation_commands:
            preparation_commands = [
                (key.format(device_serial=self.awg.serial), value)
                for key, value in self.preparation_commands.items()
            ]
            self.awg.api_session.set(preparation_commands)

        for idx in range(1, 9):
            # switch off all outputs
            self.awg.output(idx, False)

        self.awg.channel_grouping = zihdawg.HDAWGChannelGrouping.CHAN_GROUP_1x8

        self.channel_group, = self.awg.channel_tuples

        self.dac = DummyDAC()

        hardware_setup = HardwareSetup()

        hardware_setup.set_channel('TABOR_A',
                                   PlaybackChannel(self.channel_group, 0))
        hardware_setup.set_channel('TABOR_B',
                                   PlaybackChannel(self.channel_group, 1))
        hardware_setup.set_channel('TABOR_A_MARKER',
                                   MarkerChannel(self.channel_group, 0))
        hardware_setup.set_channel('TABOR_B_MARKER',
                                   MarkerChannel(self.channel_group, 1))

        hardware_setup.set_channel('TABOR_C',
                                   PlaybackChannel(self.channel_group, 2))
        hardware_setup.set_channel('TABOR_D',
                                   PlaybackChannel(self.channel_group, 3))
        hardware_setup.set_channel('TABOR_C_MARKER',
                                   MarkerChannel(self.channel_group, 3))
        hardware_setup.set_channel('TABOR_D_MARKER',
                                   MarkerChannel(self.channel_group, 4))

        hardware_setup.set_measurement("MEAS_A",
                                       MeasurementMask(self.dac, "MASK_A"))
        hardware_setup.set_measurement("MEAS_B",
                                       MeasurementMask(self.dac, "MASK_B"))
        hardware_setup.set_measurement("MEAS_C",
                                       MeasurementMask(self.dac, "MASK_C"))
        hardware_setup.set_measurement("MEAS_D",
                                       MeasurementMask(self.dac, "MASK_D"))

        self.hardware_setup = hardware_setup
Exemplo n.º 4
0
    def test_run_program(self):
        wf = DummyWaveform(duration=1.1, defined_channels={'A', 'B'})

        block = InstructionBlock()
        block.add_instruction_meas([('m1', 0., 1.)])
        block.add_instruction_exec(wf)

        awg1 = DummyAWG()
        awg2 = DummyAWG()
        awg3 = DummyAWG()

        dac1 = DummyDAC()
        dac2 = DummyDAC()

        setup = HardwareSetup()

        setup.set_channel('A', PlaybackChannel(awg1, 0))
        setup.set_channel('B', MarkerChannel(awg2, 0))
        setup.set_channel('C', MarkerChannel(awg3, 0))

        setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1'))
        setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2'))

        class ProgStart:
            def __init__(self):
                self.was_started = False

            def __call__(self):
                self.was_started = True

        program_started = ProgStart()

        setup.register_program('test', block, run_callback=program_started)

        self.assertIsNone(awg1._armed)
        self.assertIsNone(awg2._armed)
        self.assertIsNone(awg3._armed)
        self.assertIsNone(dac1._armed_program)
        self.assertIsNone(dac2._armed_program)

        setup.run_program('test')

        self.assertEqual(awg1._armed, 'test')
        self.assertEqual(awg2._armed, 'test')
        self.assertIsNone(awg3._armed)
        self.assertEqual(dac1._armed_program, 'test')
        self.assertIsNone(dac2._armed_program)

        self.assertTrue(program_started.was_started)
Exemplo n.º 5
0
    def test_clear_programs(self) -> None:
        setup = HardwareSetup()
        awg1 = DummyAWG(num_channels=2, num_markers=0)
        awg2 = DummyAWG(num_channels=1, num_markers=1)
        dac1 = DummyDAC()
        dac2 = DummyDAC()
        setup.set_channel('A', PlaybackChannel(awg1, 0))
        setup.set_channel('B', PlaybackChannel(awg1, 1))
        setup.set_channel('C', PlaybackChannel(awg2, 0))
        setup.set_channel('M1', MarkerChannel(awg2, 0))

        setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1'))
        setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2'))

        loop1, loop2, loop3 = self.get_test_loops()

        setup.register_program('prog1', loop1)
        setup.register_program('prog2', loop2)
        setup.register_program('prog3', loop3)

        self.assertTrue(setup.registered_programs)

        setup.clear_programs()

        self.assertFalse(setup.registered_programs)
Exemplo n.º 6
0
def add_tabor_to_hardware_setup(hardware_setup: HardwareSetup,
                                tabor_address: str = None,
                                name: str = 'TABOR'):
    def _find_tabor_address():
        known_instruments = pyvisa.ResourceManager().list_resources()

        _tabor_address = None
        for address in known_instruments:
            if r'0x168C::0x2184' in address:
                _tabor_address = address
                break
        if _tabor_address is None:
            raise RuntimeError('Could not locate TaborAWG')

        return _tabor_address

    if tabor_address is None:
        tabor_address = _find_tabor_address()

    tawg = TaborAWGRepresentation(tabor_address, reset=True)

    channel_pairs = []
    for pair_name in ('AB', 'CD'):
        channel_pair = getattr(tawg, 'channel_pair_%s' % pair_name)
        channel_pairs.append(channel_pair)

        for ch_i, ch_name in enumerate(pair_name):
            playback_name = '{name}_{ch_name}'.format(name=name,
                                                      ch_name=ch_name)
            hardware_setup.set_channel(playback_name,
                                       PlaybackChannel(channel_pair, ch_i))
            hardware_setup.set_channel(playback_name + '_MARKER',
                                       MarkerChannel(channel_pair, ch_i))

    return tawg, channel_pairs
Exemplo n.º 7
0
    def test_run_program(self):

        loop, *rest = self.get_test_loops()

        awg1 = DummyAWG()
        awg2 = DummyAWG()
        awg3 = DummyAWG()

        dac1 = DummyDAC()
        dac2 = DummyDAC()

        setup = HardwareSetup()

        setup.set_channel('A', PlaybackChannel(awg1, 0))
        setup.set_channel('B', MarkerChannel(awg2, 0))
        setup.set_channel('C', MarkerChannel(awg3, 0))

        setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1'))
        setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2'))

        class ProgStart:
            def __init__(self):
                self.was_started = False

            def __call__(self):
                self.was_started = True

        program_started = ProgStart()

        setup.register_program('test', loop, run_callback=program_started)

        self.assertIsNone(awg1._armed)
        self.assertIsNone(awg2._armed)
        self.assertIsNone(awg3._armed)
        self.assertIsNone(dac1._armed_program)
        self.assertIsNone(dac2._armed_program)

        setup.run_program('test')

        self.assertEqual(awg1._armed, 'test')
        self.assertEqual(awg2._armed, 'test')
        self.assertIsNone(awg3._armed)
        self.assertEqual(dac1._armed_program, 'test')
        self.assertIsNone(dac2._armed_program)

        self.assertTrue(program_started.was_started)
Exemplo n.º 8
0
 def test_known_awgs(self) -> None:
     setup = HardwareSetup()
     awg1 = DummyAWG(num_channels=2, num_markers=0)
     awg2 = DummyAWG(num_channels=0, num_markers=1)
     setup.set_channel('A', PlaybackChannel(awg1, 0))
     setup.set_channel('B', PlaybackChannel(awg1, 1))
     setup.set_channel('M1', MarkerChannel(awg2, 0))
     expected = {awg1, awg2}
     self.assertEqual(expected, setup.known_awgs)
Exemplo n.º 9
0
def add_to_hardware_setup(hardware_setup: HardwareSetup, serial, name='ZI'):
    hdawg = HDAWGRepresentation(serial, 'USB')

    channel_pairs = []
    for pair_name in ('AB', 'CD', 'EF', 'GH'):
        channel_pair = getattr(hdawg, 'channel_pair_%s' % pair_name)

        for ch_i, ch_name in enumerate(pair_name):
            playback_name = '{name}_{ch_name}'.format(name=name,
                                                      ch_name=ch_name)
            hardware_setup.set_channel(playback_name,
                                       PlaybackChannel(channel_pair, ch_i))
            hardware_setup.set_channel(playback_name + '_MARKER_FRONT',
                                       MarkerChannel(channel_pair, 2 * ch_i))
            hardware_setup.set_channel(
                playback_name + '_MARKER_BACK',
                MarkerChannel(channel_pair, 2 * ch_i + 1))

    return hdawg, channel_pairs
Exemplo n.º 10
0
    def test_remove_program(self):
        wf_1 = DummyWaveform(duration=1.1, defined_channels={'A', 'B'})
        wf_2 = DummyWaveform(duration=1.1, defined_channels={'A', 'C'})

        block_1 = InstructionBlock()
        block_2 = InstructionBlock()

        block_1.add_instruction_meas([('m1', 0., 1.)])
        block_1.add_instruction_exec(wf_1)

        block_2.add_instruction_meas([('m2', 0., 1.)])
        block_2.add_instruction_exec(wf_2)

        awg1 = DummyAWG()
        awg2 = DummyAWG()
        awg3 = DummyAWG()

        dac1 = DummyDAC()
        dac2 = DummyDAC()

        setup = HardwareSetup()

        setup.set_channel('A', PlaybackChannel(awg1, 0))
        setup.set_channel('B', MarkerChannel(awg2, 0))
        setup.set_channel('C', MarkerChannel(awg3, 0))

        setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1'))
        setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2'))

        setup.register_program('test_1', block_1)

        setup.register_program('test_2', block_2)

        setup.arm_program('test_1')

        setup.remove_program('test_1')

        self.assertEqual(setup.registered_programs.keys(), {'test_2'})

        self.assertIsNone(awg1._armed)
        self.assertIsNone(awg2._armed)
Exemplo n.º 11
0
    def test_eq_mark_mark(self):
        self.assertEqual(MarkerChannel(self.awg1, 0),
                         MarkerChannel(self.awg1, 0))

        self.assertNotEqual(MarkerChannel(self.awg1, 0),
                            MarkerChannel(self.awg1, 1))
        self.assertNotEqual(MarkerChannel(self.awg1, 0),
                            MarkerChannel(self.awg2, 0))
Exemplo n.º 12
0
    def test_register_program_exceptions(self):
        setup = HardwareSetup()

        loop, *rest = self.get_test_loops()

        with self.assertRaises(TypeError):
            setup.register_program('p1', loop, 4)

        with self.assertRaises(KeyError):
            setup.register_program('p1', loop, lambda: None)

        awg = DummyAWG(num_channels=2, num_markers=5)

        setup.set_channel('A', PlaybackChannel(awg, 0, lambda x: x))
        setup.set_channel('B', MarkerChannel(awg, 1))

        with self.assertRaises(KeyError):
            setup.register_program('p1', loop, lambda: None)
Exemplo n.º 13
0
    def test_eq_play_mark(self):
        self.assertNotEqual(MarkerChannel(self.awg1, 0),
                            PlaybackChannel(self.awg1, 0))
        self.assertNotEqual(PlaybackChannel(self.awg1, 0),
                            MarkerChannel(self.awg1, 0))
        self.assertNotEqual(PlaybackChannel(self.awg1, 0, lambda x: 0),
                            MarkerChannel(self.awg1, 0))
        self.assertNotEqual(MarkerChannel(self.awg1, 0),
                            PlaybackChannel(self.awg1, 0, lambda x: 0))

        self.assertNotEqual(MarkerChannel(self.awg1, 0),
                            PlaybackChannel(self.awg1, 1))
        self.assertNotEqual(PlaybackChannel(self.awg1, 0),
                            MarkerChannel(self.awg2, 0))
Exemplo n.º 14
0
    def test_register_program_exceptions(self):
        setup = HardwareSetup()

        wfg = WaveformGenerator(num_channels=2,
                                duration_generator=itertools.repeat(1))
        block = get_two_chan_test_block(wfg)

        with self.assertRaises(TypeError):
            setup.register_program('p1', block, 4)

        with self.assertRaises(KeyError):
            setup.register_program('p1', block, lambda: None)

        awg = DummyAWG(num_channels=2, num_markers=5)

        setup.set_channel('A', PlaybackChannel(awg, 0, lambda x: x))
        setup.set_channel('B', MarkerChannel(awg, 1))

        with self.assertRaises(ValueError):
            setup.register_program('p1', block, lambda: None)
Exemplo n.º 15
0
    def test_clear_programs(self) -> None:
        setup = HardwareSetup()
        awg1 = DummyAWG(num_channels=2, num_markers=0)
        awg2 = DummyAWG(num_channels=1, num_markers=1)
        dac1 = DummyDAC()
        dac2 = DummyDAC()
        setup.set_channel('A', PlaybackChannel(awg1, 0))
        setup.set_channel('B', PlaybackChannel(awg1, 1))
        setup.set_channel('C', PlaybackChannel(awg2, 0))
        setup.set_channel('M1', MarkerChannel(awg2, 0))

        wf1 = DummyWaveform(duration=1.1, defined_channels={'C'})
        wf2 = DummyWaveform(duration=7.2, defined_channels={'A'})
        wf3 = DummyWaveform(duration=3.7, defined_channels={'B', 'C'})

        setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1'))
        setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2'))

        block1 = InstructionBlock()
        block1.add_instruction_exec(wf1)

        block2 = InstructionBlock()
        block2.add_instruction_meas([('m1', 0., 1.)])
        block2.add_instruction_exec(wf2)

        block3 = InstructionBlock()
        block3.add_instruction_meas([('m2', 2., 3.)])
        block3.add_instruction_exec(wf3)

        setup.register_program('prog1', block1)
        setup.register_program('prog2', block2)
        setup.register_program('prog3', block3)

        self.assertTrue(setup.registered_programs)

        setup.clear_programs()

        self.assertFalse(setup.registered_programs)
Exemplo n.º 16
0
    def test_register_program(self):
        awg1 = DummyAWG()
        awg2 = DummyAWG(num_channels=2, num_markers=5)

        dac = DummyDAC()

        setup = HardwareSetup()

        wfg = WaveformGenerator(num_channels=2,
                                duration_generator=itertools.repeat(1))
        block = get_two_chan_test_block(wfg)
        block._InstructionBlock__instruction_list[:0] = (MEASInstruction([
            ('m1', 0.1, 0.2)
        ]), )

        class ProgStart:
            def __init__(self):
                self.was_started = False

            def __call__(self):
                self.was_started = True

        program_started = ProgStart()

        trafo1 = lambda x: x

        setup.set_channel('A', PlaybackChannel(awg1, 0, trafo1))
        setup.set_channel('B', MarkerChannel(awg2, 1))

        setup.set_measurement('m1', MeasurementMask(dac, 'DAC'))

        setup.register_program('p1', block, program_started)

        self.assertEqual(tuple(setup.registered_programs.keys()), ('p1', ))
        self.assertEqual(setup.registered_programs['p1'].run_callback,
                         program_started)
        self.assertEqual(setup.registered_programs['p1'].awgs_to_upload_to,
                         {awg1, awg2})

        self.assertFalse(program_started.was_started)

        self.assertEqual(len(awg1._programs), 1)
        self.assertEqual(len(awg2._programs), 1)

        _, channels, markers, trafos = awg1._programs['p1']
        self.assertEqual(channels, ('A', ))
        self.assertEqual(markers, (None, ))
        self.assertEqual(trafos, (trafo1, ))

        _, channels, markers, trafos = awg2._programs['p1']
        self.assertEqual(channels, (None, None))
        self.assertEqual(markers, (None, 'B', None, None, None))

        self.assertEqual(awg1._armed, None)
        self.assertEqual(awg2._armed, None)

        expected_measurement_windows = {
            'p1': {
                'DAC': (np.array([0.1, 0.1]), np.array([0.2, 0.2]))
            }
        }
        np.testing.assert_equal(dac._measurement_windows,
                                expected_measurement_windows)
Exemplo n.º 17
0
    def test_all(self):
        from qupulse.hardware.feature_awg.tabor import TaborChannelTuple, TaborDevice
        #import warnings
        tawg = TaborDevice(r'USB0::0x168C::0x2184::0000216488::INSTR')
        tchannelpair = TaborChannelTuple(tawg, (1, 2), 'TABOR_AB')
        tawg.paranoia_level = 2

        #warnings.simplefilter('error', Warning)

        from qupulse.hardware.setup import HardwareSetup, PlaybackChannel, MarkerChannel
        hardware_setup = HardwareSetup()

        hardware_setup.set_channel('TABOR_A', PlaybackChannel(tchannelpair, 0))
        hardware_setup.set_channel('TABOR_B', PlaybackChannel(tchannelpair, 1))
        hardware_setup.set_channel('TABOR_A_MARKER',
                                   MarkerChannel(tchannelpair, 0))
        hardware_setup.set_channel('TABOR_B_MARKER',
                                   MarkerChannel(tchannelpair, 1))

        if with_alazar:
            from qupulse.hardware.dacs.alazar import AlazarCard
            import atsaverage.server

            if not atsaverage.server.Server.default_instance.running:
                atsaverage.server.Server.default_instance.start(key=b'guest')

            import atsaverage.core

            alazar = AlazarCard(atsaverage.core.getLocalCard(1, 1))
            alazar.register_mask_for_channel('A', 0)
            alazar.register_mask_for_channel('B', 0)
            alazar.register_mask_for_channel('C', 0)
            alazar.config = get_alazar_config()

            alazar.register_operations('test', get_operations())
            window = get_window(atsaverage.core.getLocalCard(1, 1))
            hardware_setup.register_dac(alazar)

        repeated = get_pulse()

        from qupulse.pulses.sequencing import Sequencer

        sequencer = Sequencer()
        sequencer.push(repeated,
                       parameters=dict(n=1000, min=-0.5, max=0.5, tau=192 * 3),
                       channel_mapping={
                           'out': 'TABOR_A',
                           'trigger': 'TABOR_A_MARKER'
                       },
                       window_mapping=dict(A='A', B='B', C='C'))
        instruction_block = sequencer.build()

        hardware_setup.register_program('test', instruction_block)

        if with_alazar:
            from atsaverage.masks import PeriodicMask
            m = PeriodicMask()
            m.identifier = 'D'
            m.begin = 0
            m.end = 1
            m.period = 1
            m.channel = 0
            alazar._registered_programs['test'].masks.append(m)

        hardware_setup.arm_program('test')

        d = 1
Exemplo n.º 18
0
    def test_exceptions(self):
        with self.assertRaises(ValueError):
            MarkerChannel(self.awg1, 2)

        with self.assertRaises(ValueError):
            PlaybackChannel(self.awg1, 2)
Exemplo n.º 19
0
hardware_setup = HardwareSetup()

if awg_name == 'ZI':
    from qupulse.hardware.awgs.zihdawg import HDAWGRepresentation
    awg = HDAWGRepresentation(awg_address, 'USB')

    channel_pairs = []
    for pair_name in ('AB', 'CD', 'EF', 'GH'):
        channel_pair = getattr(awg, 'channel_pair_%s' % pair_name)

        for ch_i, ch_name in enumerate(pair_name):
            playback_name = '{name}_{ch_name}'.format(name=awg_name, ch_name=ch_name)
            hardware_setup.set_channel(playback_name,
                                       PlaybackChannel(channel_pair, ch_i))
            hardware_setup.set_channel(playback_name + '_MARKER_FRONT', MarkerChannel(channel_pair, 2 * ch_i))
            hardware_setup.set_channel(playback_name + '_MARKER_BACK', MarkerChannel(channel_pair, 2 * ch_i + 1))
    awg_channel = awg.channel_pair_AB

elif awg_name == 'TABOR':
    from qupulse.hardware.awgs.tabor import TaborAWGRepresentation
    awg = TaborAWGRepresentation(awg_address, reset=True)

    channel_pairs = []
    for pair_name in ('AB', 'CD'):
        channel_pair = getattr(awg, 'channel_pair_%s' % pair_name)
        channel_pairs.append(channel_pair)

        for ch_i, ch_name in enumerate(pair_name):
            playback_name = '{name}_{ch_name}'.format(name=awg_name, ch_name=ch_name)
            hardware_setup.set_channel(playback_name, PlaybackChannel(channel_pair, ch_i))
Exemplo n.º 20
0
def exec_test():
    import time
    import numpy as np

    t = []
    names = []

    def tic(name):
        t.append(time.time())
        names.append(name)

    from qupulse.hardware.awgs.tabor import TaborChannelPair, TaborAWGRepresentation
    tawg = TaborAWGRepresentation(r'USB0::0x168C::0x2184::0000216488::INSTR', reset=True)

    tchannelpair = TaborChannelPair(tawg, (1, 2), 'TABOR_AB')
    tawg.paranoia_level = 2

    # warnings.simplefilter('error', Warning)

    from qupulse.hardware.setup import HardwareSetup, PlaybackChannel, MarkerChannel
    hardware_setup = HardwareSetup()

    hardware_setup.set_channel('TABOR_A', PlaybackChannel(tchannelpair, 0))
    hardware_setup.set_channel('TABOR_B', PlaybackChannel(tchannelpair, 1))
    hardware_setup.set_channel('TABOR_A_MARKER', MarkerChannel(tchannelpair, 0))
    hardware_setup.set_channel('TABOR_B_MARKER', MarkerChannel(tchannelpair, 1))

    if with_alazar:
        from qupulse.hardware.dacs.alazar import AlazarCard
        import atsaverage.server

        if not atsaverage.server.Server.default_instance.running:
            atsaverage.server.Server.default_instance.start(key=b'guest')

        import atsaverage.core

        alazar = AlazarCard(atsaverage.core.getLocalCard(1, 1))
        alazar.register_mask_for_channel('A', 0)
        alazar.config = get_alazar_config()

        alazar.register_operations('test', get_operations())

        window = get_window(atsaverage.core.getLocalCard(1, 1))

        hardware_setup.register_dac(alazar)

    repeated = get_pulse()

    from qupulse.pulses.sequencing import Sequencer

    tic('init')
    sequencer = Sequencer()
    sequencer.push(repeated,
                   parameters=dict(n=10000, tau=1920, U=0.5),
                   channel_mapping={'out': 'TABOR_A', 'trigger': 'TABOR_A_MARKER'},
                   window_mapping=dict(A='A'))
    instruction_block = sequencer.build()

    tic('sequence')

    hardware_setup.register_program('test', instruction_block)

    tic('register')

    if with_alazar:
        from atsaverage.masks import PeriodicMask
        m = PeriodicMask()
        m.identifier = 'D'
        m.begin = 0
        m.end = 1
        m.period = 1
        m.channel = 0
        alazar._registered_programs['test'].masks.append(m)

    tic('per_mask')

    hardware_setup.arm_program('test')

    tic('arm')

    for d, name in zip(np.diff(np.asarray(t)), names[1:]):
        print(name, d)

    d = 1
Exemplo n.º 21
0
    def test_register_program(self):
        awg1 = DummyAWG()
        awg2 = DummyAWG(num_channels=2, num_markers=5)

        dac = DummyDAC()

        setup = HardwareSetup()

        loop, *rest = self.get_test_loops()

        class ProgStart:
            def __init__(self):
                self.was_started = False

            def __call__(self):
                self.was_started = True

        program_started = ProgStart()

        trafo1 = lambda x: x

        setup.set_channel('A', PlaybackChannel(awg1, 0, trafo1))
        setup.set_channel('B', MarkerChannel(awg2, 1))

        setup.set_measurement('m1', MeasurementMask(dac, 'DAC'))

        setup.register_program('p1', loop, program_started)

        self.assertEqual(tuple(setup.registered_programs.keys()), ('p1', ))
        self.assertEqual(setup.registered_programs['p1'].run_callback,
                         program_started)
        self.assertEqual(setup.registered_programs['p1'].awgs_to_upload_to,
                         {awg1, awg2})

        self.assertFalse(program_started.was_started)

        self.assertEqual(len(awg1._programs), 1)
        self.assertEqual(len(awg2._programs), 1)

        _, channels, markers, trafos = awg1._programs['p1']
        self.assertEqual(channels, ('A', ))
        self.assertEqual(markers, (None, ))
        self.assertEqual(trafos, (trafo1, ))

        _, channels, markers, trafos = awg2._programs['p1']
        self.assertEqual(channels, (None, None))
        self.assertEqual(markers, (None, 'B', None, None, None))

        self.assertEqual(awg1._armed, None)
        self.assertEqual(awg2._armed, None)

        expected_measurement_windows = {
            'p1': {
                'DAC': (np.array([
                    0,
                ]), np.array([
                    1,
                ]))
            }
        }
        np.testing.assert_equal(dac._measurement_windows,
                                expected_measurement_windows)