def test_update_parameters(self) -> None: setup = HardwareSetup() awg1 = DummyAWG(num_channels=2, num_markers=0) awg2 = DummyAWG(num_channels=1, num_markers=1) dac1 = DummyDAC() dac2 = DummyDAC() setup.set_channel('A', PlaybackChannel(awg1, 0)) setup.set_channel('B', PlaybackChannel(awg1, 1)) setup.set_channel('C', PlaybackChannel(awg2, 0)) setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1')) setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2')) loop1, loop2, _ = self.get_test_loops() name1 = 'prog1' name2 = 'prog2' setup.register_program(name1, loop1) setup.register_program(name2, loop2) parameters = dict(a=1, b=5) with mock.patch.object(DummyAWG, 'set_volatile_parameters') as setpara: setup.update_parameters(name1, parameters) setpara.assert_called_once_with(name1, parameters) with mock.patch.object(DummyAWG, 'set_volatile_parameters') as setpara: setup.update_parameters(name2, parameters) assert setpara.call_count == 2 setpara.assert_called_with(name2, parameters)
def test_clear_programs(self) -> None: setup = HardwareSetup() awg1 = DummyAWG(num_channels=2, num_markers=0) awg2 = DummyAWG(num_channels=1, num_markers=1) dac1 = DummyDAC() dac2 = DummyDAC() setup.set_channel('A', PlaybackChannel(awg1, 0)) setup.set_channel('B', PlaybackChannel(awg1, 1)) setup.set_channel('C', PlaybackChannel(awg2, 0)) setup.set_channel('M1', MarkerChannel(awg2, 0)) setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1')) setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2')) loop1, loop2, loop3 = self.get_test_loops() setup.register_program('prog1', loop1) setup.register_program('prog2', loop2) setup.register_program('prog3', loop3) self.assertTrue(setup.registered_programs) setup.clear_programs() self.assertFalse(setup.registered_programs)
def test_remove_program(self): loop1, loop2, _ = self.get_test_loops() awg1 = DummyAWG() awg2 = DummyAWG() awg3 = DummyAWG() dac1 = DummyDAC() dac2 = DummyDAC() setup = HardwareSetup() setup.set_channel('A', PlaybackChannel(awg1, 0)) setup.set_channel('B', MarkerChannel(awg2, 0)) setup.set_channel('C', MarkerChannel(awg3, 0)) setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1')) setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2')) setup.register_program('test_1', loop1) setup.register_program('test_2', loop2) setup.arm_program('test_1') setup.remove_program('test_1') self.assertEqual(setup.registered_programs.keys(), {'test_2'}) self.assertIsNone(awg1._armed) self.assertIsNone(awg2._armed)
def test_known_dacs(self) -> None: setup = HardwareSetup() dac1 = DummyDAC() dac2 = DummyDAC() setup.set_measurement('m1', MeasurementMask(dac1, 'mask_1')) setup.set_measurement('m2', MeasurementMask(dac2, 'mask_2')) expected = {dac1, dac2} self.assertEqual(expected, setup.known_dacs)
def test_run_program(self): wf = DummyWaveform(duration=1.1, defined_channels={'A', 'B'}) block = InstructionBlock() block.add_instruction_meas([('m1', 0., 1.)]) block.add_instruction_exec(wf) awg1 = DummyAWG() awg2 = DummyAWG() awg3 = DummyAWG() dac1 = DummyDAC() dac2 = DummyDAC() setup = HardwareSetup() setup.set_channel('A', PlaybackChannel(awg1, 0)) setup.set_channel('B', MarkerChannel(awg2, 0)) setup.set_channel('C', MarkerChannel(awg3, 0)) setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1')) setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2')) class ProgStart: def __init__(self): self.was_started = False def __call__(self): self.was_started = True program_started = ProgStart() setup.register_program('test', block, run_callback=program_started) self.assertIsNone(awg1._armed) self.assertIsNone(awg2._armed) self.assertIsNone(awg3._armed) self.assertIsNone(dac1._armed_program) self.assertIsNone(dac2._armed_program) setup.run_program('test') self.assertEqual(awg1._armed, 'test') self.assertEqual(awg2._armed, 'test') self.assertIsNone(awg3._armed) self.assertEqual(dac1._armed_program, 'test') self.assertIsNone(dac2._armed_program) self.assertTrue(program_started.was_started)
def initialize_hardware_setup(self): self.simulator_manager = TaborSimulatorManager() try: self.simulator_manager.start_simulator() except RuntimeError as err: raise unittest.SkipTest(*err.args) from err self.awg = self.simulator_manager.connect() if self.preparation_commands: for cmd in self.preparation_commands: self.awg.send_cmd(cmd) self.dac = DummyDAC() self.hardware_setup = HardwareSetup() self.hardware_setup.set_channel('TABOR_A', PlaybackChannel(self.awg.channel_pair_AB, 0)) self.hardware_setup.set_channel('TABOR_B', PlaybackChannel(self.awg.channel_pair_AB, 1)) self.hardware_setup.set_channel('TABOR_A_MARKER', MarkerChannel(self.awg.channel_pair_AB, 0)) self.hardware_setup.set_channel('TABOR_B_MARKER', MarkerChannel(self.awg.channel_pair_AB, 1)) self.hardware_setup.set_channel('TABOR_C', PlaybackChannel(self.awg.channel_pair_CD, 0)) self.hardware_setup.set_channel('TABOR_D', PlaybackChannel(self.awg.channel_pair_CD, 1)) self.hardware_setup.set_channel('TABOR_C_MARKER', MarkerChannel(self.awg.channel_pair_CD, 0)) self.hardware_setup.set_channel('TABOR_D_MARKER', MarkerChannel(self.awg.channel_pair_CD, 1)) self.hardware_setup.set_measurement("MEAS_A", MeasurementMask(self.dac, "MASK_A")) self.hardware_setup.set_measurement("MEAS_B", MeasurementMask(self.dac, "MASK_B")) self.hardware_setup.set_measurement("MEAS_C", MeasurementMask(self.dac, "MASK_C")) self.hardware_setup.set_measurement("MEAS_D", MeasurementMask(self.dac, "MASK_D"))
def test_run_program(self): loop, *rest = self.get_test_loops() awg1 = DummyAWG() awg2 = DummyAWG() awg3 = DummyAWG() dac1 = DummyDAC() dac2 = DummyDAC() setup = HardwareSetup() setup.set_channel('A', PlaybackChannel(awg1, 0)) setup.set_channel('B', MarkerChannel(awg2, 0)) setup.set_channel('C', MarkerChannel(awg3, 0)) setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1')) setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2')) class ProgStart: def __init__(self): self.was_started = False def __call__(self): self.was_started = True program_started = ProgStart() setup.register_program('test', loop, run_callback=program_started) self.assertIsNone(awg1._armed) self.assertIsNone(awg2._armed) self.assertIsNone(awg3._armed) self.assertIsNone(dac1._armed_program) self.assertIsNone(dac2._armed_program) setup.run_program('test') self.assertEqual(awg1._armed, 'test') self.assertEqual(awg2._armed, 'test') self.assertIsNone(awg3._armed) self.assertEqual(dac1._armed_program, 'test') self.assertIsNone(dac2._armed_program) self.assertTrue(program_started.was_started)
def test_remove_program(self): wf_1 = DummyWaveform(duration=1.1, defined_channels={'A', 'B'}) wf_2 = DummyWaveform(duration=1.1, defined_channels={'A', 'C'}) block_1 = InstructionBlock() block_2 = InstructionBlock() block_1.add_instruction_meas([('m1', 0., 1.)]) block_1.add_instruction_exec(wf_1) block_2.add_instruction_meas([('m2', 0., 1.)]) block_2.add_instruction_exec(wf_2) awg1 = DummyAWG() awg2 = DummyAWG() awg3 = DummyAWG() dac1 = DummyDAC() dac2 = DummyDAC() setup = HardwareSetup() setup.set_channel('A', PlaybackChannel(awg1, 0)) setup.set_channel('B', MarkerChannel(awg2, 0)) setup.set_channel('C', MarkerChannel(awg3, 0)) setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1')) setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2')) setup.register_program('test_1', block_1) setup.register_program('test_2', block_2) setup.arm_program('test_1') setup.remove_program('test_1') self.assertEqual(setup.registered_programs.keys(), {'test_2'}) self.assertIsNone(awg1._armed) self.assertIsNone(awg2._armed)
def test_clear_programs(self) -> None: setup = HardwareSetup() awg1 = DummyAWG(num_channels=2, num_markers=0) awg2 = DummyAWG(num_channels=1, num_markers=1) dac1 = DummyDAC() dac2 = DummyDAC() setup.set_channel('A', PlaybackChannel(awg1, 0)) setup.set_channel('B', PlaybackChannel(awg1, 1)) setup.set_channel('C', PlaybackChannel(awg2, 0)) setup.set_channel('M1', MarkerChannel(awg2, 0)) wf1 = DummyWaveform(duration=1.1, defined_channels={'C'}) wf2 = DummyWaveform(duration=7.2, defined_channels={'A'}) wf3 = DummyWaveform(duration=3.7, defined_channels={'B', 'C'}) setup.set_measurement('m1', MeasurementMask(dac1, 'DAC_1')) setup.set_measurement('m2', MeasurementMask(dac2, 'DAC_2')) block1 = InstructionBlock() block1.add_instruction_exec(wf1) block2 = InstructionBlock() block2.add_instruction_meas([('m1', 0., 1.)]) block2.add_instruction_exec(wf2) block3 = InstructionBlock() block3.add_instruction_meas([('m2', 2., 3.)]) block3.add_instruction_exec(wf3) setup.register_program('prog1', block1) setup.register_program('prog2', block2) setup.register_program('prog3', block3) self.assertTrue(setup.registered_programs) setup.clear_programs() self.assertFalse(setup.registered_programs)
def initialize_hardware_setup(self): self.awg = get_test_hdawg() if self.preparation_commands: preparation_commands = [ (key.format(device_serial=self.awg.serial), value) for key, value in self.preparation_commands.items() ] self.awg.api_session.set(preparation_commands) for idx in range(1, 9): # switch off all outputs self.awg.output(idx, False) self.awg.channel_grouping = zihdawg.HDAWGChannelGrouping.CHAN_GROUP_1x8 self.channel_group, = self.awg.channel_tuples self.dac = DummyDAC() hardware_setup = HardwareSetup() hardware_setup.set_channel('TABOR_A', PlaybackChannel(self.channel_group, 0)) hardware_setup.set_channel('TABOR_B', PlaybackChannel(self.channel_group, 1)) hardware_setup.set_channel('TABOR_A_MARKER', MarkerChannel(self.channel_group, 0)) hardware_setup.set_channel('TABOR_B_MARKER', MarkerChannel(self.channel_group, 1)) hardware_setup.set_channel('TABOR_C', PlaybackChannel(self.channel_group, 2)) hardware_setup.set_channel('TABOR_D', PlaybackChannel(self.channel_group, 3)) hardware_setup.set_channel('TABOR_C_MARKER', MarkerChannel(self.channel_group, 3)) hardware_setup.set_channel('TABOR_D_MARKER', MarkerChannel(self.channel_group, 4)) hardware_setup.set_measurement("MEAS_A", MeasurementMask(self.dac, "MASK_A")) hardware_setup.set_measurement("MEAS_B", MeasurementMask(self.dac, "MASK_B")) hardware_setup.set_measurement("MEAS_C", MeasurementMask(self.dac, "MASK_C")) hardware_setup.set_measurement("MEAS_D", MeasurementMask(self.dac, "MASK_D")) self.hardware_setup = hardware_setup
def test_register_program(self): awg1 = DummyAWG() awg2 = DummyAWG(num_channels=2, num_markers=5) dac = DummyDAC() setup = HardwareSetup() loop, *rest = self.get_test_loops() class ProgStart: def __init__(self): self.was_started = False def __call__(self): self.was_started = True program_started = ProgStart() trafo1 = lambda x: x setup.set_channel('A', PlaybackChannel(awg1, 0, trafo1)) setup.set_channel('B', MarkerChannel(awg2, 1)) setup.set_measurement('m1', MeasurementMask(dac, 'DAC')) setup.register_program('p1', loop, program_started) self.assertEqual(tuple(setup.registered_programs.keys()), ('p1', )) self.assertEqual(setup.registered_programs['p1'].run_callback, program_started) self.assertEqual(setup.registered_programs['p1'].awgs_to_upload_to, {awg1, awg2}) self.assertFalse(program_started.was_started) self.assertEqual(len(awg1._programs), 1) self.assertEqual(len(awg2._programs), 1) _, channels, markers, trafos = awg1._programs['p1'] self.assertEqual(channels, ('A', )) self.assertEqual(markers, (None, )) self.assertEqual(trafos, (trafo1, )) _, channels, markers, trafos = awg2._programs['p1'] self.assertEqual(channels, (None, None)) self.assertEqual(markers, (None, 'B', None, None, None)) self.assertEqual(awg1._armed, None) self.assertEqual(awg2._armed, None) expected_measurement_windows = { 'p1': { 'DAC': (np.array([ 0, ]), np.array([ 1, ])) } } np.testing.assert_equal(dac._measurement_windows, expected_measurement_windows)
def test_register_program(self): awg1 = DummyAWG() awg2 = DummyAWG(num_channels=2, num_markers=5) dac = DummyDAC() setup = HardwareSetup() wfg = WaveformGenerator(num_channels=2, duration_generator=itertools.repeat(1)) block = get_two_chan_test_block(wfg) block._InstructionBlock__instruction_list[:0] = (MEASInstruction([ ('m1', 0.1, 0.2) ]), ) class ProgStart: def __init__(self): self.was_started = False def __call__(self): self.was_started = True program_started = ProgStart() trafo1 = lambda x: x setup.set_channel('A', PlaybackChannel(awg1, 0, trafo1)) setup.set_channel('B', MarkerChannel(awg2, 1)) setup.set_measurement('m1', MeasurementMask(dac, 'DAC')) setup.register_program('p1', block, program_started) self.assertEqual(tuple(setup.registered_programs.keys()), ('p1', )) self.assertEqual(setup.registered_programs['p1'].run_callback, program_started) self.assertEqual(setup.registered_programs['p1'].awgs_to_upload_to, {awg1, awg2}) self.assertFalse(program_started.was_started) self.assertEqual(len(awg1._programs), 1) self.assertEqual(len(awg2._programs), 1) _, channels, markers, trafos = awg1._programs['p1'] self.assertEqual(channels, ('A', )) self.assertEqual(markers, (None, )) self.assertEqual(trafos, (trafo1, )) _, channels, markers, trafos = awg2._programs['p1'] self.assertEqual(channels, (None, None)) self.assertEqual(markers, (None, 'B', None, None, None)) self.assertEqual(awg1._armed, None) self.assertEqual(awg2._armed, None) expected_measurement_windows = { 'p1': { 'DAC': (np.array([0.1, 0.1]), np.array([0.2, 0.2])) } } np.testing.assert_equal(dac._measurement_windows, expected_measurement_windows)