Example #1
0
    def test_pulse_full_name(self):
        p = Pulse('pulse1')
        self.assertEqual(p.full_name, 'pulse1')
        p.id = 2
        self.assertEqual(p.full_name, 'pulse1[2]')

        p = DCPulse('pulse2')
        self.assertEqual(p.full_name, 'pulse2')
        p.id = 2
        self.assertEqual(p.full_name, 'pulse2[2]')
Example #2
0
    def test_number_of_t_stop_signals(self):
        p = Pulse(t_start=0, duration=1)
        registrar = Registrar()
        p['t_stop'].connect(registrar)

        p.duration = 2
        self.assertEqual(registrar.values, [1, 2])

        p.t_stop = 3
        self.assertEqual(registrar.values, [1, 2, 3])
Example #3
0
    def test_pulse_id(self):
        p = Pulse(name='read')
        self.assertEqual(p.id, None)

        self.assertEqual(p.full_name, 'read')
        p.id = 0
        self.assertEqual(p.name, 'read')
        self.assertEqual(p.full_name, 'read[0]')
        self.assertTrue(p.satisfies_conditions(name='read', id=0))
        self.assertTrue(p.satisfies_conditions(name='read[0]'))
Example #4
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]])
Example #5
0
    def test_t_stop_signal_emit_indirect(self):
        pulse = Pulse(t_start=1, duration=2)

        parameter_measure_t_stop = Parameter(set_cmd=None)
        pulse['t_stop'].connect(parameter_measure_t_stop, update=True)
        self.assertEqual(parameter_measure_t_stop(), 3)

        pulse.t_start = 2
        self.assertEqual(parameter_measure_t_stop(), 4)

        pulse.duration = 3
        self.assertEqual(parameter_measure_t_stop(), 5)
Example #6
0
    def test_pulse_full_name(self):
        p = Pulse('DC', t_start=1)
        self.assertEqual(p.name, 'DC')
        self.assertEqual(p.full_name, 'DC')

        p.id = 0
        self.assertEqual(p.name, 'DC')
        self.assertEqual(p.full_name, 'DC[0]')

        p.id = None
        self.assertEqual(p.name, 'DC')
        self.assertEqual(p.full_name, 'DC')
Example #7
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)
Example #8
0
    def test_pulse_duration_t_stop(self):
        p = Pulse(t_start=1, t_stop=3)
        self.assertEqual(p['t_stop'].get_latest(), 3)
        self.assertEqual(p.duration, 2)
        self.assertEqual(p['t_stop'].get_latest(), 3)
        self.assertEqual(p.t_stop, 3)

        p.duration = 4
        self.assertEqual(p.t_stop, 5)

        p = Pulse(t_start=1, duration=2)
        self.assertEqual(p['t_stop'].get_latest(), 3)
        self.assertEqual(p.t_stop, 3)
Example #9
0
    def test_copied_pulse_full_name(self):
        p = Pulse('DC', t_start=1)

        p_copy = copy(p)
        p_copy.name = 'DC2'

        p.id = 0
        self.assertEqual('DC', p.name)
        self.assertEqual('DC[0]', p.full_name)

        p_copy.id = 1
        p_copy.full_name
        self.assertEqual('DC2', p_copy.name)
        self.assertEqual('DC2[1]', p_copy.full_name)
Example #10
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]))
Example #11
0
    def test_signal_copy(self):
        p = Pulse(t_start=1)

        p2 = Pulse()
        p['t_start'].connect(p2['t_start'])
        self.assertEqual(p2.t_start, 1)

        p3 = copy(p2)
        self.assertEqual(p3.t_start, 1)

        p4 = deepcopy(p2)
        self.assertEqual(p4.t_start, 1)

        p.t_start = 2
        self.assertEqual(p2.t_start, 2)
        self.assertEqual(p3.t_start, 1)
        self.assertEqual(p4.t_start, 1)
Example #12
0
    def test_pulse_differing_connections(self):
        connection = SingleConnection(output_instrument='ins1',
                                      output_channel=Channel('ins1', 'ch1'),
                                      input_instrument='ins2',
                                      input_channel=Channel('ins2', 'ch1'))

        p_no_connection = Pulse()
        p_connection_label = Pulse(connection_label='arb')
        p_connection = Pulse(connection=connection)

        self.assertNotEqual(p_no_connection, p_connection_label)
        self.assertNotEqual(p_no_connection, p_connection)
        self.assertNotEqual(p_connection_label, p_connection)

        connection.label = 'arb'
        self.assertNotEqual(p_no_connection, p_connection_label)
        self.assertNotEqual(p_no_connection, p_connection)
        self.assertEqual(p_connection_label, p_connection)
Example #13
0
    def test_pickle_pulse(self):
        p = Pulse('pulse', t_start=1, duration=2)
        pickle_dump = pickle.dumps(p)

        pickled_pulse = pickle.loads(pickle_dump)
        self.assertEqual(pickled_pulse.name, 'pulse')
        self.assertEqual(pickled_pulse.t_start, 1)
        self.assertEqual(pickled_pulse.duration, 2)
        self.assertEqual(pickled_pulse.t_stop, 3)
Example #14
0
    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)
Example #15
0
    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)
Example #16
0
    def test_set_item(self):
        silq.environment = None

        p = Pulse('read')
        self.assertEqual(p.t_start, 0)
        self.assertEqual(p.t_stop, 10)

        self.config.pulses.read.t_start = 5

        self.assertEqual(p.t_start, 5)
        self.assertEqual(p.t_stop, 15)
Example #17
0
    def test_set_item_copied(self):
        silq.environment = None

        p = Pulse('read')
        p_copy = copy(p)
        self.assertEqual(p_copy.t_start, 0)
        self.assertEqual(p_copy.t_stop, 10)

        self.config.pulses.read.t_start = 5

        self.assertEqual(p_copy.t_start, 5)
        self.assertEqual(p_copy.t_stop, 15)
Example #18
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]')
Example #19
0
    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)
Example #20
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)
Example #21
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)
Example #22
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)
Example #23
0
    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, [])
Example #24
0
    def test_set_item_environment(self):
        silq.environment = 'env1'

        p = Pulse('read')
        self.assertEqual(p.t_start, None)
        self.assertEqual(p.t_stop, None)

        self.config.pulses.read.t_start = 5
        self.assertEqual(p.t_start, None)
        self.assertEqual(p.t_stop, None)

        self.config.env1 = {'pulses': {'read': {'t_start': 5}}}
        self.assertEqual(p.t_start, 5)
        self.assertEqual(p.t_stop, None)

        self.config.env1.pulses.read.t_stop = 10
        self.assertEqual(p.t_start, 5)
        self.assertEqual(p.t_stop, 10)
Example #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])
Example #26
0
    def test_signal_emit(self):
        p = Pulse(t_start=1, t_stop=2)

        p2 = Pulse(duration=3)
        p['t_start'].connect(p2['t_start'], offset=5)
        self.assertEqual(p2.t_start, 6)
        self.assertEqual(p2.duration, 3)
        self.assertEqual(p2.t_stop, 9)

        p.t_start = 3
        self.assertEqual(p.t_stop, 4)
        self.assertEqual(p2.t_start, 8)
        self.assertEqual(p2.t_stop, 11)

        p2.t_start = 5
        self.assertEqual(p2.t_start, 5)
        self.assertEqual(p2.duration, 3)
        self.assertEqual(p2.t_stop, 8)

        # The signal connection remains even after changing its value
        p.t_start = 10
        self.assertEqual(p2.t_start, 15)
Example #27
0
 def test_pulse_no_id(self):
     p = Pulse('name')
     p.id = None
Example #28
0
 def test_first_pulse_no_tstart(self):
     p = Pulse(duration=1)
     pulse_sequence = PulseSequence(pulses=[p])
     self.assertEqual(pulse_sequence[0].t_start, 0)
Example #29
0
 def test_pulse_no_duration_error(self):
     p = Pulse()
     with self.assertRaises(SyntaxError):
         PulseSequence([p])
Example #30
0
 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)