Esempio n. 1
0
    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)
Esempio n. 2
0
    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_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
Esempio n. 4
0
#%%
""" Create a program dnp with the number of pulse repetitions as volatile parameters """

sample_rate = awg_channel.sample_rate / 10**9
n_quant = 192
t_quant = n_quant / sample_rate

dnp_prog = dnp.create_program(parameters=dict(tend=float(t_quant), ta=float(t_quant/3), tb=float(2*t_quant/3),
                                              va=0.12, vb=0.25, n_minus=3, n_zero=3, n_plus=3),
                              channel_mapping={'X': '{}_A'.format(awg_name), 'Y': '{}_B'.format(awg_name)},
                              volatile={'n_minus', 'n_zero', 'n_plus'})
dnp_prog.cleanup()

#%%
""" Upload this program to the AWG """

hardware_setup.register_program('dnp', dnp_prog)
hardware_setup.arm_program('dnp')

#%%
""" Run initial program """

awg_channel.run_current_program()

#%%
""" Change volatile parameters to new values and run the modified program """

hardware_setup.update_parameters('dnp', dict(n_zero=1, n_plus=5))
awg_channel.run_current_program()
class PulseLoadingAndSequencingHelper:
    def __init__(self, data_folder, pulse_name):
        self.data_folder = data_folder
        self.pulse_name = pulse_name

        self.parameters = self.load_json('parameters.json')
        self.window_mapping = self.load_json('measurement_mapping.json')
        self.channel_mapping = self.load_json('channel_mapping.json')
        self.preparation_commands = self.load_json('preparation_commands.json')

        expected_binary_programs = self.load_json('binary_programs.json')
        if expected_binary_programs:
            self.expected_binary_programs = [
                PlottableProgram.from_builtin(prog) if prog else None
                for prog in expected_binary_programs
            ]
        else:
            self.expected_binary_programs = None

        self.validate_programs = self.load_function_from_file(
            'binary_program_validation.py', 'validate_programs')
        self.validation_data = self.load_json('binary_program_validation.json')

        self.pulse = None
        self.program = None

        self.simulator_manager = None

        self.hardware_setup = None  # type: HardwareSetup
        self.dac = None  # type: DummyDAC
        self.awg = None  # type: TaborAWGRepresentation

        self.program_AB = None
        self.program_CD = None

    def load_json(self, file_name):
        complete_file_name = os.path.join(self.data_folder, file_name)
        if os.path.exists(complete_file_name):
            with open(complete_file_name, 'r') as file_handle:
                return json.load(file_handle)
        else:
            return None

    def load_function_from_file(self, file_name, function_name):
        full_file_name = os.path.join(self.data_folder, file_name)
        if not os.path.exists(full_file_name):
            return None
        module_name = os.path.normpath(
            os.path.splitext(full_file_name)[0]).replace(os.sep, '.')

        if module_name in sys.modules:
            module = sys.modules[module_name]
        else:
            try:
                spec = importlib.util.spec_from_file_location(
                    module_name, full_file_name)
                module = importlib.util.module_from_spec(spec)
                spec.loader.exec_module(module)
            except ImportError:
                return None
        return getattr(module, function_name, None)

    def deserialize_pulse(self):
        serializer = Serializer(
            FilesystemBackend(os.path.join(self.data_folder, 'pulse_storage')))
        self.pulse = typing.cast(PulseTemplate,
                                 serializer.deserialize(self.pulse_name))

    def deserialize_pulse_2018(self) -> None:
        pulse_storage = PulseStorage(
            FilesystemBackend(
                os.path.join(self.data_folder,
                             'pulse_storage_converted_2018')))
        self.pulse = typing.cast(PulseTemplate, pulse_storage[self.pulse_name])

    def sequence_pulse(self):
        self.program = self.pulse.create_program(
            parameters=self.parameters,
            measurement_mapping=self.window_mapping,
            channel_mapping=self.channel_mapping)

    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 register_program(self):
        self.hardware_setup.register_program(self.pulse_name, self.program)

    def arm_program(self):
        self.hardware_setup.arm_program(self.pulse_name)

    def read_program(self):
        self.program_AB = self.awg.channel_pair_AB.read_complete_program()
        self.program_CD = self.awg.channel_pair_CD.read_complete_program()
        return self.program_AB, self.program_CD
Esempio n. 6
0
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