def test_upload_segment(self): channel_pair = TaborChannelPair(self.instrument, identifier='asd', channels=(1, 2)) self.reset_instrument_logs() channel_pair._segment_references = np.array([1, 2, 0, 1], dtype=np.uint32) channel_pair._segment_capacity = 192 + np.array([0, 16, 32, 32], dtype=np.uint32) channel_pair._segment_lengths = channel_pair._segment_capacity.copy() channel_pair._segment_hashes = np.array([1, 2, 3, 4], dtype=np.int64) # prevent entering and exiting configuration mode channel_pair._configuration_guard_count = 2 segment = TaborSegment.from_sampled( np.ones(192 + 16, dtype=np.uint16), np.zeros(192 + 16, dtype=np.uint16), None, None) segment_binary = segment.get_as_binary() with self.assertRaises(ValueError): channel_pair._upload_segment(3, segment) with self.assertRaises(ValueError): channel_pair._upload_segment(0, segment) channel_pair._upload_segment(2, segment) np.testing.assert_equal( channel_pair._segment_capacity, 192 + np.array([0, 16, 32, 32], dtype=np.uint32)) np.testing.assert_equal( channel_pair._segment_lengths, 192 + np.array([0, 16, 16, 32], dtype=np.uint32)) np.testing.assert_equal( channel_pair._segment_hashes, np.array([1, 2, hash(segment), 4], dtype=np.int64)) expected_commands = [ ':INST:SEL 1', ':INST:SEL 1', ':INST:SEL 1', ':TRAC:DEF 3, 208', ':TRAC:SEL 3', ':TRAC:MODE COMB' ] expected_log = [ ((), dict(cmd_str=cmd, paranoia_level=channel_pair.internal_paranoia_level)) for cmd in expected_commands ] self.assertAllCommandLogsEqual(expected_log) self.assert_written_segment_data(segment_binary)
def test_change_armed_program_advanced_sequence(self): channel_pair = TaborChannelPair(self.instrument, identifier='asd', channels=(1, 2)) # prevent entering and exiting configuration mode channel_pair._configuration_guard_count = 2 self.instrument.paranoia_level = 0 self.instrument.logged_commands = [] self.instrument.logged_queries = [] self.instrument._send_binary_data_calls = [] self.reset_instrument_logs() advanced_sequencer_table = [(2, 1, 0), (3, 2, 0)] sequencer_tables = [[(3, 0, 0), (2, 1, 0), (1, 0, 0), (1, 2, 0), (1, 3, 0)], [(4, 1, 0), (2, 1, 0), (1, 0, 0), (1, 2, 0), (1, 3, 0)]] wf_idx2seg_idx = np.array([2, 5, 3, 1]) sequencer_tables = self.to_new_sequencer_tables(sequencer_tables) advanced_sequencer_table = self.to_new_advanced_sequencer_table( advanced_sequencer_table) expected_sequencer_tables = [[(3, 3, 0), (2, 6, 0), (1, 3, 0), (1, 4, 0), (1, 2, 0)], [(4, 6, 0), (2, 6, 0), (1, 3, 0), (1, 4, 0), (1, 2, 0)]] program = DummyTaborProgramClass( advanced_sequencer_table=advanced_sequencer_table, sequencer_tables=sequencer_tables, waveform_mode=TaborSequencing.ADVANCED)(None, None, None, None) channel_pair._known_programs['test'] = TaborProgramMemory( wf_idx2seg_idx, program) channel_pair.change_armed_program('test') expected_adv_seq_table_log = [([(1, 1, 1), (2, 2, 0), (3, 3, 0)], ':ASEQ:DATA', None)] expected_sequencer_table_log = [ ((sequencer_table, ), dict(pref=':SEQ:DATA', paranoia_level=None)) for sequencer_table in [channel_pair._idle_sequence_table] + expected_sequencer_tables ] self.assert_written_sequencer_tables(channel_pair._idle_sequence_table, *expected_sequencer_tables) self.assert_written_advanced_sequencer_tables([(1, 1, 1), (2, 2, 0), (3, 3, 0)])
def test_execute_multiple_commands_with_config_guard(self): channel_pair = TaborChannelPair(self.instrument, identifier='asd', channels=(1, 2)) # prevent entering and exiting configuration mode channel_pair._configuration_guard_count = 2 given_commands = [ ':ASEQ:DEF 2,2,5,0', ':SEQ:SEL 2', ':SEQ:DEF 1,2,10,0' ] expected_command = ':ASEQ:DEF 2,2,5,0;:SEQ:SEL 2;:SEQ:DEF 1,2,10,0' with mock.patch.object(channel_pair.device, 'send_cmd') as send_cmd: channel_pair._execute_multiple_commands_with_config_guard( given_commands) send_cmd.assert_called_once_with( expected_command, paranoia_level=channel_pair.internal_paranoia_level)
def test_change_armed_program_single_waveform(self): channel_pair = TaborChannelPair(self.instrument, identifier='asd', channels=(1, 2)) # prevent entering and exiting configuration mode channel_pair._configuration_guard_count = 2 self.instrument.paranoia_level = 0 self.instrument.logged_commands = [] self.instrument.logged_queries = [] self.reset_instrument_logs() advanced_sequencer_table = [(1, 1, 0)] sequencer_tables = [[(10, 0, 0)]] w2s = np.array([4]) sequencer_tables = self.to_new_sequencer_tables(sequencer_tables) advanced_sequencer_table = self.to_new_advanced_sequencer_table( advanced_sequencer_table) expected_sequencer_table = [(10, 5, 0), (1, 1, 0), (1, 1, 0)] program = DummyTaborProgramClass( advanced_sequencer_table=advanced_sequencer_table, sequencer_tables=sequencer_tables, waveform_mode=TaborSequencing.SINGLE)(None, None, None, None) channel_pair._known_programs['test'] = TaborProgramMemory(w2s, program) channel_pair.change_armed_program('test') expected_adv_seq_table_log = [([(1, 1, 1), (1, 2, 0), (1, 1, 0)], ':ASEQ:DATA', None)] expected_sequencer_table_log = [ ((sequencer_table, ), dict(pref=':SEQ:DATA', paranoia_level=None)) for sequencer_table in [channel_pair._idle_sequence_table, expected_sequencer_table] ] self.assert_written_sequencer_tables(channel_pair._idle_sequence_table, expected_sequencer_table) self.assert_written_advanced_sequencer_tables([(1, 1, 1), (1, 2, 0), (1, 1, 0)])
def test_amend_segments_iter(self): channel_pair = TaborChannelPair(self.instrument, identifier='asd', channels=(1, 2)) # prevent entering and exiting configuration mode channel_pair._configuration_guard_count = 2 self.instrument.paranoia_level = 0 self.reset_instrument_logs() channel_pair._segment_references = np.array([1, 2, 0, 1], dtype=np.uint32) channel_pair._segment_capacity = 192 + np.array([0, 16, 32, 32], dtype=np.uint32) channel_pair._segment_lengths = 192 + np.array([0, 0, 16, 16], dtype=np.uint32) channel_pair._segment_hashes = np.array([1, 2, 3, 4], dtype=np.int64) data = np.ones(192, dtype=np.uint16) segments = [ TaborSegment.from_sampled(0 * data, 1 * data, None, None), TaborSegment.from_sampled(1 * data, 2 * data, None, None) ] indices = channel_pair._amend_segments(segments) expected_references = np.array([1, 2, 0, 1, 1, 1], dtype=np.uint32) expected_capacities = 192 + np.array([0, 16, 32, 32, 0, 0], dtype=np.uint32) expected_lengths = 192 + np.array([0, 0, 16, 16, 0, 0], dtype=np.uint32) expected_hashes = np.array( [1, 2, 3, 4, hash(segments[0]), hash(segments[1])], dtype=np.int64) np.testing.assert_equal(channel_pair._segment_references, expected_references) np.testing.assert_equal(channel_pair._segment_capacity, expected_capacities) np.testing.assert_equal(channel_pair._segment_lengths, expected_lengths) np.testing.assert_equal(channel_pair._segment_hashes, expected_hashes) np.testing.assert_equal(indices, np.array([4, 5], dtype=np.int64)) expected_commands = [ ':INST:SEL 1', ':TRAC:DEF 5,{}'.format(2 * 192 + 16), ':TRAC:SEL 5', ':TRAC:MODE COMB', ':TRAC:DEF 5,192', ':TRAC:DEF 6,192' ] expected_log = [ ((), dict(cmd_str=cmd, paranoia_level=channel_pair.internal_paranoia_level)) for cmd in expected_commands ] self.assertAllCommandLogsEqual(expected_log) # no segment lengths written self.assert_written_segment_lengths() expected_bin_blob = make_combined_wave(segments) self.assert_written_segment_data(expected_bin_blob)