def test_table_sequence_sequencer_integration(self) -> None:
        t1 = TablePulseTemplate()
        t1.add_entry(2, 'foo')
        t1.add_entry(5, 0)

        t2 = TablePulseTemplate()
        t2.add_entry(4, 0)
        t2.add_entry(4.5, 'bar', 'linear')
        t2.add_entry(5, 0)

        seqt = SequencePulseTemplate([(t1, {'foo': 'foo'}), (t2, {'bar': '2 * hugo'})], {'foo', '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 = DummyNoValueParameter()
        bar = DummyNoValueParameter()
        sequencer = Sequencer()
        sequencer.push(seqt, {'foo': foo, 'hugo': bar})
        instructions = sequencer.build()
        self.assertFalse(sequencer.has_finished())
        self.assertEqual(1, len(instructions))

        foo = DummyParameter(value=1.1)
        bar = DummyNoValueParameter()
        sequencer = Sequencer()
        sequencer.push(seqt, {'foo': foo, 'hugo': bar})
        instructions = sequencer.build()
        self.assertFalse(sequencer.has_finished())
        self.assertEqual(2, len(instructions))

        foo = DummyParameter(value=1.1)
        bar = DummyNoValueParameter()
        sequencer = Sequencer()
        sequencer.push(seqt, {'foo': bar, 'hugo': foo})
        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})
        instructions = sequencer.build()
        self.assertTrue(sequencer.has_finished())
        self.assertEqual(3, len(instructions))
Beispiel #2
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))
    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()}

        target_block = InstructionBlock()
        elem2 = DummySequencingElement(True)
        sequencer.push(elem2, ps, cs, target_block)

        elem1 = DummySequencingElement(False)
        sequencer.push(elem1, ps, cs, 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)
Beispiel #4
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)

        sequence = sequencer.build()

        self.assertFalse(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.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(), sequence[1])
        self.assertEqual(2, len(sequence))
Beispiel #5
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)

        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))
    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))
    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)

        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))
    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)

        sequence = sequencer.build()

        self.assertFalse(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.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(), sequence[1])
        self.assertEqual(2, len(sequence))
Beispiel #9
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()}

        target_block = InstructionBlock()
        elem2 = DummySequencingElement(True)
        sequencer.push(elem2, ps, cs, target_block)

        elem1 = DummySequencingElement(False)
        sequencer.push(elem1, ps, cs, 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)
Beispiel #10
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()}

        elem_main = DummySequencingElement(True)
        sequencer.push(elem_main, ps, cs)

        elem_cstm = DummySequencingElement(True)
        target_block = InstructionBlock()
        sequencer.push(elem_cstm, ps, cs, 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)
    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_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))
    def test_push(self) -> None:
        sequencer = Sequencer()

        ps = {"foo": ConstantParameter(1), "bar": ConstantParameter(7.3)}
        cs = {"foo": DummyCondition()}
        elem = DummySequencingElement()

        sequencer.push(elem, ps, cs)
        self.assertFalse(sequencer.has_finished())
        sequencer.build()
        self.assertEqual(ps, elem.parameters)
Beispiel #14
0
    def test_push(self) -> None:
        sequencer = Sequencer()

        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}
        elem = DummySequencingElement()

        sequencer.push(elem, ps, cs)
        self.assertFalse(sequencer.has_finished())
        sequencer.build()
        self.assertEqual(ps, elem.parameters)
Beispiel #15
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)
    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)
Beispiel #17
0
def plot(pulse: PulseTemplate,
         parameters: Dict[str, Parameter]=None,
         sample_rate: int=10) -> None: # pragma: no cover
    """Plot a pulse using matplotlib.

    The given pulse will first be sequenced using the Sequencer class. The resulting
    InstructionSequence will be converted into sampled value arrays using the Plotter class. These
    arrays are then plotted in a matplotlib figure.

    Args:
        pulse (PulseTemplate): The pulse to be plotted.
        parameters (Dict(str -> Parameter)): An optional mapping of parameter names to Parameter
            objects.
        sample_rate (int): The rate with which the waveforms are sampled for the plot in
            samples per time unit. (default = 10)
    Raises:
        PlottingNotPossibleException if the sequencing is interrupted before it finishes, e.g.,
            because a parameter value could not be evaluated
        all Exceptions possibly raised during sequencing
    """
    if parameters is None:
        parameters = dict()
    plotter = Plotter(sample_rate=sample_rate)
    sequencer = Sequencer()
    sequencer.push(pulse, parameters)
    sequence = sequencer.build()
    if not sequencer.has_finished():
        raise PlottingNotPossibleException(pulse)
    times, voltages = plotter.render(sequence)

    # plot!
    figure = plt.figure()
    ax = figure.add_subplot(111)
    for index, channel in enumerate(voltages):
        ax.step(times, channel, where='post', label='channel {}'.format(index))

    ax.legend()

    max_voltage = max(max(channel) for channel in voltages)
    min_voltage = min(min(channel) for channel in voltages)

    # add some margins in the presentation
    plt.plot()
    plt.xlim(-0.5, times[-1] + 0.5)
    plt.ylim(min_voltage - 0.5, max_voltage + 0.5)
    plt.xlabel('Time in ns')
    plt.ylabel('Voltage')

    if pulse.identifier:
        plt.title(pulse.identifier)

    figure.show()
    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)
Beispiel #19
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)
    def test_build_path_o1_m2_i1_f_i0_one_element_custom_block_requires_stop(self) -> None:
        sequencer = Sequencer()

        elem = DummySequencingElement(True)
        ps = {"foo": ConstantParameter(1), "bar": ConstantParameter(7.3)}
        cs = {"foo": DummyCondition()}
        target_block = InstructionBlock()
        sequencer.push(elem, ps, cs, target_block)
        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)
    def test_build_path_o1_m2_i1_f_i0_one_element_custom_block_requires_stop(
            self) -> None:
        sequencer = Sequencer()

        elem = DummySequencingElement(True)
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        cs = {'foo': DummyCondition()}
        wm = {}
        target_block = InstructionBlock()
        sequencer.push(elem,
                       ps,
                       cs,
                       window_mapping=wm,
                       target_block=target_block)
        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)
Beispiel #22
0
def plot(pulse: PulseTemplate,
         parameters: Dict[str, Parameter] = None,
         sample_rate: int = 10,
         axes: Any = None,
         show: bool = True,
         plot_channels=None) -> Any:  # pragma: no cover
    """Plot a pulse using matplotlib.

    The given pulse will first be sequenced using the Sequencer class. The resulting
    InstructionSequence will be converted into sampled value arrays using the Plotter class. These
    arrays are then plotted in a matplotlib figure.

    Args:
        pulse: The pulse to be plotted.
        parameters: An optional mapping of parameter names to Parameter
            objects.
        sample_rate: The rate with which the waveforms are sampled for the plot in
            samples per time unit. (default = 10)
        axes: matplotlib Axes object the pulse will be drawn into if provided
        show: If true, the figure will be shown
    Returns:
        matplotlib.pyplot.Figure instance in which the pulse is rendered
    Raises:
        PlottingNotPossibleException if the sequencing is interrupted before it finishes, e.g.,
            because a parameter value could not be evaluated
        all Exceptions possibly raised during sequencing
    """
    from matplotlib import pyplot as plt

    channels = pulse.defined_channels

    if parameters is None:
        parameters = dict()
    sequencer = Sequencer()
    sequencer.push(pulse,
                   parameters,
                   channel_mapping={ch: ch
                                    for ch in channels},
                   window_mapping={w: w
                                   for w in pulse.measurement_names})
    sequence = sequencer.build()
    if not sequencer.has_finished():
        raise PlottingNotPossibleException(pulse)
    times, voltages = render(sequence, sample_rate)

    if axes is None:
        # plot to figure
        figure = plt.figure()
        axes = figure.add_subplot(111)
    for ch_name, voltage in voltages.items():
        if plot_channels is None or ch_name in plot_channels:
            axes.step(times,
                      voltage,
                      where='post',
                      label='channel {}'.format(ch_name))

    axes.legend()

    max_voltage = max(max(channel) for channel in voltages.values())
    min_voltage = min(min(channel) for channel in voltages.values())

    # add some margins in the presentation
    plt.plot()
    plt.xlim(-0.5, times[-1] + 0.5)
    plt.ylim(min_voltage - 0.5, max_voltage + 0.5)
    plt.xlabel('Time in ns')
    plt.ylabel('Voltage')

    if pulse.identifier:
        plt.title(pulse.identifier)

    if show:
        axes.get_figure().show()
    return axes.get_figure()
Beispiel #23
0
    def test_build_path_no_loop_nothing_to_do(self) -> None:
        sequencer = Sequencer()

        sequencer.build()
        self.assertTrue(sequencer.has_finished())
 def test_initialization(self) -> None:
     sequencer = Sequencer()
     self.assertTrue(sequencer.has_finished())
    def test_build_path_no_loop_nothing_to_do(self) -> None:
        sequencer = Sequencer()

        sequencer.build()
        self.assertTrue(sequencer.has_finished())
Beispiel #26
0
    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'})
        instructions = sequencer.build()
        self.assertFalse(sequencer.has_finished())
        self.assertIsInstance(instructions, AbstractInstructionBlock)
        self.assertEqual(2, len(instructions.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)
Beispiel #27
0
 def test_initialization(self) -> None:
     sequencer = Sequencer()
     self.assertTrue(sequencer.has_finished())