def test_awg5014_context_view(exopy_qtbot):
    """Test displaying the context view.

    """
    root = RootSequence()
    context = AWG5014Context(sequence_name='Test')
    root.context = context
    show_and_close_widget(exopy_qtbot,
                          AWG5014ContextView(context=context, sequence=root))
Esempio n. 2
0
def test_build_from_config3(template_sequence, template_dependencies):
    """Test rebuilding a sequence including twice the same template sequence

    """
    conf = {'template_id': template_sequence, 'name': 'Template',
            'template_vars': "{'b': '19'}"}
    seq = TemplateSequence.build_from_config(conf, template_dependencies)
    seq.context.channel_mapping = {'A': 'Ch1_L', 'B': 'Ch2_L',
                                   'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A'}

    conf = {'template_id': 'test', 'name': 'Template',
            'template_vars': "{'b': '12'}"}
    seq2 = TemplateSequence.build_from_config(conf, template_dependencies)
    seq2.context.channel_mapping = {'A': 'Ch1_L', 'B': 'Ch2_L',
                                    'Ch1': 'Ch1_A', 'Ch2': 'Ch2_A'}

    root = RootSequence()
    context = DummyContext(sampling=0.5)
    root.context = context
    root.add_child_item(0, seq)
    root.add_child_item(0, seq2)
    pref = root.preferences_from_members()

    new = RootSequence.build_from_config(pref, template_dependencies)
    assert new.items[0].index == 1

    seq = new.items[0]
    assert seq.name == 'Template'
    assert seq.template_id == template_sequence
    assert seq.template_vars == dict(b='19')
    assert seq.local_vars == dict(a='1.5')
    assert len(seq.items) == 4
    assert seq.items[3].index == 5
    assert seq.docs == 'Basic user comment\nff'

    context = seq.context
    assert context.template == seq
    assert context.logical_channels == ['A', 'B']
    assert context.analogical_channel == ['Ch1', 'Ch2']
    assert context.channel_mapping == {'A': 'Ch1_L', 'B': 'Ch2_L',
                                       'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A'}

    assert new.items[1].index == 2

    seq = new.items[1]
    assert seq.name == 'Template'
    assert seq.template_id == 'test'
    assert seq.template_vars == dict(b='12')
    assert seq.local_vars == dict(a='1.5')
    assert len(seq.items) == 4
    assert seq.items[3].index == 5
    assert seq.docs == 'Basic user comment\nff'

    context = seq.context
    assert context.template == seq
    assert context.logical_channels == ['A', 'B']
    assert context.analogical_channels == ['Ch1', 'Ch2']
    assert context.channel_mapping == {'A': 'Ch1_L', 'B': 'Ch2_L',
                                       'Ch1': 'Ch1_A', 'Ch2': 'Ch2_A'}
Esempio n. 3
0
def test_pulse_view(workbench, exopy_qtbot, dialog_sleep):
    """Test the view of the Pulse class.

    """
    from exopy.testing.util import show_widget
    with enaml.imports():
        from exopy_pulses.pulses.sequences.views.base_sequences_views\
            import RootSequenceView

    pulse = Pulse(root=RootSequence(context=DummyContext()))
    pulse.kind = 'Analogical'
    root = pulse.root
    root.add_child_item(0, pulse)
    core = workbench.get_plugin('enaml.workbench.core')
    root_view = RootSequenceView(item=root, core=core)
    pulse_view = root_view.view_for(pulse)
    show_widget(exopy_qtbot, root_view)
    exopy_qtbot.wait(dialog_sleep)

    # Test selecting a slope shape
    shape_select = pulse_view.widgets()[-1].widgets()[-1]
    shape_select.selected = 'exopy_pulses.SlopeShape'
    exopy_qtbot.wait(10 + dialog_sleep)

    shape_view = pulse_view.widgets()[-1]
    sv_widgets = shape_view.split_items()[0].split_widget().widgets()

    for mode in ('Start/Stop', 'Start/Slope', 'Slope/Stop'):
        sv_widgets[1].selected = mode

        def assert_mode():
            assert sv_widgets[2].text == mode.split('/')[0]
            assert sv_widgets[4].text == mode.split('/')[1]

        exopy_qtbot.wait_until(assert_mode)
Esempio n. 4
0
def root_with_template(template_sequence, template_dependencies):
    """Build a root using the template sequence.

    """
    root = RootSequence()
    root.context = DummyContext(sampling=0.5)

    conf = {'template_id': template_sequence, 'name': 'Template',
            'template_vars': "{'b': '19'}"}
    seq = TemplateSequence.build_from_config(conf, template_dependencies)
    seq.context.channel_mapping = {'A': 'Ch1_L', 'B': 'Ch2_L',
                                   'Ch1': 'Ch2_A', 'Ch2': 'Ch1_A'}
    seq.def_1 = '1.0'
    seq.def_2 = '20.0'

    root.add_child_item(0, seq)
    return root
Esempio n. 5
0
def test_traverse_sequence():
    """Test traversing a pulse sequence.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    root.external_vars = OrderedDict({'a': 1.5})

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{2_stop} + 0.5',
                   def_2='10',
                   kind='Analogical',
                   shape=SquareShape())
    pulse4 = Pulse(def_1='{2_stop} + 0.5',
                   def_2='10',
                   kind='Analogical',
                   shape=SquareShape())
    seq = BaseSequence()
    add_children(root, [pulse1, pulse2, pulse3, seq])
    add_children(seq, [pulse4])

    items = root.traverse()
    assert len(list(items)) == 11

    assert list(
        root.traverse(0)) == [root, pulse1, pulse2, pulse3, seq, context]
Esempio n. 6
0
def test_get_accessible_vars():
    """Test getting the accessible vars of a sequence.

    """
    root = RootSequence(external_vars=OrderedDict({'a': 1}),
                        local_vars=OrderedDict({'a2': '5'}),
                        time_constrained=True)
    context = TestContext()
    root.context = context
    sequence1 = BaseSequence(local_vars=OrderedDict({'b': '1'}))
    sequence2 = BaseSequence(local_vars=OrderedDict({'c': '2'}))
    pulse = Pulse()

    sequence2.add_child_item(0, pulse)
    sequence1.add_child_item(0, sequence2)
    root.add_child_item(0, sequence1)

    variables = [
        'sequence_end', 'a', 'a2', '3_start', '3_stop', '3_duration', 'b', 'c'
    ]
    lv = sequence2.get_accessible_vars()
    for v in variables:
        assert v in lv

    variables.pop()
    lv = sequence1.get_accessible_vars()
    for v in variables:
        assert v in lv

    variables.pop()
    lv = root.get_accessible_vars()
    for v in variables:
        assert v in lv
Esempio n. 7
0
def test_collect_dependencies(workbench):
    """Test collecting build dependencies.

    """
    from exopy_pulses.pulses.sequences.base_sequences import RootSequence
    root = RootSequence(context=TestContext())

    pulse1 = Pulse(def_1='1.0', def_2='{7_start} - 1.0')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='{6_start} + 1.0')
    pulse3 = Pulse(def_1='{3_stop} + 0.5', def_2='10.0')
    pulse4 = Pulse(def_1='2.0', def_2='0.5', def_mode='Start/Duration')
    pulse5 = Pulse(def_1='{1_stop}', def_2='0.5', def_mode='Start/Duration')
    pulse5.shape = SquareShape(amplitude='0.5')
    pulse5.kind = 'Analogical'

    pulse5.modulation.frequency = '1.0**'
    pulse5.modulation.phase = '1.0'
    pulse5.modulation.activated = True

    sequence2 = BaseSequence()
    sequence2.add_child_item(0, pulse3)
    sequence1 = BaseSequence()
    sequence1.add_child_item(0, pulse2)
    sequence1.add_child_item(1, sequence2)
    sequence1.add_child_item(2, pulse4)

    root.add_child_item(0, pulse1)
    root.add_child_item(1, sequence1)
    root.add_child_item(2, pulse5)

    core = workbench.get_plugin(u'enaml.workbench.core')
    com = 'exopy.app.dependencies.analyse'
    dep = core.invoke_command(com, {'obj': root, 'dependencies': 'build'})
    assert not dep.errors

    com = 'exopy.app.dependencies.collect'
    dep = core.invoke_command(com, {
        'kind': 'build',
        'dependencies': dep.dependencies
    })

    assert not dep.errors
    assert 'exopy.pulses.item' in dep.dependencies
    assert 'exopy.pulses.context' in dep.dependencies
    assert 'exopy.pulses.shape' in dep.dependencies
    assert 'exopy.pulses.modulation' in dep.dependencies
Esempio n. 8
0
def test_root_sequence_view(exopy_qtbot, workbench):
    """Test the root sequence view.

    """
    core = workbench.get_plugin('enaml.workbench.core')
    view = RootSequenceView(item=RootSequence(), core=core)

    show_widget(exopy_qtbot, view)
    seq = BaseSequence()
    view.item.add_child_item(0, seq)
    assert seq in view._cache
    view.item.remove_child_item(0)
    assert seq not in view._cache

    but = view.widgets()[-1].pages()[1].page_widget().widgets()[0]
    with handle_dialog(exopy_qtbot, 'reject'):
        but.clicked = True
def sequence():
    """Create a sequence.

    """
    root = RootSequence()
    context = TestContext(sampling=0.5)
    root.context = context

    root.external_vars = OrderedDict({'a': None})
    root.local_vars = OrderedDict({'b': '2*{a}'})

    pulse1 = Pulse(def_1='1.0', def_2='{a}', def_mode=str('Start/Stop'))
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{2_stop} + 0.5', def_2='10 + {b}')
    for i, c in enumerate((pulse1, pulse2, pulse3)):
        root.add_child_item(i, c)

    return root
Esempio n. 10
0
def template_sequence(pulses_plugin):
    """Create a template sequence and make sure the plugin pick it up.

    """
    from exopy_pulses.pulses.pulse import Pulse
    from exopy_pulses.pulses.sequences.base_sequences import (RootSequence,
                                                              BaseSequence)
    from exopy_pulses.pulses.shapes.square_shape import SquareShape
    from exopy_pulses.pulses.contexts.template_context import TemplateContext

    root = RootSequence()
    context = TemplateContext(logical_channels=['A', 'B'],
                              analogical_channels=['Ch1', 'Ch2'],
                              channel_mapping={'A': '', 'B': '', 'Ch1': '',
                                               'Ch2': ''})
    root.context = context
    root.local_vars = OrderedDict({'a': '1.5'})

    pulse1 = Pulse(channel='A', def_1='1.0', def_2='{a}')
    pulse2 = Pulse(channel='B', def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(channel='Ch1', def_1='{2_stop} + 0.5', def_2='{b}',
                   kind='Analogical', shape=SquareShape())
    seq = BaseSequence()
    seq.add_child_item(0, Pulse(channel='Ch2', def_1='{2_stop} + 0.5',
                       def_2='{sequence_end}', kind='Analogical',
                       shape=SquareShape()))
    for i in [pulse1, pulse2, seq,  pulse3][::-1]:
        root.add_child_item(0, i)

    pref = root.preferences_from_members()
    pref['template_vars'] = repr(dict(b=''))
    del pref['item_id']
    del pref['external_vars']
    del pref['time_constrained']

    temp_path = os.path.join(pulses_plugin.templates_folders[0],
                             '__dummy__.temp_pulse.ini')
    save_sequence_prefs(temp_path, pref, 'dummy doc')

    pulses_plugin._refresh_known_template_sequences()

    return '__dummy__'
Esempio n. 11
0
def test_root_handling():
    """Test updating of item when a sequence get/lose the root.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    sequence1 = BaseSequence()
    sequence2 = BaseSequence()
    pulse = Pulse()

    sequence2.add_child_item(0, pulse)
    sequence1.add_child_item(0, sequence2)
    root.add_child_item(0, sequence1)

    assert pulse.root is root and sequence2.root is root
    assert sequence2.has_observers('_last_index')

    root.remove_child_item(0)
    assert pulse.root is None and sequence2.root is None
    assert not sequence2.has_observers('_last_index')
Esempio n. 12
0
def test_sequence_time_constaints_observation():
    """Test observation of time constraint by the root.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    sequence = BaseSequence()
    root.add_child_item(0, sequence)

    assert root.global_vars == []

    sequence.time_constrained = True

    assert (sorted(root.global_vars) == sorted(
        ['1_start', '1_stop', '1_duration']))

    sequence.time_constrained = False

    assert root.global_vars == []

    root.time_constrained = True
    assert root.linkable_vars
Esempio n. 13
0
def test_sequence_indexing2():
    """Test adding, moving, deleting a sequence in a sequence.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context

    pulse1 = Pulse()
    pulse2 = Pulse()
    pulse3 = Pulse()
    pulse4 = Pulse()

    sequence1 = BaseSequence()
    sequence2 = BaseSequence()

    root.add_child_item(0, pulse1)
    root.add_child_item(1, sequence1)
    root.add_child_item(2, pulse2)

    assert sequence1.parent is root
    assert sequence1.root is root

    sequence1.add_child_item(0, sequence2)

    assert sequence2.parent is sequence1
    assert sequence2.root is root
    assert pulse1.index == 1
    assert pulse2.index == 4
    assert (sorted(root.get_accessible_vars()) == sorted(
        ['1_start', '1_stop', '1_duration', '4_start', '4_stop',
         '4_duration']))

    pulse1.index = 200
    sequence2.add_child_item(0, pulse3)

    assert pulse3.parent is sequence2
    assert pulse3.root is root
    assert pulse2.index == 5
    assert pulse3.index == 4
    assert (sorted(root.get_accessible_vars()) == sorted([
        '1_start', '1_stop', '1_duration', '4_start', '4_stop', '4_duration',
        '5_start', '5_stop', '5_duration'
    ]))

    # Check that only the pulse below the modified sequence are updated.
    assert pulse1.index == 200
    pulse1.index = 0

    sequence1.add_child_item(0, pulse4)

    assert pulse4.index == 3
    assert sequence2.index == 4
    assert pulse3.index == 5
    assert pulse2.index == 6
    assert (sorted(root.get_accessible_vars()) == sorted([
        '1_start', '1_stop', '1_duration', '3_start', '3_stop', '3_duration',
        '5_start', '5_stop', '5_duration', '6_start', '6_stop', '6_duration'
    ]))

    sequence1.remove_child_item(1)

    assert sequence2.parent is None
    assert sequence2.index == 0
    assert pulse2.index == 4
    assert (sorted(root.get_accessible_vars()) == sorted([
        '1_start', '1_stop', '1_duration', '3_start', '3_stop', '3_duration',
        '4_start', '4_stop', '4_duration'
    ]))

    sequence1.index = 200
    root2 = RootSequence()
    sequence2.root = root2
    while True:
        sequence2.remove_child_item(0)
        if not sequence2.items:
            break

    # Check the observer was properly removed
    assert sequence1.index == 200
Esempio n. 14
0
def test_sequence_indexing1():
    """Test adding, moving, deleting pulse in a sequence.

    """
    root = RootSequence()
    root.time_constrained = True
    root.sequence_duration = '1.0'
    context = TestContext()
    root.context = context

    pulse1 = Pulse()
    pulse2 = Pulse()
    pulse3 = Pulse()

    root.add_child_item(0, pulse1)
    assert pulse1.index == 1
    assert pulse1.root is root
    assert (sorted(root.get_accessible_vars()) == (sorted(
        ['sequence_end', '1_start', '1_stop', '1_duration'])))

    root.add_child_item(1, pulse2)
    assert pulse1.index == 1
    assert pulse2.index == 2
    assert pulse2.root is root
    assert (sorted(root.get_accessible_vars()) == sorted([
        'sequence_end', '1_start', '1_stop', '1_duration', '2_start', '2_stop',
        '2_duration'
    ]))

    root.move_child_item(0, 1)
    assert pulse1.index == 2
    assert pulse2.index == 1
    assert (sorted(root.get_accessible_vars()) == sorted([
        'sequence_end', '1_start', '1_stop', '1_duration', '2_start', '2_stop',
        '2_duration'
    ]))

    root.move_child_item(0, 1)

    root.add_child_item(2, pulse3)
    assert pulse1.index == 1
    assert pulse2.index == 2
    assert pulse3.index == 3
    assert pulse3.root is root
    assert (sorted(root.get_accessible_vars()) == sorted([
        'sequence_end', '1_start', '1_stop', '1_duration', '2_start', '2_stop',
        '2_duration', '3_start', '3_stop', '3_duration'
    ]))

    root.time_constrained = False
    root.remove_child_item(1)
    assert pulse1.index == 1
    assert pulse2.index == 0
    assert pulse3.index == 2
    assert pulse2.root is None
    assert (sorted(root.get_accessible_vars()) == sorted(
        ['1_start', '1_stop', '1_duration', '2_start', '2_stop',
         '2_duration']))

    root.add_child_item(1, pulse2)
    assert pulse1.index == 1
    assert pulse2.index == 2
    assert pulse3.index == 3
    assert pulse2.root is root
    assert (sorted(root.get_accessible_vars()) == sorted([
        '1_start', '1_stop', '1_duration', '2_start', '2_stop', '2_duration',
        '3_start', '3_stop', '3_duration'
    ]))
Esempio n. 15
0
def root():
    root = RootSequence(context=DummyContext())
    return root
Esempio n. 16
0
def root():
    root = RootSequence(context=TestContext())
    return root
Esempio n. 17
0
def item():
    return Item(root=RootSequence(context=TestContext()))
Esempio n. 18
0
def item():
    return Item(root=RootSequence(context=DummyContext()))
 def setup(self):
     self.root = RootSequence()
     self.context = AWG5014Context(sequence_name='Test')
     self.compile = self.context.compile_and_transfer_sequence
     self.driver = DummyDriver()
     self.root.context = self.context
Esempio n. 20
0
def root():
    root = RootSequence()
    context = TestContext(sampling=0.5)
    root.context = context
    return root
Esempio n. 21
0
def test_build_from_config():
    """Test building a pulse sequence.

    """
    root = RootSequence()
    context = TestContext()
    root.context = context
    root.external_vars = OrderedDict({'a': 1.5})

    pulse1 = Pulse(def_1='1.0', def_2='{a}')
    pulse2 = Pulse(def_1='{a} + 1.0', def_2='3.0')
    pulse3 = Pulse(def_1='{2_stop} + 0.5',
                   def_2='10',
                   kind='Analogical',
                   shape=SquareShape())
    pulse4 = Pulse(def_1='{2_stop} + 0.5',
                   def_2='10',
                   kind='Analogical',
                   shape=SquareShape())
    seq = BaseSequence()
    add_children(root, [pulse1, pulse2, pulse3, seq])
    add_children(seq, [pulse4])

    pref = root.preferences_from_members()
    dependecies = {
        'exopy.pulses.item': {
            'exopy_pulses.BaseSequence': BaseSequence,
            'exopy_pulses.Pulse': Pulse
        },
        'exopy.pulses.shape': {
            'exopy_pulses.SquareShape': SquareShape
        },
        'exopy.pulses.context': {
            'exopy_pulses.TestContext': TestContext
        }
    }

    aux = RootSequence.build_from_config(pref, dependecies)
    assert aux.external_vars == {'a': 1.5}
    assert len(aux.items) == 4
    assert isinstance(aux.context, TestContext)

    pulse1 = aux.items[0]
    assert pulse1.parent
    assert pulse1.def_1 == '1.0'
    assert pulse1.def_2 == '{a}'

    pulse2 = aux.items[1]
    assert pulse2.parent
    assert pulse2.def_1 == '{a} + 1.0'
    assert pulse2.def_2 == '3.0'

    pulse3 = aux.items[2]
    assert pulse3.parent
    assert pulse3.def_1 == '{2_stop} + 0.5'
    assert pulse3.def_2 == '10'
    assert pulse3.kind == 'Analogical'
    assert isinstance(pulse3.shape, SquareShape)

    seq = aux.items[3]
    assert seq.parent
    assert len(seq.items) == 1
class TestAWGContext(object):
    """Test the AWG5014 context capabilities.

    """
    def setup(self):
        self.root = RootSequence()
        self.context = AWG5014Context(sequence_name='Test')
        self.compile = self.context.compile_and_transfer_sequence
        self.driver = DummyDriver()
        self.root.context = self.context

    def test_changing_unit(self):
        time = self.context.sampling_time
        self.context.time_unit = 'ms'
        assert self.context.sampling_time != time

    def test_compiling_A_pulse_not_selecting(self):
        self.context.select_after_transfer = False
        self.context.run_after_transfer = False
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse = Pulse(kind='Analogical',
                      shape=SquareShape(amplitude='1.0'),
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_A')
        self.root.add_child_item(0, pulse)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert sorted(infos) == sorted(self.context.list_sequence_infos())
        assert not self.driver.running
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert self.driver.channels[1].array is None

        sequence = np.zeros(2000, dtype=np.uint8)
        sequence[1::2] = 2**5
        sequence[201:1001:2] += 2**4 + 2**3 + 4 + 2 + 1
        sequence[200:1000:2] += 255
        np.testing.assert_array_equal(self.driver.sequences['Test_Ch1'],
                                      to_bytes(sequence))

    def test_compiling_M1_pulse_selecting_but_not_clearing(self):
        self.context.clear_unused_channels = False
        self.driver.channels[2].array = np.zeros(10)
        self.context.run_after_transfer = False
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse = Pulse(kind='Logical',
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_M1')
        pulse2 = Pulse(kind='Logical',
                       def_1='0.1',
                       def_2='0.1',
                       channel='Ch1_M1')
        self.root.add_child_item(0, pulse)
        self.root.add_child_item(1, pulse2)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert not self.driver.running
        assert self.driver.channels[2].array is not None
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert (self.driver.channels[1].array is
                self.driver.sequences['Test_Ch1'])

        sequence = np.zeros(2000, dtype=np.uint8)
        sequence[1::2] = 2**5
        sequence[201:1001:2] += 2**6
        np.testing.assert_array_equal(self.driver.channels[1].array,
                                      to_bytes(sequence))

    def test_compiling_M2_pulse_selecting_and_clearing(self):
        self.driver.channels[2].array = np.zeros(10)
        self.context.run_after_transfer = False
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse = Pulse(kind='Logical',
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_M2')
        self.root.add_child_item(0, pulse)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert not self.driver.running
        assert self.driver.channels[2].array is None
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert (self.driver.channels[1].array is
                self.driver.sequences['Test_Ch1'])

    def test_compiling_inverted_logical_pulses_and_running(self):
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse = Pulse(kind='Logical',
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_M2')
        self.context.inverted_log_channels = ['Ch1_M1', 'Ch1_M2']
        self.root.add_child_item(0, pulse)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert self.driver.running
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert (self.driver.channels[1].array is
                self.driver.sequences['Test_Ch1'])

        sequence = np.zeros(2000, dtype=np.uint8)
        sequence[1::2] = 2**7 + 2**6 + 2**5
        sequence[201:1001:2] -= 2**7
        np.testing.assert_array_equal(self.driver.channels[1].array,
                                      to_bytes(sequence))

    def test_compiling_variable_length(self):
        pulse = Pulse(kind='Logical',
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_M1')
        self.context.sampling_frequency = 1e8
        self.root.add_child_item(0, pulse)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert self.driver.running
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert (self.driver.channels[1].array is
                self.driver.sequences['Test_Ch1'])

        sequence = np.zeros(100, dtype=np.uint8)
        sequence[1::2] = 2**5
        sequence[21:101:2] += 2**6
        np.testing.assert_array_equal(self.driver.channels[1].array,
                                      to_bytes(sequence))

    def test_too_short_fixed_length(self):
        self.root.time_constrained = True
        self.root.sequence_duration = '0.3'
        pulse = Pulse(kind='Logical',
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_M1')
        self.root.add_child_item(0, pulse)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert not res

    def test_channel_kind_mixing(self):
        pulse = Pulse(kind='Logical',
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_A')
        self.root.add_child_item(0, pulse)

        res, infos, errors = self.compile(self.root, self.driver)
        assert not res

    def test_overlapping_pulses(self):
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse1 = Pulse(kind='Analogical',
                       def_1='0.1',
                       def_2='0.5',
                       channel='Ch1_A',
                       shape=SquareShape(amplitude='1.0'),
                       modulation=Modulation(frequency='2.5',
                                             kind='sin',
                                             activated=True))
        pulse2 = Pulse(kind='Analogical',
                       def_1='0.1',
                       def_2='0.5',
                       channel='Ch1_A',
                       shape=SquareShape(amplitude='1.0'),
                       modulation=Modulation(frequency='2.5',
                                             kind='sin',
                                             phase='Pi',
                                             activated=True))
        self.root.add_child_item(0, pulse1)
        self.root.add_child_item(1, pulse2)

        res, infos, errors = self.compile(self.root, None)
        print(errors)
        assert res
        assert infos['sequence_ch1'] == 'Test_Ch1'

    def test_nearly_overlapping_M2(self):
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse1 = Pulse(kind='Logical',
                       def_1='0.1',
                       def_2='0.5',
                       channel='Ch1_M2')
        pulse2 = Pulse(kind='Logical',
                       def_1='0.5',
                       def_2='0.6',
                       channel='Ch1_M2')
        self.root.add_child_item(0, pulse1)
        self.root.add_child_item(1, pulse2)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert self.driver.running
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert (self.driver.channels[1].array is
                self.driver.sequences['Test_Ch1'])

        sequence = np.zeros(2000, dtype=np.uint8)
        sequence[1::2] = 2**5
        sequence[201:1201:2] += 2**7
        np.testing.assert_array_equal(self.driver.channels[1].array,
                                      to_bytes(sequence))

    def test_overflow_check_A(self):
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse1 = Pulse(kind='Analogical',
                       def_1='0.1',
                       def_2='0.5',
                       channel='Ch1_A',
                       shape=SquareShape(amplitude='1.0'),
                       modulation=Modulation(frequency='2.5',
                                             kind='sin',
                                             activated=True))
        pulse2 = Pulse(kind='Analogical',
                       def_1='0.1',
                       def_2='0.5',
                       channel='Ch1_A',
                       shape=SquareShape(amplitude='1.0'),
                       modulation=Modulation(frequency='2.5',
                                             kind='sin',
                                             activated=True))
        self.root.add_child_item(0, pulse1)
        self.root.add_child_item(1, pulse2)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert not res
        assert 'Ch1_A' in errors

    def test_overflow_check_M1(self):
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse1 = Pulse(kind='Logical',
                       def_1='0.1',
                       def_2='0.5',
                       channel='Ch1_M1')
        pulse2 = Pulse(kind='Logical',
                       def_1='0.1',
                       def_2='0.5',
                       channel='Ch1_M1')
        self.root.add_child_item(0, pulse1)
        self.root.add_child_item(1, pulse2)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert not res
        assert 'Ch1_M1' in errors

    def test_overflow_check_M2(self):
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse1 = Pulse(kind='Logical',
                       def_1='0.1',
                       def_2='0.5',
                       channel='Ch1_M2')
        pulse2 = Pulse(kind='Logical',
                       def_1='0.4',
                       def_2='0.6',
                       channel='Ch1_M2')
        self.root.add_child_item(0, pulse1)
        self.root.add_child_item(1, pulse2)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert not res
        assert 'Ch1_M2' in errors

    def test_compiling_sequence1(self):
        self.root.external_vars = OrderedDict({'a': 1.5})

        pulse1 = Pulse(channel='Ch1_M1', def_1='1.0', def_2='{7_start} - 1.0')
        pulse2 = Pulse(channel='Ch1_M2',
                       def_1='{a} + 1.0',
                       def_2='{6_start} + 1.0')
        pulse3 = Pulse(channel='Ch2_M1', def_1='{3_stop} + 0.5', def_2='10.0')
        pulse4 = Pulse(channel='Ch2_M2',
                       def_1='2.0',
                       def_2='0.5',
                       def_mode='Start/Duration')
        pulse5 = Pulse(channel='Ch3_M1',
                       def_1='3.0',
                       def_2='0.5',
                       def_mode='Start/Duration')

        sequence2 = BaseSequence()
        sequence2.add_child_item(0, pulse3)
        sequence1 = BaseSequence()
        for i, item in enumerate([pulse2, sequence2, pulse4]):
            sequence1.add_child_item(i, item)

        for i, item in enumerate([pulse1, sequence1, pulse5]):
            self.root.add_child_item(i, item)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert self.driver.running
        for i in (1, 2, 3):
            assert 'Test_Ch%d' % i in self.driver.sequences
        assert len(self.driver.sequences) == 3
        for i in (1, 2, 3):
            assert (self.driver.channels[i].array is
                    self.driver.sequences['Test_Ch%d' % i])
Esempio n. 23
0
def pulse():
    return Pulse(root=RootSequence(context=DummyContext()))
Esempio n. 24
0
def pulse():
    return Pulse(root=RootSequence(context=TestContext()))