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, []) expected_begins = np.rint(begins / 10).astype(dtype=np.uint64) np.testing.assert_equal( card._registered_programs['otto'].masks[0].begin, expected_begins) # pi ist genau 3 length = card._registered_programs['otto'].masks[0].length np.testing.assert_equal( length if isinstance(length, np.ndarray) else length.as_ndarray(), 3) self.assertEqual(card._registered_programs['otto'].masks[0].channel, 3) self.assertEqual(card._registered_programs['otto'].masks[0].identifier, 'A')
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 exec_test(): import time import numpy as np t = [] names = [] def tic(name): t.append(time.time()) names.append(name) from qctoolkit.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 qctoolkit.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 qctoolkit.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 qctoolkit.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
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 test_mask_prototypes(self): card = AlazarCard(None) self.assertIs(card.mask_prototypes, card._mask_prototypes)
def test_all(self): from qctoolkit.hardware.awgs.tabor import TaborChannelPair, TaborAWGRepresentation #import warnings tawg = TaborAWGRepresentation(r'USB0::0x168C::0x2184::0000216488::INSTR') tchannelpair = TaborChannelPair(tawg, (1, 2), 'TABOR_AB') tawg.paranoia_level = 2 #warnings.simplefilter('error', Warning) from qctoolkit.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 qctoolkit.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 qctoolkit.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