Exemplo n.º 1
0
    def test_rm_channel(self):
        awg1 = DummyAWG()
        awg2 = DummyAWG(num_channels=2)

        setup = HardwareSetup()

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

        with self.assertRaises(KeyError):
            setup.rm_channel('b')
        setup.rm_channel('B')

        self.assertEqual(setup.registered_channels(),
                         dict(A={PlaybackChannel(awg1, 0)}))
Exemplo n.º 2
0
def exec_test():
    import time
    import numpy as np

    t = []
    names = []

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

    from qctoolkit.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 qctoolkit.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 qctoolkit.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 qctoolkit.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.º 3
0
    def test_set_channel(self):
        awg1 = DummyAWG()
        awg2 = DummyAWG(num_channels=4)

        setup = HardwareSetup()

        setup.set_channel('A', PlaybackChannel(awg1, 0))
        setup.set_channel('B', PlaybackChannel(awg2, 0))
        self.assertEqual(
            setup.registered_channels(),
            dict(A={PlaybackChannel(awg1, 0)}, B={PlaybackChannel(awg2, 0)}))

        with self.assertRaises(ValueError):
            setup.set_channel('C', PlaybackChannel(awg1, 0))

        with self.assertWarns(DeprecationWarning):
            setup.set_channel('A', PlaybackChannel(awg2, 1), True)

        self.assertEqual(
            setup.registered_channels(),
            dict(A={PlaybackChannel(awg2, 1),
                    PlaybackChannel(awg1, 0)},
                 B={PlaybackChannel(awg2, 0)}))

        setup.set_channel('A',
                          {PlaybackChannel(awg2, 3),
                           PlaybackChannel(awg2, 2)})
        self.assertEqual(
            setup.registered_channels(),
            dict(A={PlaybackChannel(awg2, 3),
                    PlaybackChannel(awg2, 2)},
                 B={PlaybackChannel(awg2, 0)}))
Exemplo n.º 4
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.º 5
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.º 6
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.º 7
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.º 8
0
    def test_all(self):
        from qctoolkit.hardware.awgs.tabor import TaborChannelPair, TaborAWGRepresentation
        #import warnings
        tawg = TaborAWGRepresentation(r'USB0::0x168C::0x2184::0000216488::INSTR')
        tchannelpair = TaborChannelPair(tawg, (1, 2), 'TABOR_AB')
        tawg.paranoia_level = 2

        #warnings.simplefilter('error', Warning)

        from qctoolkit.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 qctoolkit.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 qctoolkit.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