Ejemplo n.º 1
0
    def test_requires_stop(self) -> None:
        condition = DummyCondition(requires_stop=False)
        conditions = {'foo_cond': condition}
        body = DummyPulseTemplate(requires_stop=False)
        t = WhileLoopPulseTemplate('foo_cond', body)
        self.assertFalse(t.requires_stop({}, conditions))

        condition.requires_stop_ = True
        self.assertTrue(t.requires_stop({}, conditions))

        body.requires_stop_ = True
        condition.requires_stop_ = False
        self.assertFalse(t.requires_stop({}, conditions))
Ejemplo n.º 2
0
    def test_is_interruptable(self) -> None:
        condition = DummyCondition()
        body = DummyPulseTemplate(is_interruptable=False)
        t = WhileLoopPulseTemplate(condition, body)
        self.assertFalse(t.is_interruptable)

        body.is_interruptable_ = True
        self.assertTrue(t.is_interruptable)
Ejemplo n.º 3
0
    def test_parameter_names_and_declarations(self) -> None:
        condition = DummyCondition()
        body = DummyPulseTemplate()
        t = WhileLoopPulseTemplate(condition, body)
        self.assertEqual(body.parameter_names, t.parameter_names)

        body.parameter_names_ = {'foo', 't', 'bar'}
        self.assertEqual(body.parameter_names, t.parameter_names)
Ejemplo n.º 4
0
 def test_integral(self) -> None:
     condition = DummyCondition()
     body = DummyPulseTemplate(defined_channels={'A', 'B'})
     pulse = WhileLoopPulseTemplate(condition, body)
     self.assertEqual(
         {
             'A': ExpressionScalar('nan'),
             'B': ExpressionScalar('nan')
         }, pulse.integral)
Ejemplo n.º 5
0
    def test_get_serialization_data_old(self) -> None:
        # test for deprecated version during transition period, remove after final switch
        with self.assertWarnsRegex(
                DeprecationWarning,
                "deprecated",
                msg=
                "WhileLoopPT does not issue warning for old serialization routines."
        ):
            body = DummyPulseTemplate()
            condition_name = 'foo_cond'
            identifier = 'foo_loop'
            t = WhileLoopPulseTemplate(condition_name,
                                       body,
                                       identifier=identifier)

            serializer = DummySerializer()
            expected_data = dict(body=str(id(body)), condition=condition_name)

            data = t.get_serialization_data(serializer)
            self.assertEqual(expected_data, data)
Ejemplo n.º 6
0
 def test_condition_missing(self) -> None:
     body = DummyPulseTemplate(requires_stop=False)
     t = WhileLoopPulseTemplate('foo_cond', body)
     sequencer = DummySequencer()
     block = DummyInstructionBlock()
     with self.assertRaises(ConditionMissingException):
         t.requires_stop({}, {})
         t.build_sequence(sequencer, {}, {}, {}, block)
Ejemplo n.º 7
0
 def test_build_sequence(self) -> None:
     condition = DummyCondition()
     body = DummyPulseTemplate()
     t = WhileLoopPulseTemplate('foo_cond', body)
     sequencer = DummySequencer()
     block = DummyInstructionBlock()
     parameters = {}
     conditions = {'foo_cond': condition}
     measurement_mapping = {'swag': 'aufdrehen'}
     channel_mapping = {}
     t.build_sequence(sequencer, parameters, conditions,
                      measurement_mapping, channel_mapping, block)
     expected_data = dict(delegator=t,
                          body=body,
                          sequencer=sequencer,
                          parameters=parameters,
                          conditions=conditions,
                          measurement_mapping=measurement_mapping,
                          channel_mapping=channel_mapping,
                          instruction_block=block)
     self.assertEqual(expected_data, condition.loop_call_data)
     self.assertFalse(condition.branch_call_data)
     self.assertFalse(sequencer.sequencing_stacks)
Ejemplo n.º 8
0
    def test_deserialize(self) -> None:
        # test for deprecated version during transition period, remove after final switch
        with self.assertWarnsRegex(
                DeprecationWarning,
                "deprecated",
                msg=
                "WhileLoopPT does not issue warning for old serialization routines."
        ):
            data = dict(identifier='foo_loop',
                        condition='foo_cond',
                        body='bodyDummyPulse')

            # prepare dependencies for deserialization
            serializer = DummySerializer()
            serializer.subelements[data['body']] = DummyPulseTemplate()

            # deserialize
            result = WhileLoopPulseTemplate.deserialize(serializer, **data)

            # compare
            self.assertIs(serializer.subelements[data['body']], result.body)
            self.assertEqual(data['condition'], result.condition)
            self.assertEqual(data['identifier'], result.identifier)
Ejemplo n.º 9
0
 def test_str(self) -> None:
     condition = DummyCondition()
     body = DummyPulseTemplate()
     t = WhileLoopPulseTemplate(condition, body)
     self.assertIsInstance(str(t), str)