def test_get_pulses(self): pulse_sequence = PulseSequence() self.assertListEqual(pulse_sequence.get_pulses(), []) pulse1 = DCPulse(name='dc1', amplitude=1.5, duration=10, t_start=1) pulse2 = DCPulse(name='dc2', amplitude=2.5, duration=10, t_start=1) pulse3 = TriggerPulse(name='trig', duration=12, t_start=1) pulse_sequence.add(pulse1, pulse2, pulse3) subset_pulses = pulse_sequence.get_pulses() self.assertEqual(subset_pulses[0], pulse1) self.assertListEqual(subset_pulses, [pulse1, pulse2, pulse3]) subset_pulses = pulse_sequence.get_pulses(t_start=1) self.assertListEqual(subset_pulses, [pulse1, pulse2, pulse3]) subset_pulses = pulse_sequence.get_pulses(duration=10) self.assertListEqual(subset_pulses, [pulse1, pulse2]) subset_pulses = pulse_sequence.get_pulses(amplitude=1.5) self.assertListEqual(subset_pulses, [pulse1]) subset_pulses = pulse_sequence.get_pulses(amplitude=('>', 1.5)) self.assertListEqual(subset_pulses, [pulse2]) subset_pulses = pulse_sequence.get_pulses(amplitude=('>=', 1.5)) self.assertListEqual(subset_pulses, [pulse1, pulse2]) pulse = pulse_sequence.get_pulse(amplitude=1.5) self.assertEqual(pulse, pulse1) pulse = pulse_sequence.get_pulse(duration=12) self.assertEqual(pulse, pulse3) with self.assertRaises(RuntimeError): pulse_sequence.get_pulse(duration=10)
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]))
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)
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)
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)
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)
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)
def test_pulse_sequence_bool(self): pulse_sequence = PulseSequence() self.assertFalse(pulse_sequence) pulse_sequence.add(Pulse(duration=5)) self.assertTrue(pulse_sequence) pulse_sequence.clear() self.assertFalse(pulse_sequence)
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
def test_remove_wrong_pulse_remove(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=2, duration=10, t_start=0) with self.assertRaises(AssertionError): pulse_sequence.remove( pulse2) # Should not work since different amplitude self.assertEqual(len(pulse_sequence.pulses), 1)
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)
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]))
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]')
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])
def test_t_list(self): pulse_sequence = PulseSequence() self.assertEqual(pulse_sequence.t_list, [0]) self.assertEqual(pulse_sequence.t_start_list, []) self.assertEqual(pulse_sequence.t_stop_list, []) pulse_sequence.add(Pulse(t_start=1, duration=5)) self.assertEqual(pulse_sequence.t_list, [1, 6]) self.assertEqual(pulse_sequence.t_start_list, [1]) self.assertEqual(pulse_sequence.t_stop_list, [6]) pulse_sequence.clear() self.assertEqual(pulse_sequence.t_list, [0]) self.assertEqual(pulse_sequence.t_start_list, []) self.assertEqual(pulse_sequence.t_stop_list, [])
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)
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)
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']
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]])
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)
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)
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)
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)
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, [])
def test_pulse_sequence_id(self): pulse_sequence = PulseSequence() pulse_sequence.add(Pulse(name='read', duration=1)) p1_read = pulse_sequence['read'] self.assertIsNone(p1_read.id) pulse_sequence.add(Pulse(name='load', duration=1)) self.assertIsNone(p1_read.id) pulse_sequence.add(Pulse(name='read', duration=1)) self.assertEqual(p1_read.id, 0) self.assertEqual(pulse_sequence.get_pulse(name='read', id=0), p1_read) self.assertEqual(pulse_sequence.get_pulse(name='read[0]'), p1_read) p2_read = pulse_sequence['read[1]'] self.assertNotEqual(p2_read, p1_read) pulse_sequence.add(Pulse(name='read', duration=1)) p3_read = pulse_sequence['read[2]'] self.assertNotEqual(p3_read, p1_read) self.assertNotEqual(p3_read, p2_read)
def test_get_pulses_connection(self): connection = SingleConnection(output_instrument='ins1', output_channel=Channel('ins1', 'ch1'), input_instrument='ins2', input_channel=Channel('ins1', 'ch1'), label='connection') pulse_sequence = PulseSequence() pulse1, pulse2 = pulse_sequence.add( Pulse('pulse1', duration=1, connection=connection), Pulse('pulse1', duration=2)) retrieved_pulse = pulse_sequence.get_pulse(connection=connection) self.assertEqual(retrieved_pulse, pulse1) retrieved_pulse = pulse_sequence.get_pulse( name='pulse1', connection_label='connection') self.assertEqual(retrieved_pulse, pulse1) pulse2.connection_label = 'connection' self.assertEqual(len(pulse_sequence.get_pulses(connection=connection)), 2)
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])
def test_pulse_overlap(self): pulse_sequence = PulseSequence(allow_pulse_overlap=False) pulse1 = DCPulse(t_start=0, duration=10e-3) pulse2 = DCPulse(t_start=5e-3, duration=10e-3) with self.assertRaises(AssertionError): pulse_sequence.add(pulse1, pulse2)
def test_pulse_overlap_no_t_start_sequential(self): pulse_sequence = PulseSequence(allow_pulse_overlap=False) pulse1 = DCPulse(duration=10e-3) pulse_sequence.add(pulse1) pulse_sequence.add(pulse1)
def test_second_pulse_no_tstart_sequential(self): p = Pulse(duration=1) pulse_sequence = PulseSequence(pulses=[p]) pulse_sequence.add(p) self.assertEqual(pulse_sequence[0].t_start, 0) self.assertEqual(pulse_sequence[1].t_start, 1)