Exemplo n.º 1
0
    def test_schedule_generator_supports_parameter_expressions(self):
        """Test expression-based schedule generator functionalty."""

        t_param = Parameter('t')
        amp = 1.0

        def test_func(dur: ParameterExpression, t_val: int):
            dur_bound = dur.bind({t_param: t_val})
            sched = Schedule()
            sched += Play(library.constant(int(float(dur_bound)), amp),
                          DriveChannel(0))
            return sched

        expected_sched = Schedule()
        expected_sched += Play(library.constant(10, amp), DriveChannel(0))

        inst_map = InstructionScheduleMap()
        inst_map.add('f', (0, ), test_func)
        self.assertEqual(inst_map.get('f', (0, ), dur=2 * t_param, t_val=5),
                         expected_sched)

        self.assertEqual(inst_map.get_parameters('f', (0, )), (
            'dur',
            't_val',
        ))
Exemplo n.º 2
0
    def test_parameterized_schedule(self):
        """Test adding parameterized schedule."""
        converter = QobjToInstructionConverter([], buffer=0)
        qobj = PulseQobjInstruction(name='pv', ch='u1', t0=10, val='P2*cos(np.pi*P1)')
        converted_instruction = converter(qobj)

        inst_map = InstructionScheduleMap()

        inst_map.add('pv_test', 0, converted_instruction)
        self.assertEqual(inst_map.get_parameters('pv_test', 0), ('P1', 'P2'))

        sched = inst_map.get('pv_test', 0, P1=0, P2=-1)
        self.assertEqual(sched.instructions[0][-1].command.value, -1)
        with self.assertRaises(PulseError):
            inst_map.get('pv_test', 0, 0, P1=-1)
        with self.assertRaises(PulseError):
            inst_map.get('pv_test', 0, P1=1, P2=2, P3=3)
Exemplo n.º 3
0
    def test_schedule_generator(self):
        """Test schedule generator functionalty."""

        x_test = 10
        amp_test = 1.0

        def test_func(x):
            sched = Schedule()
            sched += Play(library.constant(int(x), amp_test), DriveChannel(0))
            return sched

        ref_sched = Schedule()
        ref_sched += Play(library.constant(x_test, amp_test), DriveChannel(0))

        inst_map = InstructionScheduleMap()
        inst_map.add('f', (0,), test_func)
        self.assertEqual(inst_map.get('f', (0,), x_test), ref_sched)

        self.assertEqual(inst_map.get_parameters('f', (0,)), ('x',))
Exemplo n.º 4
0
    def test_schedule_generator(self):
        """Test schedule generator functionalty."""

        dur_val = 10
        amp = 1.0

        def test_func(dur: int):
            sched = Schedule()
            sched += Play(library.constant(int(dur), amp), DriveChannel(0))
            return sched

        expected_sched = Schedule()
        expected_sched += Play(library.constant(dur_val, amp), DriveChannel(0))

        inst_map = InstructionScheduleMap()
        inst_map.add('f', (0, ), test_func)
        self.assertEqual(inst_map.get('f', (0, ), dur_val), expected_sched)

        self.assertEqual(inst_map.get_parameters('f', (0, )), ('dur', ))