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_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_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_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_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_overlapping_random_pulses(self): for connection_label in [ 'connection1', 'connection2', 'connection3', None ]: pulses = [] t = 0 for k in range(30): duration = np.round(np.random.rand(), 11) pulses.append( DCPulse('DC', t_start=t, duration=duration, connection_label='connection1')) t += duration random.shuffle(pulses) pulse_sequence = PulseSequence(allow_pulse_overlap=False) pulse_sequence.quick_add(*pulses) pulse_sequence.finish_quick_add() # No overlap # Add pulses with connection label second_pulses = [] t = 0 for k in range(30): duration = np.round(np.random.rand(), 11) second_pulses.append( DCPulse('DC', t_start=t, duration=duration, connection_label='connection2')) t += duration random.shuffle(second_pulses) pulse_sequence.quick_add(*second_pulses) pulse_sequence.finish_quick_add() # No overlap # Add pulse that potentially overlaps based on connection_label overlapping_pulse = DCPulse(t_start=pulse_sequence.duration / 2, duration=1e-5, connection_label=connection_label) overlapping_pulse_copy, = pulse_sequence.quick_add( overlapping_pulse) if connection_label in ['connection1', 'connection2', None]: with self.assertRaises(AssertionError): pulse_sequence.finish_quick_add() else: pulse_sequence.finish_quick_add() pulse_sequence.remove(overlapping_pulse_copy) pulse_sequence.finish_quick_add()