diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 444f779da9082a48a86ce6ca147800e748a27d4b..c85b596ac1caea31f45334bb872f5bd392e4b4b8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,6 +19,6 @@ repos: - id: isort name: isort (python) - repo: https://github.com/Carreau/velin - rev: 0.0.12 + rev: 0.0.11 hooks: - id: velin diff --git a/b_asic/resources.py b/b_asic/resources.py index feedc9c4bb88bf22413ece9c83e94a44a54c87ea..2d85c2b8f1cd778505b62f786f3886bd75bccefd 100644 --- a/b_asic/resources.py +++ b/b_asic/resources.py @@ -34,9 +34,9 @@ def draw_exclusion_graph_coloring( color_dict: Dict[Process, int], ax: Optional[Axes] = None, color_list: Optional[Union[List[str], List[Tuple[float, float, float]]]] = None, -): +) -> None: """ - Use matplotlib.pyplot and networkx to draw a colored exclusion graph from the memory assignment + Draw a colored exclusion graph from the memory assignment. .. code-block:: python @@ -51,12 +51,19 @@ def draw_exclusion_graph_coloring( ---------- exclusion_graph : nx.Graph A nx.Graph exclusion graph object that is to be drawn. - color_dict : dictionary - A color dictionary where keys are Process objects and where values are integers representing colors. These - dictionaries are automatically generated by :func:`networkx.algorithms.coloring.greedy_color`. + color_dict : dict + A dict where keys are :class:`~b_asic.process.Process` objects and values are + integers representing colors. These dictionaries are automatically generated by + :func:`networkx.algorithms.coloring.greedy_color`. ax : :class:`matplotlib.axes.Axes`, optional - A Matplotlib Axes object to draw the exclusion graph - color_list : Optional[Union[List[str], List[Tuple[float,float,float]]]] + A Matplotlib :class:`~matplotlib.axes.Axes` object to draw the exclusion graph. + color_list : iterable of color, optional + A list of colors in Matplotlib format. + + Returns + ------- + None + """ COLOR_LIST = [ '#aa0000', @@ -126,7 +133,7 @@ class ProcessCollection: Parameters ---------- process : Process - The process object to be added to the collection + The process object to be added to the collection. """ self._collection.add(process) @@ -141,13 +148,14 @@ class ProcessCollection: show_markers: bool = True, ): """ - Use matplotlib.pyplot to generate a process variable lifetime chart from this process collection. + Plot a process variable lifetime chart. Parameters ---------- ax : :class:`matplotlib.axes.Axes`, optional - Matplotlib Axes object to draw this lifetime chart onto. If not provided (i.e., set to None), - this method will return a new axes object on return. + Matplotlib :class:`~matplotlib.axes.Axes` object to draw this lifetime chart + onto. If not provided (i.e., set to None), this method will return a new + Axes object. show_name : bool, default: True Show name of all processes in the lifetime chart. bar_color : color, optional @@ -176,7 +184,8 @@ class ProcessCollection: PAD_L, PAD_R = 0.05, 0.05 max_execution_time = max(process.execution_time for process in self._collection) if max_execution_time > self._schedule_time: - # Schedule time needs to be greater than or equal to the maximum process lifetime + # Schedule time needs to be greater than or equal to the maximum process + # lifetime raise KeyError( f'Error: Schedule time: {self._schedule_time} < Max execution' f' time: {max_execution_time}' @@ -247,16 +256,19 @@ class ProcessCollection: total_ports: Optional[int] = None, ) -> nx.Graph: """ - Create an exclusion graph from a ProcessCollection based on a number of read/write ports + Create an exclusion graph based on a number of read/write ports. Parameters ---------- read_ports : int - The number of read ports used when splitting process collection based on memory variable access. + The number of read ports used when splitting process collection based on + memory variable access. write_ports : int - The number of write ports used when splitting process collection based on memory variable access. + The number of write ports used when splitting process collection based on + memory variable access. total_ports : int - The total number of ports used when splitting process collection based on memory variable access. + The total number of ports used when splitting process collection based on + memory variable access. Returns ------- @@ -348,29 +360,28 @@ class ProcessCollection: return exclusion_graph def split_execution_time( - self, heuristic: str = "graph_color", coloring_strategy: str = "DSATUR" + self, + heuristic: str = "graph_color", + coloring_strategy: str = "saturation_largest_first", ) -> Set["ProcessCollection"]: """ Split a ProcessCollection based on overlapping execution time. Parameters ---------- - heuristic : str, default: 'graph_color' + heuristic : {'graph_color', 'left_edge'}, default: 'graph_color' The heuristic used when splitting based on execution times. - One of: 'graph_color', 'left_edge'. - coloring_strategy : str, default: 'DSATUR' - Node ordering strategy passed to nx.coloring.greedy_color() if the heuristic is set to 'graph_color'. This - parameter is only considered if heuristic is set to graph_color. + coloring_strategy : str, default: 'saturation_largest_first' + Node ordering strategy passed to :func:`networkx.coloring.greedy_color`. + This parameter is only considered if *heuristic* is set to 'graph_color'. One of - * `'largest_first'` - * `'random_sequential'` - * `'smallest_last'` - * `'independent_set'` - * `'connected_sequential_bfs'` - * `'connected_sequential_dfs'` - * `'connected_sequential'` (alias for the previous strategy) - * `'saturation_largest_first'` - * `'DSATUR'` (alias for the saturation_largest_first strategy) + * 'largest_first' + * 'random_sequential' + * 'smallest_last' + * 'independent_set' + * 'connected_sequential_bfs' + * 'connected_sequential_dfs' or 'connected_sequential' + * 'saturation_largest_first' or 'DSATUR' Returns ------- @@ -402,14 +413,17 @@ class ProcessCollection: heuristic : str, default: "graph_color" The heuristic used when splitting this ProcessCollection. Valid options are: - * "graph_color" - * "..." + * "graph_color" + * "..." read_ports : int, optional - The number of read ports used when splitting process collection based on memory variable access. + The number of read ports used when splitting process collection based on + memory variable access. write_ports : int, optional - The number of write ports used when splitting process collection based on memory variable access. + The number of write ports used when splitting process collection based on + memory variable access. total_ports : int, optional - The total number of ports used when splitting process collection based on memory variable access. + The total number of ports used when splitting process collection based on + memory variable access. Returns ------- @@ -436,29 +450,30 @@ class ProcessCollection: read_ports: int, write_ports: int, total_ports: int, - coloring_strategy: str = "DSATUR", + coloring_strategy: str = "saturation_largest_first", ) -> Set["ProcessCollection"]: """ Parameters ---------- read_ports : int - The number of read ports used when splitting process collection based on memory variable access. + The number of read ports used when splitting process collection based on + memory variable access. write_ports : int - The number of write ports used when splitting process collection based on memory variable access. + The number of write ports used when splitting process collection based on + memory variable access. total_ports : int - The total number of ports used when splitting process collection based on memory variable access. - coloring_strategy : str, default: 'DSATUR' - Node ordering strategy passed to nx.coloring.greedy_color() + The total number of ports used when splitting process collection based on + memory variable access. + coloring_strategy : str, default: 'saturation_largest_first' + Node ordering strategy passed to :func:`networkx.coloring.greedy_color` One of - * `'largest_first'` - * `'random_sequential'` - * `'smallest_last'` - * `'independent_set'` - * `'connected_sequential_bfs'` - * `'connected_sequential_dfs'` - * `'connected_sequential'` (alias for the previous strategy) - * `'saturation_largest_first'` - * `'DSATUR'` (alias for the saturation_largest_first strategy) + * 'largest_first' + * 'random_sequential' + * 'smallest_last' + * 'independent_set' + * 'connected_sequential_bfs' + * 'connected_sequential_dfs' or 'connected_sequential' + * 'saturation_largest_first' or 'DSATUR' """ # Create new exclusion graph. Nodes are Processes exclusion_graph = self.create_exclusion_graph_from_ports( @@ -475,11 +490,13 @@ class ProcessCollection: ) -> Set["ProcessCollection"]: """ Split :class:`Process` objects into a set of :class:`ProcessesCollection` objects based on a provided graph coloring. - Resulting :class:`ProcessCollection` will have the same schedule time and cyclic propoery as self. + + Resulting :class:`ProcessCollection` will have the same schedule time and cyclic + property as self. Parameters ---------- - coloring : Dict[Process, int] + coloring : dict Process->int (color) mappings Returns @@ -496,8 +513,8 @@ class ProcessCollection: def _repr_svg_(self) -> str: """ - Generate an SVG_ of the resource collection. This is automatically displayed in e.g. - Jupyter Qt console. + Generate an SVG_ of the resource collection. This is automatically displayed in + e.g. Jupyter Qt console. """ fig, ax = plt.subplots() self.draw_lifetime_chart(ax, show_markers=False) diff --git a/b_asic/signal_generator.py b/b_asic/signal_generator.py index 69f7acbc16978655d24787c3aebd6474e5e5d05c..9f8f199147a245bc09d422f64c507db79f42ed15 100644 --- a/b_asic/signal_generator.py +++ b/b_asic/signal_generator.py @@ -165,7 +165,9 @@ class ZeroPad(SignalGenerator): class FromFile(SignalGenerator): """ Signal generator that reads from file and pads a sequence with zeros. + File should be of type .txt or .csv and contain a single column vector + Parameters ---------- path : string diff --git a/test/test_simulation.py b/test/test_simulation.py index cdcb86c0c82e1a6c6a2b5f0a603ef101ad086a5d..d2d59512d556a4cdaf85f0ef50994617e98f80d6 100644 --- a/test/test_simulation.py +++ b/test/test_simulation.py @@ -2,6 +2,7 @@ import numpy as np import pytest from b_asic import Simulation +from b_asic._b_asic import FastSimulation as Simulation class TestRunFor: