def test_register_operations(self): card = AlazarCard(None) operations = 'this is no operatoin but a string' card.register_operations('test', operations) self.assertEqual(len(card._registered_programs), 1) self.assertIs(card._registered_programs['test'].operations, operations)
def test_register_measurement_windows(self): raw_card = dummy_modules.dummy_atsaverage.core.AlazarCard() card = AlazarCard(raw_card) self.assertIs(card.card, raw_card) card.register_mask_for_channel('A', 3, 'auto') card.register_mask_for_channel('B', 1, 'auto') card.config = dummy_modules.dummy_atsaverage.config.ScanlineConfiguration() card.register_measurement_windows('empty', dict()) begins = np.arange(100)*176.5 lengths = np.ones(100)*10*np.pi card.register_measurement_windows('otto', dict(A=(begins, lengths))) self.assertEqual(set(card._registered_programs.keys()), {'empty', 'otto'}) self.assertEqual(card._registered_programs['empty'].masks(lambda x: x), []) [(result_begins, result_lengths)] = card._registered_programs['otto'].masks(lambda _, b, l: (b, l)) expected_begins = np.rint(begins / 10).astype(dtype=np.uint64) np.testing.assert_equal(result_begins, expected_begins) # pi ist genau 3 np.testing.assert_equal(result_lengths if isinstance(result_lengths, np.ndarray) else result_lengths.as_ndarray(), 3)
def test_add_mask_prototype(self): card = AlazarCard(None) card.register_mask_for_channel('M', 3, 'auto') self.assertEqual(card._mask_prototypes, dict(M=(3, 'auto'))) with self.assertRaises(ValueError): card.register_mask_for_channel('M', 'A', 'auto') with self.assertRaises(NotImplementedError): card.register_mask_for_channel('M', 1, 'periodic')
def test_make_mask(self): card = AlazarCard(None) card.register_mask_for_channel('M', 3, 'auto') begins = np.arange(15, dtype=np.uint64)*16 lengths = 1+np.arange(15, dtype=np.uint64) with self.assertRaises(KeyError): card._make_mask('N', begins, lengths) with self.assertRaises(ValueError): card._make_mask('M', begins, lengths*3) mask = card._make_mask('M', begins, lengths) self.assertEqual(mask.identifier, 'M') np.testing.assert_equal(mask.begin, begins) np.testing.assert_equal(mask.length, lengths) self.assertEqual(mask.channel, 3)
def test_arm_operation(self): raw_card = dummy_modules.dummy_atsaverage.core.AlazarCard() card = AlazarCard(raw_card) card.register_mask_for_channel('A', 3, 'auto') card.register_mask_for_channel('B', 1, 'auto') card.register_operations('otto', []) card.config = dummy_modules.dummy_atsaverage.config.ScanlineConfiguration() with self.assertRaisesRegex(RuntimeError, 'No operations'): card.arm_program('otto') card.register_operations('otto', ['asd']) with self.assertRaisesRegex(RuntimeError, "No masks"): card.arm_program('otto') begins = np.arange(100) * 176.5 lengths = np.ones(100) * 10 * np.pi card.register_measurement_windows('otto', dict(A=(begins, lengths))) card.config.totalRecordSize = 17 with self.assertRaisesRegex(ValueError, "total record size is smaller than needed"): card.arm_program('otto') card.config.totalRecordSize = 0 with mock.patch.object(card.card, 'applyConfiguration') as mock_applyConfiguration: with mock.patch.object(card.card, 'startAcquisition') as mock_startAcquisition: card.arm_program('otto') mock_applyConfiguration.assert_called_once_with(card.config, True) mock_startAcquisition.assert_called_once_with(1) mock_applyConfiguration.reset_mock() mock_startAcquisition.reset_mock() card.arm_program('otto') mock_applyConfiguration.assert_not_called() mock_startAcquisition.assert_called_once_with(1)
def test_mask_prototypes(self): card = AlazarCard(None) self.assertIs(card.mask_prototypes, card._mask_prototypes)
def test_all(self): from qupulse.hardware.feature_awg.tabor import TaborChannelTuple, TaborDevice #import warnings tawg = TaborDevice(r'USB0::0x168C::0x2184::0000216488::INSTR') tchannelpair = TaborChannelTuple(tawg, (1, 2), 'TABOR_AB') tawg.paranoia_level = 2 #warnings.simplefilter('error', Warning) from qupulse.hardware.setup import HardwareSetup, PlaybackChannel, MarkerChannel hardware_setup = HardwareSetup() hardware_setup.set_channel('TABOR_A', PlaybackChannel(tchannelpair, 0)) hardware_setup.set_channel('TABOR_B', PlaybackChannel(tchannelpair, 1)) hardware_setup.set_channel('TABOR_A_MARKER', MarkerChannel(tchannelpair, 0)) hardware_setup.set_channel('TABOR_B_MARKER', MarkerChannel(tchannelpair, 1)) if with_alazar: from qupulse.hardware.dacs.alazar import AlazarCard import atsaverage.server if not atsaverage.server.Server.default_instance.running: atsaverage.server.Server.default_instance.start(key=b'guest') import atsaverage.core alazar = AlazarCard(atsaverage.core.getLocalCard(1, 1)) alazar.register_mask_for_channel('A', 0) alazar.register_mask_for_channel('B', 0) alazar.register_mask_for_channel('C', 0) alazar.config = get_alazar_config() alazar.register_operations('test', get_operations()) window = get_window(atsaverage.core.getLocalCard(1, 1)) hardware_setup.register_dac(alazar) repeated = get_pulse() from qupulse.pulses.sequencing import Sequencer sequencer = Sequencer() sequencer.push(repeated, parameters=dict(n=1000, min=-0.5, max=0.5, tau=192 * 3), channel_mapping={ 'out': 'TABOR_A', 'trigger': 'TABOR_A_MARKER' }, window_mapping=dict(A='A', B='B', C='C')) instruction_block = sequencer.build() hardware_setup.register_program('test', instruction_block) if with_alazar: from atsaverage.masks import PeriodicMask m = PeriodicMask() m.identifier = 'D' m.begin = 0 m.end = 1 m.period = 1 m.channel = 0 alazar._registered_programs['test'].masks.append(m) hardware_setup.arm_program('test') d = 1
def test_arm_operation(self): raw_card = dummy_modules.dummy_atsaverage.core.AlazarCard() card = AlazarCard(raw_card) card.register_mask_for_channel('A', 3, 'auto') card.register_mask_for_channel('B', 1, 'auto') card.register_operations('otto', []) card.config = dummy_modules.dummy_atsaverage.config.ScanlineConfiguration( ) with self.assertRaises(RuntimeError): card.arm_program('otto') card.register_operations('otto', ['asd']) with self.assertRaises(RuntimeError): card.arm_program('otto') begins = np.arange(100) * 176.5 lengths = np.ones(100) * 10 * np.pi card.register_measurement_windows('otto', dict(A=(begins, lengths))) card.config.totalRecordSize = 17 with self.assertRaises(ValueError): card.arm_program('otto') card.config.totalRecordSize = 0 card.arm_program('otto') self.assertEqual(card.config._apply_calls, [(raw_card, True)]) self.assertEqual(card.card._startAcquisition_calls, [1]) card.arm_program('otto') self.assertEqual(card.config._apply_calls, [(raw_card, True)]) self.assertEqual(card.card._startAcquisition_calls, [1, 1])
def exec_test(): import time import numpy as np t = [] names = [] def tic(name): t.append(time.time()) names.append(name) from qupulse.hardware.awgs.tabor import TaborChannelPair, TaborAWGRepresentation tawg = TaborAWGRepresentation(r'USB0::0x168C::0x2184::0000216488::INSTR', reset=True) tchannelpair = TaborChannelPair(tawg, (1, 2), 'TABOR_AB') tawg.paranoia_level = 2 # warnings.simplefilter('error', Warning) from qupulse.hardware.setup import HardwareSetup, PlaybackChannel, MarkerChannel hardware_setup = HardwareSetup() hardware_setup.set_channel('TABOR_A', PlaybackChannel(tchannelpair, 0)) hardware_setup.set_channel('TABOR_B', PlaybackChannel(tchannelpair, 1)) hardware_setup.set_channel('TABOR_A_MARKER', MarkerChannel(tchannelpair, 0)) hardware_setup.set_channel('TABOR_B_MARKER', MarkerChannel(tchannelpair, 1)) if with_alazar: from qupulse.hardware.dacs.alazar import AlazarCard import atsaverage.server if not atsaverage.server.Server.default_instance.running: atsaverage.server.Server.default_instance.start(key=b'guest') import atsaverage.core alazar = AlazarCard(atsaverage.core.getLocalCard(1, 1)) alazar.register_mask_for_channel('A', 0) alazar.config = get_alazar_config() alazar.register_operations('test', get_operations()) window = get_window(atsaverage.core.getLocalCard(1, 1)) hardware_setup.register_dac(alazar) repeated = get_pulse() from qupulse.pulses.sequencing import Sequencer tic('init') sequencer = Sequencer() sequencer.push(repeated, parameters=dict(n=10000, tau=1920, U=0.5), channel_mapping={'out': 'TABOR_A', 'trigger': 'TABOR_A_MARKER'}, window_mapping=dict(A='A')) instruction_block = sequencer.build() tic('sequence') hardware_setup.register_program('test', instruction_block) tic('register') if with_alazar: from atsaverage.masks import PeriodicMask m = PeriodicMask() m.identifier = 'D' m.begin = 0 m.end = 1 m.period = 1 m.channel = 0 alazar._registered_programs['test'].masks.append(m) tic('per_mask') hardware_setup.arm_program('test') tic('arm') for d, name in zip(np.diff(np.asarray(t)), names[1:]): print(name, d) d = 1