Ejemplo n.º 1
0
    def __qupulse_template_to_array(sequence, sampling_rate):
        """ Renders a qupulse sequence as array with voltages.

        Args:
            sequence (dict): a waveform is a dictionary with "type" value
            given the used pulse library. The "wave" value should contain
            the actual wave-object.
            sampling_rate (float): The number of samples per second.

        Returns:
            voltages (np.array): The array with voltages generated from the template.
        """
        sequencer = Sequencing()
        template = sequence['wave']
        channels = template.defined_channels
        sequencer.push(
            template,
            dict(),
            channel_mapping={ch: ch
                             for ch in channels},
            window_mapping={w: w
                            for w in template.measurement_names})
        instructions = sequencer.build()
        if not sequencer.has_finished():
            raise PlottingNotPossibleException(template)
        (_, voltages, _) = render(instructions,
                                  sampling_rate / Sequencer.__sec_to_ns)
        return np.array(voltages[next(iter(voltages))])
Ejemplo n.º 2
0
 def test_build_path_o2_m2_i1_t_i1_t_m2_i0_i0_one_element_custom_block_one_element_main_block(self) -> None:
     sequencer = Sequencer()
             
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     
     elem_main = DummySequencingElement(False)
     sequencer.push(elem_main, ps, cs)
     
     target_block = InstructionBlock()
     elem_cstm = DummySequencingElement(False)
     sequencer.push(elem_cstm, ps, cs, target_block=target_block)
     
     sequence = sequencer.build()
     
     self.assertTrue(sequencer.has_finished())
     self.assertIs(elem_main, sequence[0].elem)
     self.assertEqual(ps, elem_main.parameters)
     self.assertEqual(cs, elem_main.conditions)
     self.assertEqual(1, elem_main.requires_stop_call_counter)
     self.assertEqual(1, elem_main.build_call_counter)
     self.assertIs(target_block, elem_cstm.target_block)
     self.assertEqual(ps, elem_cstm.parameters)
     self.assertEqual(cs, elem_cstm.conditions)
     self.assertEqual(1, elem_cstm.requires_stop_call_counter)
     self.assertEqual(1, elem_cstm.build_call_counter)
     self.assertEqual(STOPInstruction(), sequence[1])
     self.assertEqual(2, len(sequence))
Ejemplo n.º 3
0
 def test_build_path_o1_m2_i1_f_i1_f_one_element_custom_and_main_block_requires_stop(self) -> None:
     sequencer = Sequencer()
 
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     wm = {}
     cm = {}
     elem_main = DummySequencingElement(True)
     sequencer.push(elem_main, ps, cs, channel_mapping=cm)
     
     elem_cstm = DummySequencingElement(True)
     target_block = InstructionBlock()
     sequencer.push(elem_cstm, ps, cs, window_mapping=wm, channel_mapping=cm, target_block=target_block)
     
     sequencer.build()
     
     self.assertFalse(sequencer.has_finished())
     self.assertEqual(ps, elem_main.parameters)
     self.assertEqual(cs, elem_main.conditions)
     self.assertEqual(1, elem_main.requires_stop_call_counter)
     self.assertEqual(0, elem_main.build_call_counter)
     self.assertEqual(ps, elem_cstm.parameters)
     self.assertEqual(cs, elem_cstm.conditions)
     self.assertEqual(1, elem_cstm.requires_stop_call_counter)
     self.assertEqual(0, elem_cstm.build_call_counter)
Ejemplo n.º 4
0
 def test_build_path_o2_m2_i1_f_i2_tf_m2_i1_f_i1_f_two_elements_custom_block_last_requires_stop_one_element_requires_stop_main_block(self) -> None:
     sequencer = Sequencer()
             
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     wm = {'foo': 'bar'}
     
     target_block = InstructionBlock()
     elem2 = DummySequencingElement(True)
     sequencer.push(elem2, ps, cs, window_mapping=wm, target_block=target_block)
     
     elem1 = DummySequencingElement(False)
     sequencer.push(elem1, ps, cs, window_mapping=wm, target_block=target_block)
     
     elem_main = DummySequencingElement(True)
     sequencer.push(elem_main, ps, cs)
     
     sequencer.build()
     
     self.assertFalse(sequencer.has_finished())
     self.assertIs(target_block, elem1.target_block)
     self.assertEqual(ps, elem1.parameters)
     self.assertEqual(cs, elem1.conditions)
     self.assertEqual(1, elem1.requires_stop_call_counter)
     self.assertEqual(1, elem1.build_call_counter)
     self.assertEqual(ps, elem2.parameters)
     self.assertEqual(cs, elem2.conditions)
     self.assertEqual(2, elem2.requires_stop_call_counter)
     self.assertEqual(0, elem2.build_call_counter)
     self.assertEqual(ps, elem_main.parameters)
     self.assertEqual(cs, elem_main.conditions)
     self.assertEqual(2, elem_main.requires_stop_call_counter)
     self.assertEqual(0, elem_main.build_call_counter)
Ejemplo n.º 5
0
    def test_build_path_o2_m1_i2_tf_m2_i1_f_i1_f_two_elements_main_block_last_requires_stop_add_one_element_requires_stop_new_block(self) -> None:
        sequencer = Sequencer()
    
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}
        
        new_block = InstructionBlock()
        new_elem = DummySequencingElement(True)
        
        elem1 = DummySequencingElement(False, (new_block, [new_elem]))
        elem2 = DummySequencingElement(True)
        sequencer.push(elem2, ps, cs)
        sequencer.push(elem1, ps, cs)

        instr, stop = sequencer.build()
        
        self.assertFalse(sequencer.has_finished())
        self.assertIs(elem1, instr.elem)
        self.assertEqual(ps, elem1.parameters)
        self.assertEqual(cs, elem1.conditions)
        self.assertEqual(1, elem1.requires_stop_call_counter)
        self.assertEqual(1, elem1.build_call_counter)
        self.assertEqual(ps, elem2.parameters)
        self.assertEqual(cs, elem2.conditions)
        self.assertEqual(2, elem2.requires_stop_call_counter)
        self.assertEqual(0, elem2.build_call_counter)
        self.assertEqual(ps, new_elem.parameters)
        self.assertEqual(cs, new_elem.conditions)
        self.assertEqual(1, new_elem.requires_stop_call_counter)
        self.assertEqual(0, new_elem.build_call_counter)
        self.assertEqual(STOPInstruction(), stop)
Ejemplo n.º 6
0
    def test_build_path_o2_m1_i1_t_m2_i0_i1_f_one_element_main_block_adds_one_element_requires_stop_new_block(self) -> None:
        sequencer = Sequencer()
    
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}
        
        new_block = InstructionBlock()
        new_elem = DummySequencingElement(True)
        
        elem = DummySequencingElement(False, (new_block, [new_elem]))
        sequencer.push(elem, ps, cs)

        sequence = sequencer.build()
        
        self.assertFalse(sequencer.has_finished())
        self.assertIs(elem, sequence[0].elem)
        self.assertEqual(ps, elem.parameters)
        self.assertEqual(cs, elem.conditions)
        self.assertEqual(1, elem.requires_stop_call_counter)
        self.assertEqual(1, elem.build_call_counter)
        self.assertEqual(ps, new_elem.parameters)
        self.assertEqual(cs, new_elem.conditions)
        self.assertEqual(1, new_elem.requires_stop_call_counter)
        self.assertEqual(0, new_elem.build_call_counter)
        self.assertEqual(STOPInstruction(), sequence[1])
        self.assertEqual(2, len(sequence))
Ejemplo n.º 7
0
    def test_build_path_o2_m1_i2_tt_m1_i0_two_elements_main_block(self) -> None:
        sequencer = Sequencer()
    
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}

        elem1 = DummySequencingElement(False)
        elem2 = DummySequencingElement(False)
        sequencer.push(elem2, ps, cs)
        sequencer.push(elem1, ps, cs)

        sequence = sequencer.build()
        
        self.assertTrue(sequencer.has_finished())
        self.assertIs(elem1, sequence[0].elem)
        self.assertEqual(ps, elem1.parameters)
        self.assertEqual(cs, elem1.conditions)
        self.assertEqual(1, elem1.requires_stop_call_counter)
        self.assertEqual(1, elem1.build_call_counter)
        self.assertIs(elem2, sequence[1].elem)
        self.assertEqual(ps, elem2.parameters)
        self.assertEqual(cs, elem2.conditions)
        self.assertEqual(1, elem2.requires_stop_call_counter)
        self.assertEqual(1, elem2.build_call_counter)
        self.assertEqual(STOPInstruction(), sequence[2])
        self.assertEqual(3, len(sequence))
Ejemplo n.º 8
0
    def test_push_float_params(self) -> None:
        sequencer = Sequencer()

        ps = {'foo': 1, 'bar': 7.3}
        cs = {'foo': DummyCondition()}
        elem = DummySequencingElement()
        sequencer.push(elem, ps, cs)
        self.assertFalse(sequencer.has_finished())
        sequencer.build()
        self.assertIsInstance(elem.parameters['foo'], ConstantParameter)
        self.assertIsInstance(elem.parameters['bar'], ConstantParameter)
        self.assertEqual(cs, elem.conditions)
Ejemplo n.º 9
0
 def test_push(self) -> None:
     sequencer = Sequencer()
     
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     wm = {'foo' : 'bar'}
     elem = DummySequencingElement()
     
     sequencer.push(elem, ps, cs, window_mapping=wm)
     self.assertFalse(sequencer.has_finished())
     sequencer.build()
     self.assertEqual(ps, elem.parameters)
Ejemplo n.º 10
0
 def test_build_path_o1_m1_i1_f_single_element_requires_stop_main_block(self) -> None:
     sequencer = Sequencer()
 
     elem = DummySequencingElement(True)
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     sequencer.push(elem, ps, cs)
     sequencer.build()
     
     self.assertFalse(sequencer.has_finished())
     self.assertEqual(ps, elem.parameters)
     self.assertEqual(cs, elem.conditions)
     self.assertEqual(1, elem.requires_stop_call_counter)
     self.assertEqual(0, elem.build_call_counter)
Ejemplo n.º 11
0
 def test_build_path_o2_m2_i2_tt_t_i2_tt_m2_i0_i0_two_elements_custom_block_two_element_main_block(self) -> None:
     sequencer = Sequencer()
             
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     cs = {'foo': DummyCondition()}
     wm = {'foo': 'bar'}
     
     target_block = InstructionBlock()
     elem2 = DummySequencingElement(False)
     sequencer.push(elem2, ps, cs, window_mapping=wm, target_block=target_block)
     
     elem1 = DummySequencingElement(False)
     sequencer.push(elem1, ps, cs, window_mapping=wm, target_block=target_block)
     
     elem_main2 = DummySequencingElement(False)
     sequencer.push(elem_main2, ps, cs)
     
     elem_main1 = DummySequencingElement(False)
     sequencer.push(elem_main1, ps, cs)
     
     sequence = sequencer.build()
     
     self.assertTrue(sequencer.has_finished())
     self.assertIs(target_block, elem1.target_block)
     self.assertEqual(ps, elem1.parameters)
     self.assertEqual(cs, elem1.conditions)
     self.assertEqual(1, elem1.requires_stop_call_counter)
     self.assertEqual(1, elem1.build_call_counter)
     self.assertIs(target_block, elem2.target_block)
     self.assertEqual(ps, elem2.parameters)
     self.assertEqual(cs, elem2.conditions)
     self.assertEqual(1, elem2.requires_stop_call_counter)
     self.assertEqual(1, elem2.build_call_counter)
     self.assertIs(elem_main1, sequence[0].elem)
     self.assertEqual(ps, elem_main1.parameters)
     self.assertEqual(cs, elem_main1.conditions)
     self.assertEqual(1, elem_main1.requires_stop_call_counter)
     self.assertEqual(1, elem_main1.build_call_counter)
     self.assertIs(elem_main2, sequence[1].elem)
     self.assertEqual(ps, elem_main2.parameters)
     self.assertEqual(cs, elem_main2.conditions)
     self.assertEqual(1, elem_main2.requires_stop_call_counter)
     self.assertEqual(1, elem_main2.build_call_counter)
     self.assertEqual(STOPInstruction(), sequence[2])
     self.assertEqual(3, len(sequence))
Ejemplo n.º 12
0
    def test_qupulse_template_to_array_new_style_vs_old_style(self):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore",
                                    category=UserWarning,
                                    message="qupulse")
            warnings.filterwarnings(
                "ignore",
                category=DeprecationWarning,
                message="InstructionBlock API is deprecated")
            period = 1e-3
            amplitude = 1.5
            sampling_rate = 1e9
            sequence = Sequencer.make_sawtooth_wave(amplitude, period)
            template = sequence['wave']
            channels = template.defined_channels
            sequencer = Sequencing()
            sequencer.push(
                template,
                dict(),
                channel_mapping={ch: ch
                                 for ch in channels},
                window_mapping={w: w
                                for w in template.measurement_names})
            instructions = sequencer.build()
            if not sequencer.has_finished():
                raise PlottingNotPossibleException(template)
            (_, voltages_old, _) = render(instructions, sampling_rate / 1e9)

            loop = template.create_program(
                parameters=dict(),
                measurement_mapping={w: w
                                     for w in template.measurement_names},
                channel_mapping={ch: ch
                                 for ch in channels},
                global_transformation=None,
                to_single_waveform=set())

            (_, voltages_new, _) = render(loop, sampling_rate / 1e9)
            self.assertTrue(len(voltages_old) == len(voltages_new))
            self.assertTrue(np.min(voltages_old) == np.min(voltages_old))
            self.assertTrue(np.max(voltages_old) == np.max(voltages_old))
Ejemplo n.º 13
0
    def test_build_path_o2_m2_i0_i1_t_m2_i0_i0_one_element_custom_block(self) -> None:
        sequencer = Sequencer()
                
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}
        wm = {'foo': 'bar'}
        cm = {'A': 'B'}

        target_block = InstructionBlock()
        elem = DummySequencingElement(False)
        sequencer.push(elem, ps, cs, window_mapping=wm, channel_mapping=cm, target_block=target_block)
        
        sequencer.build()
        
        self.assertTrue(sequencer.has_finished())
        self.assertIs(target_block, elem.target_block)
        self.assertEqual(ps, elem.parameters)
        self.assertEqual(cs, elem.conditions)
        self.assertEqual(wm, elem.window_mapping)
        self.assertEqual(cm, elem.channel_mapping)
        self.assertEqual(1, elem.requires_stop_call_counter)
        self.assertEqual(1, elem.build_call_counter)
    def test_table_sequence_sequencer_integration(self) -> None:
        t1 = TablePulseTemplate(entries={'default': [(2, 'foo'), (5, 0)]},
                                measurements=[('foo', 2, 2)])

        t2 = TablePulseTemplate(
            entries={'default': [(4, 0), (4.5, 'bar', 'linear'), (5, 0)]},
            measurements=[('foo', 4, 1)])

        seqt = SequencePulseTemplate(
            MappingPulseTemplate(t1, measurement_mapping={'foo': 'bar'}),
            MappingPulseTemplate(t2, parameter_mapping={'bar': '2 * hugo'}))

        with self.assertRaises(ParameterNotProvidedException):
            t1.requires_stop(dict(), dict())
        with self.assertRaises(ParameterNotProvidedException):
            t2.requires_stop(dict(), dict())
        self.assertFalse(
            seqt.requires_stop(
                {
                    'foo': DummyParameter(),
                    'hugo': DummyParameter()
                }, {}))

        foo = DummyNoValueParameter()
        bar = DummyNoValueParameter()
        sequencer = Sequencer()
        sequencer.push(seqt, {
            'foo': foo,
            'hugo': bar
        },
                       window_mapping=dict(bar='my', foo='thy'),
                       channel_mapping={'default': 'A'})
        instructions = sequencer.build()
        self.assertFalse(sequencer.has_finished())
        self.assertEqual(1, len(instructions))

        # stop after first TablePT
        foo = DummyParameter(value=1.1)
        bar = DummyNoValueParameter()
        sequencer = Sequencer()
        sequencer.push(seqt, {
            'foo': foo,
            'hugo': bar
        },
                       window_mapping=dict(bar='my', foo='thy'),
                       channel_mapping={'default': 'A'})
        block = sequencer.build()
        instructions = block.instructions
        self.assertFalse(sequencer.has_finished())
        self.assertIsInstance(block, AbstractInstructionBlock)
        self.assertEqual(2, len(instructions))
        self.assertEqual(instructions[0], MEASInstruction([('my', 2, 2)]))
        self.assertIsInstance(instructions[1], EXECInstruction)

        # stop before first TablePT
        foo = DummyParameter(value=1.1)
        bar = DummyNoValueParameter()
        sequencer = Sequencer()
        sequencer.push(seqt, {
            'foo': bar,
            'hugo': foo
        },
                       window_mapping=dict(bar='my', foo='thy'),
                       channel_mapping={'default': 'A'})
        instructions = sequencer.build()
        self.assertFalse(sequencer.has_finished())
        self.assertEqual(1, len(instructions))

        foo = DummyParameter(value=1.1)
        bar = DummyParameter(value=-0.2)
        sequencer = Sequencer()
        sequencer.push(seqt, {
            'foo': foo,
            'hugo': bar
        },
                       window_mapping=dict(bar='my', foo='thy'),
                       channel_mapping={'default': 'A'})
        instructions = sequencer.build()
        self.assertTrue(sequencer.has_finished())
        self.assertEqual(4, len(instructions.instructions))

        self.assertEqual(instructions[0], MEASInstruction([('my', 2, 2)]))
        self.assertIsInstance(instructions[1], EXECInstruction)
        self.assertEqual(instructions[2], MEASInstruction([('thy', 4, 1)]))
        self.assertIsInstance(instructions[3], EXECInstruction)
Ejemplo n.º 15
0
 def test_build_path_no_loop_nothing_to_do(self) -> None:
     sequencer = Sequencer()
     
     sequencer.build()
     self.assertTrue(sequencer.has_finished())
Ejemplo n.º 16
0
 def test_initialization(self) -> None:
     sequencer = Sequencer()
     self.assertTrue(sequencer.has_finished())