Exemplo n.º 1
0
 def test_create_program_declaration_parameter_value_not_whole(
         self) -> None:
     repetitions = "foo"
     body = DummyPulseTemplate(duration=2.0,
                               waveform=DummyWaveform(duration=2.0))
     t = RepetitionPulseTemplate(body,
                                 repetitions,
                                 parameter_constraints=['foo<9'])
     scope = DictScope.from_kwargs(foo=(3.3))
     measurement_mapping = dict(moth='fire')
     channel_mapping = dict(asd='f')
     children = [Loop(waveform=DummyWaveform(duration=0))]
     program = Loop(children=children)
     with self.assertRaises(ParameterNotIntegerException):
         t._internal_create_program(scope=scope,
                                    measurement_mapping=measurement_mapping,
                                    channel_mapping=channel_mapping,
                                    to_single_waveform=set(),
                                    global_transformation=None,
                                    parent_loop=program)
     self.assertFalse(body.create_program_calls)
     self.assertEqual(1, program.repetition_count)
     self.assertEqual(children, list(program.children))
     self.assertIsNone(program.waveform)
     self.assert_measurement_windows_equal(
         {}, program.get_measurement_windows())
Exemplo n.º 2
0
    def test_create_program_rep_count_neg_declaration_with_measurements(
            self) -> None:
        repetitions = "foo"
        body_program = Loop(waveform=DummyWaveform(duration=1.0))
        body = DummyPulseTemplate(duration=2.0, program=body_program)

        # suppress warning about 0 repetitions on construction here, we are only interested in correct behavior during sequencing (i.e., do nothing)
        with warnings.catch_warnings(record=True):
            t = RepetitionPulseTemplate(body,
                                        repetitions,
                                        measurements=[('moth', 0, 'meas_end')])

        scope = DictScope.from_kwargs(foo=-1, meas_end=7.1)
        measurement_mapping = dict(moth='fire')
        channel_mapping = dict(asd='f')

        program = Loop()
        t._internal_create_program(scope=scope,
                                   measurement_mapping=measurement_mapping,
                                   channel_mapping=channel_mapping,
                                   to_single_waveform=set(),
                                   global_transformation=None,
                                   parent_loop=program)
        self.assertFalse(body.create_program_calls)
        self.assertFalse(program.children)
        self.assertEqual(1, program.repetition_count)
        self.assertEqual(None, program._measurements)
Exemplo n.º 3
0
    def test_create_program_declaration_success(self) -> None:
        repetitions = "foo"
        body = DummyPulseTemplate(duration=2.0,
                                  waveform=DummyWaveform(
                                      duration=2, defined_channels={'A'}))
        t = RepetitionPulseTemplate(body,
                                    repetitions,
                                    parameter_constraints=['foo<9'])
        scope = DictScope.from_kwargs(foo=3)
        measurement_mapping = dict(moth='fire')
        channel_mapping = dict(asd='f')
        program = Loop()
        t._internal_create_program(scope=scope,
                                   measurement_mapping=measurement_mapping,
                                   channel_mapping=channel_mapping,
                                   to_single_waveform=set(),
                                   global_transformation=None,
                                   parent_loop=program)

        self.assertEqual(1, program.repetition_count)
        self.assertEqual(1, len(program.children))
        internal_loop = program.children[0]  # type: Loop
        self.assertEqual(scope[repetitions], internal_loop.repetition_count)

        self.assertEqual(1, len(internal_loop))
        self.assertEqual(
            (scope, measurement_mapping, channel_mapping, internal_loop),
            body.create_program_calls[-1])
        self.assertEqual(body.waveform, internal_loop[0].waveform)

        self.assert_measurement_windows_equal(
            {}, program.get_measurement_windows())
Exemplo n.º 4
0
    def test_internal_create_program(self):
        wf = DummyWaveform(duration=2.)
        body = PulseTemplateStub()

        rpt = RepetitionPulseTemplate(body,
                                      'n_rep*mul',
                                      measurements=[('m', 'a', 'b')])

        scope = DictScope.from_kwargs(n_rep=3,
                                      mul=2,
                                      a=.1,
                                      b=.2,
                                      irrelevant=42)
        measurement_mapping = {'m': 'l'}
        channel_mapping = {'x': 'Y'}
        global_transformation = TransformationStub()
        to_single_waveform = {'to', 'single', 'waveform'}

        program = Loop()
        expected_program = Loop(
            children=[Loop(children=[Loop(waveform=wf)], repetition_count=6)],
            measurements=[('l', .1, .2)])

        real_relevant_parameters = dict(n_rep=3, mul=2, a=0.1, b=0.2)

        with mock.patch.object(body,
                               '_create_program',
                               wraps=get_appending_internal_create_program(
                                   wf,
                                   always_append=True)) as body_create_program:
            with mock.patch.object(rpt, 'validate_scope') as validate_scope:
                with mock.patch.object(
                        rpt, 'get_repetition_count_value',
                        return_value=6) as get_repetition_count_value:
                    with mock.patch.object(rpt,
                                           'get_measurement_windows',
                                           return_value=[('l', .1, .2)
                                                         ]) as get_meas:
                        rpt._internal_create_program(
                            scope=scope,
                            measurement_mapping=measurement_mapping,
                            channel_mapping=channel_mapping,
                            global_transformation=global_transformation,
                            to_single_waveform=to_single_waveform,
                            parent_loop=program)

                        self.assertEqual(program, expected_program)
                        body_create_program.assert_called_once_with(
                            scope=scope,
                            measurement_mapping=measurement_mapping,
                            channel_mapping=channel_mapping,
                            global_transformation=global_transformation,
                            to_single_waveform=to_single_waveform,
                            parent_loop=program.children[0])
                        validate_scope.assert_called_once_with(scope)
                        get_repetition_count_value.assert_called_once_with(
                            scope)
                        get_meas.assert_called_once_with(
                            scope, measurement_mapping)
Exemplo n.º 5
0
    def test_create_program_constant_success_measurements(self) -> None:
        repetitions = 3
        body = DummyPulseTemplate(duration=2.0,
                                  waveform=DummyWaveform(
                                      duration=2, defined_channels={'A'}),
                                  measurements=[('b', 0, 1)])
        t = RepetitionPulseTemplate(body,
                                    repetitions,
                                    parameter_constraints=['foo<9'],
                                    measurements=[('my', 2, 2)])
        scope = DictScope.from_mapping({'foo': 8})
        measurement_mapping = {'my': 'thy', 'b': 'b'}
        channel_mapping = {}
        program = Loop()
        t._internal_create_program(scope=scope,
                                   measurement_mapping=measurement_mapping,
                                   channel_mapping=channel_mapping,
                                   to_single_waveform=set(),
                                   global_transformation=None,
                                   parent_loop=program)

        self.assertEqual(1, len(program.children))
        internal_loop = program[0]  # type: Loop
        self.assertEqual(repetitions, internal_loop.repetition_count)

        self.assertEqual(1, len(internal_loop))
        self.assertEqual(
            (scope, measurement_mapping, channel_mapping, internal_loop),
            body.create_program_calls[-1])
        self.assertEqual(body.waveform, internal_loop[0].waveform)

        self.assert_measurement_windows_equal(
            {
                'b': ([0, 2, 4], [1, 1, 1]),
                'thy': ([2], [2])
            }, program.get_measurement_windows())

        # done in MultiChannelProgram
        program.cleanup()

        self.assert_measurement_windows_equal(
            {
                'b': ([0, 2, 4], [1, 1, 1]),
                'thy': ([2], [2])
            }, program.get_measurement_windows())
Exemplo n.º 6
0
 def test_create_program_none_subprogram(self) -> None:
     repetitions = "foo"
     body = DummyPulseTemplate(duration=0.0, waveform=None)
     t = RepetitionPulseTemplate(body,
                                 repetitions,
                                 parameter_constraints=['foo<9'])
     scope = DictScope.from_kwargs(foo=3)
     measurement_mapping = dict(moth='fire')
     channel_mapping = dict(asd='f')
     program = Loop()
     t._internal_create_program(scope=scope,
                                measurement_mapping=measurement_mapping,
                                channel_mapping=channel_mapping,
                                to_single_waveform=set(),
                                global_transformation=None,
                                parent_loop=program)
     self.assertFalse(program.children)
     self.assertEqual(1, program.repetition_count)
     self.assertEqual(None, program._measurements)
Exemplo n.º 7
0
    def test_create_program_declaration_success_appended_measurements(
            self) -> None:
        repetitions = "foo"
        body = DummyPulseTemplate(duration=2.0,
                                  waveform=DummyWaveform(duration=2),
                                  measurements=[('b', 0, 1)])
        t = RepetitionPulseTemplate(body,
                                    repetitions,
                                    parameter_constraints=['foo<9'],
                                    measurements=[('moth', 0, 'meas_end')])
        scope = DictScope.from_kwargs(foo=3, meas_end=7.1)
        measurement_mapping = dict(moth='fire', b='b')
        channel_mapping = dict(asd='f')
        children = [Loop(waveform=DummyWaveform(duration=0))]
        program = Loop(children=children,
                       measurements=[('a', [0], [1])],
                       repetition_count=2)

        t._internal_create_program(scope=scope,
                                   measurement_mapping=measurement_mapping,
                                   channel_mapping=channel_mapping,
                                   to_single_waveform=set(),
                                   global_transformation=None,
                                   parent_loop=program)

        self.assertEqual(2, program.repetition_count)
        self.assertEqual(2, len(program.children))
        self.assertIs(program.children[0], children[0])
        internal_loop = program.children[1]  # type: Loop
        self.assertEqual(scope[repetitions], internal_loop.repetition_count)

        self.assertEqual(1, len(internal_loop))
        self.assertEqual(
            (scope, measurement_mapping, channel_mapping, internal_loop),
            body.create_program_calls[-1])
        self.assertEqual(body.waveform, internal_loop[0].waveform)

        self.assert_measurement_windows_equal(
            {
                'fire': ([0, 6], [7.1, 7.1]),
                'b': ([0, 2, 4, 6, 8, 10], [1, 1, 1, 1, 1, 1]),
                'a': ([0], [1])
            }, program.get_measurement_windows())
Exemplo n.º 8
0
    def test_create_program_constant_measurement_mapping_failure(self) -> None:
        repetitions = "foo"
        body = DummyPulseTemplate(duration=2.0,
                                  waveform=DummyWaveform(duration=2.0),
                                  measurements=[('b', 0, 1)])
        t = RepetitionPulseTemplate(body,
                                    repetitions,
                                    parameter_constraints=['foo<9'],
                                    measurements=[('a', 0, 1)])
        scope = DictScope.from_kwargs(foo=3)
        measurement_mapping = dict()
        channel_mapping = dict(asd='f')
        children = [Loop(waveform=DummyWaveform(duration=0))]
        program = Loop(children=children)
        with self.assertRaises(KeyError):
            t._internal_create_program(scope=scope,
                                       measurement_mapping=measurement_mapping,
                                       channel_mapping=channel_mapping,
                                       to_single_waveform=set(),
                                       global_transformation=None,
                                       parent_loop=program)

        # test for failure on child level
        measurement_mapping = dict(a='a')
        with self.assertRaises(KeyError):
            t._internal_create_program(scope=scope,
                                       measurement_mapping=measurement_mapping,
                                       channel_mapping=channel_mapping,
                                       to_single_waveform=set(),
                                       global_transformation=None,
                                       parent_loop=program)
        self.assertFalse(body.create_program_calls)
        self.assertEqual(1, program.repetition_count)
        self.assertEqual(children, list(program.children))
        self.assertIsNone(program.waveform)
        self.assert_measurement_windows_equal(
            {}, program.get_measurement_windows())