Skip to content
Snippets Groups Projects
Commit e817f13a authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Improve repr for resources

parent 72bf5ff3
No related branches found
No related tags found
1 merge request!202Improve repr for resources
Pipeline #89909 passed
......@@ -58,6 +58,11 @@ class Process:
def __str__(self) -> str:
return self._name
def __repr__(self) -> str:
return (
f"Process({self.start_time}, {self.execution_time}, {self.name})"
)
# Static counter for default names
_name_cnt = 0
......@@ -142,6 +147,13 @@ class MemoryVariable(Process):
def write_port(self) -> OutputPort:
return self._write_port
def __repr__(self) -> str:
reads = {k: v for k, v in zip(self._read_ports, self._life_times)}
return (
f"MemoryVariable({self.start_time}, {self.write_port},"
f" {reads!r}, {self.name!r})"
)
class PlainMemoryVariable(Process):
"""
......@@ -189,3 +201,10 @@ class PlainMemoryVariable(Process):
@property
def write_port(self) -> int:
return self._write_port
def __repr__(self) -> str:
reads = {k: v for k, v in zip(self._read_ports, self._life_times)}
return (
f"PlainMemoryVariable({self.start_time}, {self.write_port},"
f" {reads!r}, {self.name!r})"
)
import io
import re
from typing import Dict, Iterable, List, Optional, Set, Tuple, TypeVar, Union
......@@ -390,3 +391,15 @@ class ProcessCollection:
)
for process_collection_set in process_collection_set_list
}
def _repr_svg_(self) -> str:
"""
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)
f = io.StringIO()
fig.savefig(f, format="svg")
return f.getvalue()
......@@ -32,6 +32,7 @@ from b_asic.graph_component import GraphID
from b_asic.operation import Operation
from b_asic.port import InputPort, OutputPort
from b_asic.process import MemoryVariable, Process
from b_asic.resources import ProcessCollection
from b_asic.signal_flow_graph import SFG
from b_asic.special_operations import Delay, Output
......@@ -583,8 +584,8 @@ class Schedule:
] + cast(int, source_port.latency_offset)
self._remove_delays()
def _get_memory_variables_list(self) -> List['Process']:
ret: List['Process'] = []
def _get_memory_variables_list(self) -> List['MemoryVariable']:
ret: List['MemoryVariable'] = []
for graph_id, start_time in self._start_times.items():
slacks = self._forward_slacks(graph_id)
for outport, signals in slacks.items():
......@@ -597,10 +598,25 @@ class Schedule:
start_time + cast(int, outport.latency_offset),
outport,
reads,
outport.operation.graph_id,
)
)
return ret
def get_memory_variables(self) -> ProcessCollection:
"""
Return a :class:`~b_asic.resources.ProcessCollection` containing all
memory variables.
Returns
-------
ProcessCollection
"""
return ProcessCollection(
set(self._get_memory_variables_list()), self.schedule_time
)
def _get_y_position(
self, graph_id, operation_height=1.0, operation_gap=None
) -> float:
......
......@@ -54,3 +54,5 @@ sfg.set_execution_time_of_type(Subtraction.type_name(), 1)
# Generate schedule
schedule = Schedule(sfg, cyclic=True)
schedule.plot()
pc = schedule.get_memory_variables()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment