Skip to content
Snippets Groups Projects
Commit fb3b6eda authored by Mikael Henriksson's avatar Mikael Henriksson :runner:
Browse files

resources.py: add show method (fixes #233)

parent 8829dcd0
No related branches found
No related tags found
1 merge request!332resources.py: add show method (fixes #233)
Pipeline #96284 passed
...@@ -447,6 +447,7 @@ class ProcessCollection: ...@@ -447,6 +447,7 @@ class ProcessCollection:
def plot( def plot(
self, self,
ax: Optional[Axes] = None, ax: Optional[Axes] = None,
*,
show_name: bool = True, show_name: bool = True,
bar_color: Union[str, Tuple[float, ...]] = _LATENCY_COLOR, bar_color: Union[str, Tuple[float, ...]] = _LATENCY_COLOR,
marker_color: Union[str, Tuple[float, ...]] = "black", marker_color: Union[str, Tuple[float, ...]] = "black",
...@@ -454,7 +455,6 @@ class ProcessCollection: ...@@ -454,7 +455,6 @@ class ProcessCollection:
marker_write: str = "o", marker_write: str = "o",
show_markers: bool = True, show_markers: bool = True,
row: Optional[int] = None, row: Optional[int] = None,
*,
allow_excessive_lifetimes: bool = False, allow_excessive_lifetimes: bool = False,
): ):
""" """
...@@ -472,10 +472,10 @@ class ProcessCollection: ...@@ -472,10 +472,10 @@ class ProcessCollection:
Bar color in lifetime chart. Bar color in lifetime chart.
marker_color : color, default 'black' marker_color : color, default 'black'
Color for read and write marker. Color for read and write marker.
marker_write : str, default 'x'
Marker at write time in the lifetime chart.
marker_read : str, default 'o' marker_read : str, default 'o'
Marker at read time in the lifetime chart. Marker at read time in the lifetime chart.
marker_write : str, default 'x'
Marker at write time in the lifetime chart.
show_markers : bool, default True show_markers : bool, default True
Show markers at read and write times. Show markers at read and write times.
row : int, optional row : int, optional
...@@ -581,6 +581,53 @@ class ProcessCollection: ...@@ -581,6 +581,53 @@ class ProcessCollection:
pass pass
return _ax return _ax
def show(
self,
*,
show_name: bool = True,
bar_color: Union[str, Tuple[float, ...]] = _LATENCY_COLOR,
marker_color: Union[str, Tuple[float, ...]] = "black",
marker_read: str = "X",
marker_write: str = "o",
show_markers: bool = True,
allow_excessive_lifetimes: bool = False,
) -> None:
"""
Show the process collection using the current Matplotlib backend.
Equivalent to creating a Matplotlib figure, passing it and arguments to :func:`plot`
and invoking :py:meth:`matplotlib.figure.Figure.show`.
Parameters
----------
show_name : bool, default: True
Show name of all processes in the lifetime chart.
bar_color : color, optional
Bar color in lifetime chart.
marker_color : color, default 'black'
Color for read and write marker.
marker_read : str, default 'o'
Marker at read time in the lifetime chart.
marker_write : str, default 'x'
Marker at write time in the lifetime chart.
show_markers : bool, default True
Show markers at read and write times.
allow_excessive_lifetimes : bool, default False
If set to true, the plot method allows ploting collections of variables with a greater lifetime
than the schedule time.
"""
fig, ax = plt.subplots()
self.plot(
ax=ax,
show_name=show_name,
bar_color=bar_color,
marker_color=marker_color,
marker_read=marker_read,
marker_write=marker_write,
show_markers=show_markers,
allow_excessive_lifetimes=allow_excessive_lifetimes,
)
fig.show() # type: ignore
def create_exclusion_graph_from_ports( def create_exclusion_graph_from_ports(
self, self,
read_ports: Optional[int] = None, read_ports: Optional[int] = None,
...@@ -721,7 +768,7 @@ class ProcessCollection: ...@@ -721,7 +768,7 @@ class ProcessCollection:
The heuristic used when splitting based on execution times. The heuristic used when splitting based on execution times.
coloring_strategy : str, default: 'saturation_largest_first' coloring_strategy : str, default: 'saturation_largest_first'
Node ordering strategy passed to :func:`networkx.coloring.greedy_color`. Node ordering strategy passed to :func:`networkx.algorithms.coloring.greedy_color`.
This parameter is only considered if *heuristic* is set to 'graph_color'. This parameter is only considered if *heuristic* is set to 'graph_color'.
One of One of
...@@ -761,7 +808,7 @@ class ProcessCollection: ...@@ -761,7 +808,7 @@ class ProcessCollection:
Parameters Parameters
---------- ----------
heuristic : str, default: "graph_color" heuristic : str, default: "graph_color"
The heuristic used when splitting this ProcessCollection. The heuristic used when splitting this :class:`ProcessCollection`.
Valid options are: Valid options are:
* "graph_color" * "graph_color"
...@@ -811,7 +858,7 @@ class ProcessCollection: ...@@ -811,7 +858,7 @@ class ProcessCollection:
The total number of ports used when splitting process collection based on The total number of ports used when splitting process collection based on
memory variable access. memory variable access.
coloring_strategy : str, default: 'saturation_largest_first' coloring_strategy : str, default: 'saturation_largest_first'
Node ordering strategy passed to :func:`networkx.coloring.greedy_color` Node ordering strategy passed to :func:`networkx.algorithms.coloring.greedy_color`
One of One of
* 'largest_first' * 'largest_first'
* 'random_sequential' * 'random_sequential'
...@@ -884,13 +931,14 @@ class ProcessCollection: ...@@ -884,13 +931,14 @@ class ProcessCollection:
coloring: Optional[Dict[Process, int]] = None, coloring: Optional[Dict[Process, int]] = None,
) -> Set["ProcessCollection"]: ) -> Set["ProcessCollection"]:
""" """
Perform cell assignment of the processes in this collection using graph coloring with networkx.coloring.greedy_color. Perform cell assignment of the processes in this collection using graph coloring.
Two or more processes can share a single cell if, and only if, they have no overlaping time alive. Two or more processes can share a single cell if, and only if, they have no overlaping time alive.
Parameters Parameters
---------- ----------
coloring_strategy : str, default: "saturation_largest_first" coloring_strategy : str, default: "saturation_largest_first"
Graph coloring strategy passed to networkx.coloring.greedy_color(). Graph coloring strategy passed to :func:`networkx.algorithms.coloring.greedy_color`.
coloring : dictionary, optional coloring : dictionary, optional
An optional graph coloring, dictionary with Process and its associated color (int). An optional graph coloring, dictionary with Process and its associated color (int).
If a graph coloring is not provided throught this parameter, one will be created when calling this method. If a graph coloring is not provided throught this parameter, one will be created when calling this method.
......
""" """
Example SFG used for scheduling in the TSTE87 course. ====================================================
Example SFG used for scheduling in the TSTE87 course
====================================================
Node numbering from the original SFG used with the Matlab toolbox.:: Node numbering from the original SFG used with the Matlab toolbox::
sfg=addoperand([],'in',1,1); sfg=addoperand([],'in',1,1);
sfg=addoperand(sfg,'constmult',1,1,2,0.25); sfg=addoperand(sfg,'constmult',1,1,2,0.25);
......
...@@ -134,3 +134,6 @@ class TestProcessCollectionPlainMemoryVariable: ...@@ -134,3 +134,6 @@ class TestProcessCollectionPlainMemoryVariable:
isinstance(operand.operation, ConstantMultiplication) isinstance(operand.operation, ConstantMultiplication)
for operand in pc_cmul.collection for operand in pc_cmul.collection
) )
def test_show(self, simple_collection: ProcessCollection):
simple_collection.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment