Skip to content
Snippets Groups Projects
Commit 5aa0ab43 authored by Hugo Winbladh's avatar Hugo Winbladh Committed by Oscar Gustafsson
Browse files

add comments, add test for reintroducing delays, and remove schedule._original_sfg

parent 579bf5d2
No related branches found
No related tags found
1 merge request!420Add method to reconstruct SFG from a schedule
...@@ -113,7 +113,6 @@ class Schedule: ...@@ -113,7 +113,6 @@ class Schedule:
if not isinstance(sfg, SFG): if not isinstance(sfg, SFG):
raise TypeError("An SFG must be provided") raise TypeError("An SFG must be provided")
self._original_sfg = sfg() # Make a copy
self._sfg = sfg self._sfg = sfg
self._start_times = {} self._start_times = {}
self._laps = defaultdict(_laps_default) self._laps = defaultdict(_laps_default)
...@@ -390,13 +389,14 @@ class Schedule: ...@@ -390,13 +389,14 @@ class Schedule:
operation_id : GraphID operation_id : GraphID
The GraphID of the operation to swap. The GraphID of the operation to swap.
""" """
self._original_sfg.swap_io_of_operation(operation_id)
self._sfg.swap_io_of_operation(operation_id) self._sfg.swap_io_of_operation(operation_id)
@property @property
def sfg(self) -> SFG: def sfg(self) -> SFG:
"""The SFG of the current schedule.""" """The SFG corresponding to the current schedule."""
return self._original_sfg reconstructed_sfg = self._reintroduce_delays()
simplified_sfg = reconstructed_sfg.simplify_delay_element_placement()
return simplified_sfg
@property @property
def start_times(self) -> Dict[GraphID, int]: def start_times(self) -> Dict[GraphID, int]:
...@@ -529,7 +529,6 @@ class Schedule: ...@@ -529,7 +529,6 @@ class Schedule:
The execution time of the operation. The execution time of the operation.
""" """
self._sfg.set_execution_time_of_type(type_name, execution_time) self._sfg.set_execution_time_of_type(type_name, execution_time)
self._original_sfg.set_execution_time_of_type(type_name, execution_time)
def move_y_location( def move_y_location(
self, graph_id: GraphID, new_y: int, insert: bool = False self, graph_id: GraphID, new_y: int, insert: bool = False
...@@ -761,6 +760,7 @@ class Schedule: ...@@ -761,6 +760,7 @@ class Schedule:
delay_list = self._sfg.find_by_type_name(Delay.type_name()) delay_list = self._sfg.find_by_type_name(Delay.type_name())
def _reintroduce_delays(self) -> SFG: def _reintroduce_delays(self) -> SFG:
"""Reintroduce delay elements to each signal according to the ``_laps`` variable."""
reconstructed_sfg = self._sfg() reconstructed_sfg = self._sfg()
for signal_id,lap in self._laps.items(): for signal_id,lap in self._laps.items():
for delays in range(lap): for delays in range(lap):
......
...@@ -439,7 +439,6 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow): ...@@ -439,7 +439,6 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow):
self.save_as() self.save_as()
return return
self._schedule._sfg._graph_id_generator = None self._schedule._sfg._graph_id_generator = None
self._schedule._original_sfg._graph_id_generator = None
with open(self._file_name, 'wb') as f: with open(self._file_name, 'wb') as f:
pickle.dump(self._schedule, f) pickle.dump(self._schedule, f)
self._add_recent_file(self._file_name) self._add_recent_file(self._file_name)
...@@ -462,7 +461,6 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow): ...@@ -462,7 +461,6 @@ class ScheduleMainWindow(QMainWindow, Ui_MainWindow):
filename += '.bsc' filename += '.bsc'
self._file_name = filename self._file_name = filename
self._schedule._sfg._graph_id_generator = None self._schedule._sfg._graph_id_generator = None
self._schedule._original_sfg._graph_id_generator = None
with open(self._file_name, 'wb') as f: with open(self._file_name, 'wb') as f:
pickle.dump(self._schedule, f) pickle.dump(self._schedule, f)
self._add_recent_file(self._file_name) self._add_recent_file(self._file_name)
......
...@@ -737,6 +737,13 @@ class SFG(AbstractOperation): ...@@ -737,6 +737,13 @@ class SFG(AbstractOperation):
return sfg_copy() return sfg_copy()
def simplify_delay_element_placement(self) -> "SFG": def simplify_delay_element_placement(self) -> "SFG":
""" Simplify an SFG by removing some redundant delay elements.
For example two signals originating from the same starting point, each
connected to a delay element will combine into a single delay element.
Returns a copy of the simplified SFG.
"""
sfg_copy = self() sfg_copy = self()
for delay_element in sfg_copy.find_by_type_name(Delay.type_name()): for delay_element in sfg_copy.find_by_type_name(Delay.type_name()):
neighboring_delays = [] neighboring_delays = []
......
...@@ -520,6 +520,23 @@ class TestRescheduling: ...@@ -520,6 +520,23 @@ class TestRescheduling:
assert schedule._start_times["add0"] == 0 assert schedule._start_times["add0"] == 0
assert schedule._start_times["out0"] == 2 assert schedule._start_times["out0"] == 2
def test_reintroduce_delays(self, precedence_sfg_delays, sfg_direct_form_iir_lp_filter):
precedence_sfg_delays.set_latency_of_type(Addition.type_name(), 1)
precedence_sfg_delays.set_latency_of_type(ConstantMultiplication.type_name(), 3)
sfg_direct_form_iir_lp_filter.set_latency_of_type(Addition.type_name(), 1)
sfg_direct_form_iir_lp_filter.set_latency_of_type(ConstantMultiplication.type_name(), 3)
schedule = Schedule(precedence_sfg_delays, algorithm="ASAP")
sfg = schedule.sfg
assert precedence_sfg_delays.evaluate(5) == sfg.evaluate(5)
schedule = Schedule(sfg_direct_form_iir_lp_filter, algorithm="ASAP")
sfg = schedule.sfg
assert sfg_direct_form_iir_lp_filter.evaluate(5) == sfg.evaluate(5)
class TestTimeResolution: class TestTimeResolution:
def test_increase_time_resolution( def test_increase_time_resolution(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment