Esempio n. 1
0
 def test_get_updated_channel_mapping(self):
     template = DummyPulseTemplate(defined_channels={'foo', 'bar', 'brotzeit'})
     st = MappingPulseTemplate(template, channel_mapping={'bar': 'kneipe', 'brotzeit': None})
     with self.assertRaises(KeyError):
         st.get_updated_channel_mapping(dict())
     self.assertEqual(st.get_updated_channel_mapping({'kneipe': 'meas1',
                                                      'foo': 'meas2',
                                                      'troet': 'meas3'}),
                      {'foo': 'meas2',
                       'bar': 'meas1',
                       'brotzeit': None})
    def test_build_sequence(self):
        measurement_mapping = {'meas1': 'meas2'}
        parameter_mapping = {'t': 'k'}

        template = DummyPulseTemplate(
            measurement_names=set(measurement_mapping.keys()),
            parameter_names=set(parameter_mapping.keys()))
        st = MappingPulseTemplate(template,
                                  parameter_mapping=parameter_mapping,
                                  measurement_mapping=measurement_mapping)
        sequencer = DummySequencer()
        block = DummyInstructionBlock()
        pre_parameters = {'k': ConstantParameter(5)}
        pre_measurement_mapping = {'meas2': 'meas3'}
        pre_channel_mapping = {'default': 'A'}
        conditions = dict(a=True)
        st.build_sequence(sequencer, pre_parameters, conditions,
                          pre_measurement_mapping, pre_channel_mapping, block)

        self.assertEqual(template.build_sequence_calls, 1)
        forwarded_args = template.build_sequence_arguments[0]
        self.assertEqual(forwarded_args[0], sequencer)
        self.assertEqual(forwarded_args[1], st.map_parameters(pre_parameters))
        self.assertEqual(forwarded_args[2], conditions)
        self.assertEqual(
            forwarded_args[3],
            st.get_updated_measurement_mapping(pre_measurement_mapping))
        self.assertEqual(forwarded_args[4],
                         st.get_updated_channel_mapping(pre_channel_mapping))
        self.assertEqual(forwarded_args[5], block)
    def test_create_program_subtemplate_none(self) -> None:
        measurement_mapping = {'meas1': 'meas2'}
        parameter_mapping = {'t': 'k'}
        channel_mapping = {'B': 'default'}

        template = DummyPulseTemplate(measurements=[('meas1', 0, 1)],
                                      measurement_names={'meas1'},
                                      defined_channels={'B'},
                                      waveform=None,
                                      duration=0,
                                      parameter_names={'t'})
        st = MappingPulseTemplate(template,
                                  parameter_mapping=parameter_mapping,
                                  measurement_mapping=measurement_mapping,
                                  channel_mapping=channel_mapping)

        pre_parameters = {'k': ConstantParameter(5)}
        pre_measurement_mapping = {'meas2': 'meas3'}
        pre_channel_mapping = {'default': 'A'}

        program = Loop()
        st._internal_create_program(
            parameters=pre_parameters,
            measurement_mapping=pre_measurement_mapping,
            channel_mapping=pre_channel_mapping,
            to_single_waveform=set(),
            global_transformation=None,
            parent_loop=program)

        self.assertEqual(1, len(template.create_program_calls))
        self.assertEqual(
            (st.map_parameters(pre_parameters),
             st.get_updated_measurement_mapping(pre_measurement_mapping),
             st.get_updated_channel_mapping(pre_channel_mapping), program),
            template.create_program_calls[-1])

        self.assertEqual(1, program.repetition_count)
        self.assertEqual(0, len(program.children))
        self.assertIsNone(program._measurements)

        # ensure same result as from Sequencer
        sequencer = Sequencer()
        sequencer.push(st,
                       parameters=pre_parameters,
                       conditions={},
                       window_mapping=pre_measurement_mapping,
                       channel_mapping=pre_channel_mapping)
        block = sequencer.build()
        program_old = MultiChannelProgram(
            block, channels={'A'}).programs[frozenset({'A'})]
        self.assertEqual(program_old, program)
    def test_create_program(self) -> None:
        measurement_mapping = {'meas1': 'meas2'}
        parameter_mapping = {'t': 'k'}
        channel_mapping = {'B': 'default'}
        global_transformation = TransformationStub()
        to_single_waveform = {'tom', 'jerry'}

        template = DummyPulseTemplate(measurements=[('meas1', 0, 1)],
                                      measurement_names={'meas1'},
                                      defined_channels={'B'},
                                      waveform=DummyWaveform(duration=2.0),
                                      duration=2,
                                      parameter_names={'t'})
        st = MappingPulseTemplate(template,
                                  parameter_mapping=parameter_mapping,
                                  measurement_mapping=measurement_mapping,
                                  channel_mapping=channel_mapping)

        pre_parameters = {'k': ConstantParameter(5)}
        pre_measurement_mapping = {'meas2': 'meas3'}
        pre_channel_mapping = {'default': 'A'}

        program = Loop()
        expected_inner_args = dict(
            parameters=st.map_parameters(pre_parameters),
            measurement_mapping=st.get_updated_measurement_mapping(
                pre_measurement_mapping),
            channel_mapping=st.get_updated_channel_mapping(
                pre_channel_mapping),
            to_single_waveform=to_single_waveform,
            global_transformation=global_transformation,
            parent_loop=program)

        with mock.patch.object(template,
                               '_create_program') as inner_create_program:
            st._internal_create_program(
                parameters=pre_parameters,
                measurement_mapping=pre_measurement_mapping,
                channel_mapping=pre_channel_mapping,
                to_single_waveform=to_single_waveform,
                global_transformation=global_transformation,
                parent_loop=program)
            inner_create_program.assert_called_once_with(**expected_inner_args)

        # as we mock the inner function there shouldnt be any changes
        self.assertEqual(program, Loop())
Esempio n. 5
0
    def test_create_program_subtemplate_none(self) -> None:
        measurement_mapping = {'meas1': 'meas2'}
        parameter_mapping = {'t': 'k'}
        channel_mapping = {'B': 'default'}
        volatile = {'t'}

        template = DummyPulseTemplate(measurements=[('meas1', 0, 1)],
                                      measurement_names={'meas1'},
                                      defined_channels={'B'},
                                      waveform=None,
                                      duration=0,
                                      parameter_names={'t'})
        st = MappingPulseTemplate(template,
                                  parameter_mapping=parameter_mapping,
                                  measurement_mapping=measurement_mapping,
                                  channel_mapping=channel_mapping)

        pre_scope = DictScope.from_kwargs(k=5, volatile=volatile)
        pre_measurement_mapping = {'meas2': 'meas3'}
        pre_channel_mapping = {'default': 'A'}

        program = Loop()
        st._internal_create_program(
            scope=pre_scope,
            measurement_mapping=pre_measurement_mapping,
            channel_mapping=pre_channel_mapping,
            to_single_waveform=set(),
            global_transformation=None,
            parent_loop=program)

        self.assertEqual(1, len(template.create_program_calls))
        self.assertEqual(
            (st.map_scope(pre_scope),
             st.get_updated_measurement_mapping(pre_measurement_mapping),
             st.get_updated_channel_mapping(pre_channel_mapping), program),
            template.create_program_calls[-1])

        self.assertEqual(1, program.repetition_count)
        self.assertEqual(0, len(program.children))
        self.assertIsNone(program._measurements)