Skip to content
Snippets Groups Projects
schedule.py 40.8 KiB
Newer Older
  • Learn to ignore specific revisions
  •             ax.add_patch(Polygon(xy.T, fc=_LATENCY_COLOR))
    
    
                if 'in' in str(graph_id):
                    ax.annotate(
                        graph_id,
                        xy=(op_start_time - 0.48, y_pos + 0.7),
                        color="black",
                        size=10 - (0.05 * len(self._start_times)),
                    )
                else:
                    ax.annotate(
                        graph_id,
                        xy=(op_start_time + 0.03, y_pos + 0.7),
                        color="black",
                        size=10 - (0.05 * len(self._start_times)),
                    )
    
                if execution_time_coordinates:
                    _x, _y = zip(*execution_time_coordinates)
    
                    x = np.array(_x)
                    y = np.array(_y)
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                        x + op_start_time,
    
                        color=_EXECUTION_TIME_COLOR,
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                        linewidth=3,
                    )
    
                ytickpositions.append(y_pos + 0.5)
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                yticklabels.append(cast(Operation, self._sfg.find_by_id(graph_id)).name)
    
            for graph_id, op_start_time in self._start_times.items():
    
                operation = cast(Operation, self._sfg.find_by_id(graph_id))
                out_coordinates = operation.get_output_coordinates()
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                source_y_pos = self._get_y_position(graph_id, operation_gap=operation_gap)
    
                for output_port in operation.outputs:
    
                    for output_signal in output_port.signals:
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                        destination = cast(InputPort, output_signal.destination)
                        destination_op = destination.operation
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                        destination_start_time = self._start_times[destination_op.graph_id]
    
                        destination_y_pos = self._get_y_position(
                            destination_op.graph_id, operation_gap=operation_gap
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                            destination.operation.get_input_coordinates()
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                        )
                        _draw_offset_arrow(
    
                            out_coordinates[output_port.index],
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                            destination_in_coordinates[destination.index],
    
                            [op_start_time, source_y_pos],
                            [destination_start_time, destination_y_pos],
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
                            laps=self._laps[output_signal.graph_id],
                        )
    
            ax.set_yticks(ytickpositions)
            ax.set_yticklabels(yticklabels)
    
    
            # Get operation with maximum position
    
            max_pos_graph_id = max(self._y_locations, key=self._y_locations.get)
    
            y_position_max = (
    
                self._get_y_position(max_pos_graph_id, operation_gap=operation_gap)
                + 1
                + (OPERATION_GAP if operation_gap is None else operation_gap)
            )
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            ax.axis([-1, self._schedule_time + 1, y_position_max, 0])  # Inverted y-axis
    
            ax.xaxis.set_major_locator(MaxNLocator(integer=True, min_n_ticks=1))
    
            ax.axvline(
                0,
                linestyle="--",
                color="black",
    
            ax.axvline(
                self._schedule_time,
                linestyle="--",
                color="black",
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            )
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
        def _reset_y_locations(self) -> None:
    
            """Reset all the y-locations in the schedule to None"""
    
            self._y_locations = defaultdict(_y_locations_default)
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
        def plot(self, ax: Axes, operation_gap: float = OPERATION_GAP) -> None:
    
            """
            Plot the schedule in a :class:`matplotlib.axes.Axes` or subclass.
    
            Parameters
            ----------
    
            ax : :class:`~matplotlib.axes.Axes`
    
                The :class:`matplotlib.axes.Axes` to plot in.
            operation_gap : float, optional
    
                The vertical distance between operations in the schedule. The height of
                the operation is always 1.
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            self._plot_schedule(ax, operation_gap=operation_gap)
    
        def show(
    
            self, operation_gap: float = OPERATION_GAP, title: Optional[str] = None
    
        ) -> None:
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            Show the schedule. Will display based on the current Matplotlib backend.
    
    
            Parameters
            ----------
            operation_gap : float, optional
    
                The vertical distance between operations in the schedule. The height of
                the operation is always 1.
    
            title : str, optional
                Figure title.
    
            fig = self._get_figure(operation_gap=operation_gap)
            if title:
                fig.suptitle(title)
            fig.show()
    
        def _get_figure(self, operation_gap: float = OPERATION_GAP) -> Figure:
    
            """
            Create a Figure and an Axes and plot schedule in the Axes.
    
            Parameters
            ----------
            operation_gap : float, optional
    
                The vertical distance between operations in the schedule. The height of
                the operation is always 1.
    
            The Matplotlib Figure.
    
            height = len(self._start_times) * 0.3 + 2
            fig, ax = plt.subplots(figsize=(12, height))
    
            self._plot_schedule(ax, operation_gap=operation_gap)
    
    Oscar Gustafsson's avatar
    Oscar Gustafsson committed
            return fig
    
        def _repr_svg_(self) -> str:
    
            Generate an SVG of the schedule. This is automatically displayed in e.g.
            Jupyter Qt console.
    
            height = len(self._start_times) * 0.3 + 2
            fig, ax = plt.subplots(figsize=(12, height))
    
            self._plot_schedule(ax)
    
            buffer = io.StringIO()
            fig.savefig(buffer, format="svg")
    
            return buffer.getvalue()
    
    
        # SVG is valid HTML. This is useful for e.g. sphinx-gallery
        _repr_html_ = _repr_svg_