Пример #1
0
    def test_quick_add_unsorted_pulses(self):
        pulses = []

        t = 0
        for k in range(30):
            duration = np.round(np.random.rand(), 11)
            pulses.append(DCPulse('DC', t_start=t, duration=duration))
            t += duration
        random.shuffle(pulses)

        pulse_sequence = PulseSequence()
        added_pulses = pulse_sequence.quick_add(*pulses)

        for pulse in added_pulses:
            self.assertEqual(pulse.id, None)

        pulse_sequence.finish_quick_add()

        t = 0
        for k, pulse in enumerate(pulse_sequence.pulses):
            self.assertEqual(pulse.id, k)
            self.assertAlmostEqual(pulse.t_start, t)
            t += pulse.duration

        self.assertAlmostEqual(pulse_sequence.duration, t)
Пример #2
0
    def test_sort(self):
        pulse_sequence = PulseSequence()
        pulse1 = DCPulse(name='dc1', amplitude=1.5, duration=10, t_start=1)
        pulse2 = DCPulse(name='dc2', amplitude=1.5, duration=10, t_start=0)
        pulse_sequence.add(pulse1, pulse2)

        self.assertEqual(pulse_sequence[0], pulse2)
Пример #3
0
    def test_quick_add_pulse_id(self):
        pulses = [
            DCPulse('DC', duration=10),
            DCPulse('DC', duration=10),
            DCPulse('DC2', duration=10)
        ]
        pulse_sequence = PulseSequence()
        added_pulses = pulse_sequence.quick_add(*pulses)
        pulse_sequence.finish_quick_add()

        self.assertNotEqual(pulses, added_pulses)
        self.assertEqual(pulses[0].t_start, None)
        self.assertEqual(added_pulses[0].t_start, 0)
        self.assertEqual(added_pulses[1].t_start, 10)
        self.assertEqual(added_pulses[2].t_start, 20)

        self.assertEqual(pulses[0].full_name, 'DC')
        self.assertEqual(pulses[1].full_name, 'DC')
        self.assertEqual(pulses[2].full_name, 'DC2')

        self.assertEqual(added_pulses[0].full_name, 'DC[0]')
        self.assertEqual(added_pulses[1].full_name, 'DC[1]')
        self.assertEqual(added_pulses[2].full_name, 'DC2')

        self.assertEqual(pulse_sequence.duration, 30)
Пример #4
0
    def test_add_remove_pulse(self):
        pulse_sequence = PulseSequence()
        self.assertFalse(pulse_sequence)

        pulse = DCPulse(name='dc', amplitude=1.5, duration=10, t_start=0)
        pulse_sequence.add(pulse)
        self.assertIn(pulse, pulse_sequence)
        self.assertTrue(pulse_sequence)
Пример #5
0
 def create_large_pulse_sequence(self):
     pulse_sequence = PulseSequence()
     duration = 10e-3
     for k in range(2):
         pulse_sequence.add(DCRampPulse('DC_ramp', amplitude_start=0,
                                        amplitude_stop=1,
                                        t_start=k*duration,
                                        duration=duration))
     return pulse_sequence
Пример #6
0
    def test_remove_pulse_by_name(self):
        # Remove pulses using .remove
        pulse_sequence = PulseSequence()
        pulse = DCPulse(name='dc', amplitude=1.5, duration=10, t_start=0)
        self.assertEqual(pulse.name, 'dc')
        self.assertEqual(pulse.full_name, 'dc')
        added_pulse, = pulse_sequence.add(pulse)
        self.assertEqual(added_pulse.full_name, 'dc')

        pulse_sequence.remove('dc')
        self.assertEqual(len(pulse_sequence.pulses), 0)
Пример #7
0
    def test_quick_add_pulses(self):
        pulses = [DCPulse(duration=10), DCPulse(duration=10)]
        pulse_sequence = PulseSequence()
        added_pulses = pulse_sequence.quick_add(*pulses)

        self.assertNotEqual(pulses, added_pulses)
        self.assertEqual(pulses[0].t_start, None)
        self.assertEqual(added_pulses[0].t_start, 0)
        self.assertEqual(added_pulses[1].t_start, 10)

        self.assertEqual(pulse_sequence.duration, 20)
Пример #8
0
 def test_add_disabled_pulse(self):
     pulse_sequence = PulseSequence()
     pulses = []
     for pulse in [
             Pulse(name='p1', duration=1),
             Pulse(name='p2', duration=1, enabled=False),
             Pulse(name='p3', duration=1)
     ]:
         pulses += [pulse_sequence.add(pulse)[0]]
     self.assertEqual(pulse_sequence.enabled_pulses, [pulses[0], pulses[2]])
     self.assertEqual(pulse_sequence.disabled_pulses, [pulses[1]])
Пример #9
0
    def test_copy_pulse_sequence_equality(self):
        pulse_sequence = PulseSequence()
        pulse_sequence_copy = copy(pulse_sequence)
        self.assertEqual(pulse_sequence, pulse_sequence_copy)

        pulse = DCPulse('read', duration=1, amplitude=2)
        pulse_sequence.add(pulse)
        self.assertNotEqual(pulse_sequence, pulse_sequence_copy)
        pulse_sequence_copy_2 = copy(pulse_sequence)
        self.assertEqual(pulse_sequence, pulse_sequence_copy_2)

        self.assertEqual(pulse_sequence_copy_2, PulseSequence([pulse]))
Пример #10
0
    def test_add_same_name_pulses_sequentially(self):
        pulse_sequence = PulseSequence()
        p = Pulse('DC', duration=5)
        added_pulse, = pulse_sequence.add(p)
        self.assertEqual(added_pulse.id, None)
        self.assertEqual(added_pulse.full_name, 'DC')

        added_pulse2, = pulse_sequence.add(p)
        self.assertEqual(added_pulse.id, 0)
        self.assertEqual(added_pulse.full_name, 'DC[0]')
        self.assertEqual(added_pulse2.id, 1)
        self.assertEqual(added_pulse2.full_name, 'DC[1]')
Пример #11
0
    def test_get_pulses_connection_label(self):
        pulse_sequence = PulseSequence()
        pulse1, pulse2 = pulse_sequence.add(
            Pulse('pulse1', duration=1, connection_label='connection'),
            Pulse('pulse1', duration=2))
        retrieved_pulse = pulse_sequence.get_pulse(
            connection_label='connection')
        self.assertEqual(retrieved_pulse, pulse1)

        retrieved_pulse = pulse_sequence.get_pulse(
            name='pulse1', connection_label='connection')
        self.assertEqual(retrieved_pulse, pulse1)
Пример #12
0
    def test_transition_voltages(self):
        # To test transitions, pulses must be on the same connection
        channel_out = Channel('arbstudio', 'ch1', id=1, output=True)
        channel_in = Channel('device', 'input', id=1, output=True)
        c1 = SingleConnection(output_instrument='arbstudio',
                              output_channel=channel_out,
                              input_instrument='device',
                              input_channel=channel_in)
        pulses = [
            DCPulse(name='dc1',
                    amplitude=0,
                    duration=5,
                    t_start=0,
                    connection=c1),
            DCPulse(name='dc2',
                    amplitude=1,
                    duration=10,
                    t_start=5,
                    connection=c1),
            DCPulse(name='dc3',
                    amplitude=2,
                    duration=8,
                    t_start=15,
                    connection=c1),
            DCPulse(name='dc4',
                    amplitude=3,
                    duration=7,
                    t_start=12,
                    connection=c1)
        ]

        pulse_sequence = PulseSequence(pulses)

        self.assertRaises(TypeError, pulse_sequence.get_transition_voltages)
        self.assertRaises(TypeError,
                          pulse_sequence.get_transition_voltages,
                          connection=c1)
        self.assertRaises(TypeError,
                          pulse_sequence.get_transition_voltages,
                          t=5)

        transition_voltage = pulse_sequence.get_transition_voltages(
            pulse=pulses[1])
        self.assertTupleEqual(transition_voltage, (0, 1))

        transition_voltage = pulse_sequence.get_transition_voltages(
            connection=c1, t=5)
        self.assertTupleEqual(transition_voltage, (0, 1))

        transition_voltage = pulse_sequence.get_transition_voltages(
            connection=c1, t=15)
        self.assertTupleEqual(transition_voltage, (1, 2))
Пример #13
0
    def test_arbstudio_pulseblaster(self):
        self.layout.acquisition_channels([])
        self.layout.primary_instrument('pulseblaster')
        self.layout.acquisition_instrument('ATS')
        self.layout.add_connection(output_arg='arbstudio.ch1',
                                   input_arg='chip.TGAC')
        self.layout.add_connection(output_arg='arbstudio.ch2',
                                   input_arg='chip.DF',
                                   default=True)

        self.layout.add_connection(output_arg='pulseblaster.ch1',
                                   input_arg='arbstudio.trig_in',
                                   trigger=True)

        trigger_connections = self.layout.get_connections(
            input_instrument='arbstudio', trigger=True)
        self.assertEqual(len(trigger_connections), 1)
        trigger_connection = trigger_connections[0]
        self.assertEqual(trigger_connection.output['instrument'],
                         'pulseblaster')

        pulse_sequence = PulseSequence()
        empty_pulse = DCPulse(name='empty',
                              t_start=0,
                              duration=10,
                              amplitude=1.5)
        load_pulse = DCPulse(name='load',
                             t_start=10,
                             duration=10,
                             amplitude=-1.5)
        read_pulse = DCPulse(name='read', t_start=20, duration=10, amplitude=0)
        pulses = [empty_pulse, load_pulse, read_pulse]
        for pulse in pulses:
            pulse_sequence.add(pulse)

        self.layout.pulse_sequence = pulse_sequence
        self.layout.setup()

        self.assertEqual(len(self.pulseblaster.instructions()), 7)
        self.assertEqual([ins[0] for ins in self.pulseblaster.instructions()],
                         [1, 0, 1, 0, 1, 0, 0])
        self.assertEqual(self.pulseblaster.instructions()[-1][2], 1)

        self.pulseblaster.instructions([])
        self.interfaces['pulseblaster'].ignore_first_trigger(True)
        self.layout.pulse_sequence = pulse_sequence
        self.layout.setup()

        self.assertEqual(len(self.pulseblaster.instructions()), 7)
        self.assertEqual([ins[0] for ins in self.pulseblaster.instructions()],
                         [0, 0, 1, 0, 1, 0, 1])
Пример #14
0
    def test_final_delay(self):
        original_final_delay = PulseSequence.default_final_delay

        pulse_sequence = PulseSequence()
        self.assertEqual(pulse_sequence.final_delay, original_final_delay)

        PulseSequence.default_final_delay = 1
        pulse_sequence = PulseSequence()
        self.assertEqual(pulse_sequence.final_delay, 1)

        pulse_sequence = PulseSequence(final_delay=2)
        self.assertEqual(pulse_sequence.final_delay, 2)

        PulseSequence.default_final_delay = original_final_delay
Пример #15
0
    def test_add_pulse_separate_connection(self):
        pulse_sequence = PulseSequence()
        pulse1, = pulse_sequence.add(Pulse(duration=1))
        self.assertEqual(pulse1.t_start, 0)

        pulse2, = pulse_sequence.add(
            Pulse(duration=2, connection_label='output'))
        self.assertEqual(pulse2.t_start, 0)

        pulse3, = pulse_sequence.add(
            Pulse(duration=2, connection_label='output'))
        self.assertEqual(pulse3.t_start, 2)

        connection = SingleConnection(output_instrument='ins1',
                                      output_channel=Channel('ins1', 'ch1'),
                                      input_instrument='ins2',
                                      input_channel=Channel('ins2', 'ch1'))
        pulse4, = pulse_sequence.add(Pulse(duration=5, connection=connection))
        self.assertEqual(pulse4.t_start, 0)
        pulse5, = pulse_sequence.add(Pulse(duration=5, connection=connection))
        self.assertEqual(pulse5.t_start, 5)

        output_connection = SingleConnection(
            output_instrument='ins1',
            output_channel=Channel('ins1', 'ch1'),
            input_instrument='ins2',
            input_channel=Channel('ins2', 'ch1'),
            label='output')
        pulse6, = pulse_sequence.add(
            Pulse(duration=5, connection=output_connection))
        self.assertEqual(pulse6.t_start, 4)
Пример #16
0
    def test_add_multiple_pulses(self):
        pulse = DCPulse(name='dc', amplitude=1.5, duration=10, t_start=0)
        pulse2 = DCPulse(name='dc', amplitude=1.5, duration=10, t_start=10)
        pulse_sequence = PulseSequence()
        pulse_sequence.add(pulse, pulse2)
        self.assertEqual(len(pulse_sequence), 2)
        self.assertEqual(pulse_sequence.pulses[0], pulse)
        self.assertEqual(pulse_sequence.pulses[1], pulse2)

        pulse3 = DCPulse(name='dc', amplitude=1.5, duration=10)
        pulse3_added, = pulse_sequence.add(pulse3)
        # This one shouldn't be equal since t_stop was not set
        self.assertNotEqual(pulse_sequence.pulses[2], pulse3)
        pulse3.t_start = pulse3_added.t_start
        self.assertEqual(pulse_sequence.pulses[2], pulse3)
Пример #17
0
    def test_pickle_pulse_sequence_two_pulses(self):
        p = DCPulse('pulse', duration=2, amplitude=3)
        pulse_sequence = PulseSequence(pulses=[p, p])
        self.assertEqual(pulse_sequence.pulses[0].full_name, 'pulse[0]')
        self.assertEqual(pulse_sequence.pulses[1].full_name, 'pulse[1]')
        self.assertEqual(pulse_sequence.pulses[0].t_start, 0)
        self.assertEqual(pulse_sequence.pulses[0].duration, 2)
        self.assertEqual(pulse_sequence.pulses[0].amplitude, 3)
        self.assertEqual(pulse_sequence.duration, 4)

        pickle_dump = pickle.dumps(pulse_sequence)
        pickled_pulse_sequence = pickle.loads(pickle_dump)
        self.assertEqual(pickled_pulse_sequence.pulses[0].full_name,
                         'pulse[0]')
        self.assertEqual(pickled_pulse_sequence.pulses[0].t_start, 0)
        self.assertEqual(pickled_pulse_sequence.pulses[0].duration, 2)
        self.assertEqual(pickled_pulse_sequence.pulses[0].amplitude, 3)

        self.assertEqual(pickled_pulse_sequence.pulses[1].full_name,
                         'pulse[1]')
        self.assertEqual(pickled_pulse_sequence.pulses[1].t_start, 2)
        self.assertEqual(pickled_pulse_sequence.pulses[1].duration, 2)
        self.assertEqual(pickled_pulse_sequence.pulses[1].amplitude, 3)

        self.assertEqual(pickled_pulse_sequence.duration, 4)
Пример #18
0
    def test_getitem(self):
        pulse_sequence = PulseSequence()
        pulse1, = pulse_sequence.add(DCPulse('DC', duration=1))

        self.assertIs(pulse_sequence['DC'], pulse1)
        self.assertIs(pulse_sequence['duration'],
                      pulse_sequence.parameters['duration'])

        pulse1.id = 0
        self.assertIs(pulse_sequence['DC'], pulse1)
        self.assertIs(pulse_sequence['DC[0]'], pulse1)

        pulse2, = pulse_sequence.add(DCPulse('DC', duration=1))
        self.assertIs(pulse_sequence['DC[0]'], pulse1)
        self.assertIs(pulse_sequence['DC[1]'], pulse2)
        with self.assertRaises(KeyError):
            pulse_sequence['DC']
Пример #19
0
    def test_pulse_signalling_after_copy(self):
        pulse_sequence = PulseSequence()
        pulse, = pulse_sequence.add(DCPulse('read', duration=1, amplitude=2))
        self.assertEqual(pulse_sequence.enabled_pulses, [pulse])
        self.assertEqual(pulse_sequence.disabled_pulses, [])

        pulse.enabled = False
        self.assertEqual(pulse_sequence.enabled_pulses, [])
        self.assertEqual(pulse_sequence.disabled_pulses, [pulse])

        pulse_sequence_copy = copy(pulse_sequence)
        self.assertEqual(pulse_sequence.enabled_pulses, [])
        self.assertEqual(pulse_sequence.disabled_pulses, [pulse])

        pulse.enabled = True
        self.assertEqual(pulse_sequence.enabled_pulses, [pulse])
        self.assertEqual(pulse_sequence.disabled_pulses, [])
Пример #20
0
 def test_initialize_with_pulses(self):
     pulse = DCPulse(name='dc', amplitude=1.5, duration=10, t_start=0)
     pulse2 = DCPulse(name='dc', amplitude=1.5, duration=10)
     pulse_sequence = PulseSequence(pulses=[pulse, pulse2])
     self.assertEqual(len(pulse_sequence), 2)
     self.assertEqual(pulse_sequence.pulses[0], pulse)
     self.assertNotEqual(pulse_sequence.pulses[1], pulse2)  #t_start differs
     pulse2.t_start = 10
     self.assertEqual(pulse_sequence.pulses[1], pulse2)
Пример #21
0
    def test_get_pulse(self):
        pulse_sequence = PulseSequence()
        p = Pulse('p1', duration=1)
        p1_added, = pulse_sequence.add(p)

        self.assertIs(pulse_sequence.get_pulse(name='p1'), p1_added)

        p2_added, = pulse_sequence.add(p)
        with self.assertRaises(RuntimeError):
            pulse_sequence.get_pulse(name='p1')
        self.assertIs(pulse_sequence.get_pulse(name='p1[0]'), p1_added)
        self.assertIs(pulse_sequence.get_pulse(name='p1[1]'), p2_added)
Пример #22
0
    def test_change_first_t_stop(self):
        p = Pulse(duration=1)
        pulse_sequence = PulseSequence(pulses=[p, p])
        self.assertEqual(pulse_sequence[1].t_start, 1)

        pulse_sequence[0].duration = 2
        self.assertEqual(pulse_sequence[0].t_stop, 2)
        self.assertEqual(pulse_sequence[1].t_start, 2)

        pulse_sequence[0].t_start = 2
        self.assertEqual(pulse_sequence[0].t_stop, 4)
        self.assertEqual(pulse_sequence[1].t_start, 4)
Пример #23
0
    def test_snapshot(self):
        pulse_sequence = PulseSequence()
        snapshot = pulse_sequence.snapshot()
        for parameter_name, parameter in pulse_sequence.parameters.items():
            if parameter.unit:
                parameter_name += f' ({parameter.unit})'
            if parameter_name in ['enabled_pulses']:
                continue
            self.assertEqual(snapshot.pop(parameter_name),
                             parameter(),
                             msg=parameter_name)

        self.assertEqual(len(snapshot), 1)

        pulse_sequence.add(Pulse(duration=5))

        snapshot = pulse_sequence.snapshot()
        for parameter_name, parameter in pulse_sequence.parameters.items():
            if parameter_name in ['pulses', 'enabled_pulses']:
                continue
            if parameter.unit:
                parameter_name += f' ({parameter.unit})'
            self.assertEqual(snapshot.pop(parameter_name),
                             parameter(),
                             msg=parameter_name)

        for k, pulse_snapshot in enumerate(snapshot['pulses']):
            self.assertEqual(pulse_snapshot,
                             pulse_sequence.pulses[k].snapshot(),
                             msg=repr(pulse_sequence.pulses[k]))
Пример #24
0
 def test_remove_pulse_remove(self):
     # Remove pulses using .remove
     pulse_sequence = PulseSequence()
     pulse = DCPulse(name='dc', amplitude=1.5, duration=10, t_start=0)
     pulse_sequence.add(pulse)
     pulse_sequence.remove(pulse)
     self.assertEqual(len(pulse_sequence.pulses), 0)
Пример #25
0
    def test_connected_pulses_t_startoffset(self):
        pulse_sequence = PulseSequence()

        p = Pulse(duration=1)
        pulse1, pulse2 = pulse_sequence.add(p, p)

        # also connect to t_start to measure how often it's called
        registrar = Registrar()
        pulse2['t_start'].connect(registrar)
        self.assertEqual(registrar.values, [1])

        pulse1.t_stop = 2
        self.assertEqual(registrar.values, [1, 2])
        self.assertEqual(pulse2.t_start, 2)

        pulse1['t_stop'].connect(pulse2['t_start'], offset=1)
        self.assertEqual(pulse2.t_start, 3)
        self.assertEqual(registrar.values, [1, 2, 3])

        pulse1.t_stop = 5
        self.assertEqual(pulse2.t_start, 6)
        self.assertEqual(registrar.values, [1, 2, 3, 6])
Пример #26
0
 def test_remove_wrong_pulse_by_name(self):
     # Remove pulses using .remove
     pulse_sequence = PulseSequence()
     pulse = DCPulse(name='dc', amplitude=1.5, duration=10, t_start=0)
     pulse_sequence.add(pulse)
     with self.assertRaises(AssertionError):
         pulse_sequence.remove('dc2')
     self.assertEqual(len(pulse_sequence.pulses), 1)
Пример #27
0
 def test_overlapping_pulses_different_connection_label(self):
     pulses = [
         DCPulse(t_start=0, duration=10, connection_label='con1'),
         DCPulse(t_start=5, duration=10, connection_label='con2')
     ]
     pulse_sequence = PulseSequence(allow_pulse_overlap=False)
     pulse_sequence.quick_add(*pulses)
     pulse_sequence.finish_quick_add()
Пример #28
0
 def test_remove_reinstantiated_pulse(self):
     # Remove other pulse using .remove
     pulse_sequence = PulseSequence()
     pulse = DCPulse(name='dc', amplitude=1.5, duration=10, t_start=0)
     pulse_sequence.add(pulse)
     pulse2 = DCPulse(name='dc', amplitude=1.5, duration=10, t_start=0)
     pulse_sequence.remove(pulse2)  # Should work since all attributes match
     self.assertEqual(len(pulse_sequence.pulses), 0)
Пример #29
0
    def test_setup_pulses(self):
        self.layout.primary_instrument('arbstudio')
        self.layout.add_connection(output_arg='arbstudio.ch1',
                                   input_arg='chip.TGAC')
        self.layout.add_connection(output_arg='arbstudio.ch2',
                                   input_arg='chip.DF',
                                   default=True)

        pulse_sequence = PulseSequence()
        empty_pulse = DCPulse(name='empty',
                              t_start=0,
                              duration=10,
                              amplitude=1.5)
        load_pulse = DCPulse(name='load',
                             t_start=10,
                             duration=10,
                             amplitude=-1.5)
        read_pulse = DCPulse(name='read', t_start=20, duration=10, amplitude=0)
        pulses = [empty_pulse, load_pulse, read_pulse]
        for pulse in pulses:
            pulse_sequence.add(pulse)

        self.layout.pulse_sequence = pulse_sequence
        self.layout.setup()

        waveforms = self.arbstudio.get_waveforms()
        for channel in [0, 2, 3]:
            self.assertEqual(len(waveforms[channel]), 0)
        self.assertEqual(len(waveforms[1]), 3)
        sequence = [
            self.arbstudio.ch1_sequence(),
            self.arbstudio.ch2_sequence(),
            self.arbstudio.ch3_sequence(),
            self.arbstudio.ch4_sequence()
        ]
        for channel in [0, 2, 3]:
            self.assertEqual(len(sequence[channel]), 0)
        self.assertEqual(len(sequence[1]), 3)
Пример #30
0
    def test_pulse_sequence_duration(self):
        pulse_sequence = PulseSequence()
        pulse_sequence.duration
        self.assertEqual(pulse_sequence.duration, 0)

        pulse_sequence.duration = None
        self.assertEqual(pulse_sequence.duration, 0)

        pulse_sequence.duration = 1
        self.assertEqual(pulse_sequence.duration, 1)

        pulse_sequence.add(DCPulse(duration=5))
        self.assertEqual(pulse_sequence.duration, 5)

        pulse_sequence.clear()
        self.assertEqual(pulse_sequence.duration, 0)