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

Renamed Schema to Schedule

parent bdf79a16
No related branches found
No related tags found
1 merge request!74Renamed Schema to Schedule
Pipeline #31072 passed
......@@ -16,4 +16,4 @@ from b_asic.signal import *
from b_asic.simulation import *
from b_asic.special_operations import *
from b_asic.save_load_structure import *
from b_asic.schema import *
from b_asic.schedule import *
"""B-ASIC Schema Module.
"""B-ASIC Schedule Module.
Contains the schema class for scheduling operations in an SFG.
Contains the schedule class for scheduling operations in an SFG.
"""
from collections import defaultdict
......@@ -17,8 +17,8 @@ from b_asic.graph_component import GraphID
from b_asic.special_operations import Delay, Output
class Schema:
"""Schema of an SFG with scheduled Operations."""
class Schedule:
"""Schedule of an SFG with scheduled Operations."""
_sfg: SFG
_start_times: Dict[GraphID, int]
......@@ -28,7 +28,7 @@ class Schema:
_resolution: int
def __init__(self, sfg: SFG, schedule_time: Optional[int] = None, cyclic: bool = False, resolution: int = 1, scheduling_alg: str = "ASAP"):
"""Construct a Schema from an SFG."""
"""Construct a Schedule from an SFG."""
self._sfg = sfg
self._start_times = dict()
self._laps = defaultdict(lambda: 0)
......@@ -54,7 +54,7 @@ class Schema:
def start_time_of_operation(self, op_id: GraphID) -> int:
"""Get the start time of the operation with the specified by the op_id."""
assert op_id in self._start_times, "No operation with the specified op_id in this schema."
assert op_id in self._start_times, "No operation with the specified op_id in this schedule."
return self._start_times[op_id]
def _get_max_end_time(self) -> int:
......@@ -67,7 +67,7 @@ class Schema:
return max_end_time
def forward_slack(self, op_id: GraphID) -> int:
assert op_id in self._start_times, "No operation with the specified op_id in this schema."
assert op_id in self._start_times, "No operation with the specified op_id in this schedule."
slack = sys.maxsize
output_slacks = self._forward_slacks(op_id)
# Make more pythonic
......@@ -93,7 +93,7 @@ class Schema:
return ret
def backward_slack(self, op_id: GraphID) -> int:
assert op_id in self._start_times, "No operation with the specified op_id in this schema."
assert op_id in self._start_times, "No operation with the specified op_id in this schedule."
slack = sys.maxsize
input_slacks = self._backward_slacks(op_id)
# Make more pythonic
......@@ -120,13 +120,13 @@ class Schema:
def slacks(self, op_id: GraphID) -> Tuple[int, int]:
assert op_id in self._start_times, "No operation with the specified op_id in this schema."
assert op_id in self._start_times, "No operation with the specified op_id in this schedule."
return (self.backward_slack(op_id), self.forward_slack(op_id))
def print_slacks(self) -> None:
raise NotImplementedError
def set_schedule_time(self, time: int) -> "Schema":
def set_schedule_time(self, time: int) -> "Schedule":
assert self._get_max_end_time() < time, "New schedule time to short."
self._schedule_time = time
return self
......@@ -135,14 +135,14 @@ class Schema:
def schedule_time(self) -> int:
return self._schedule_time
def increase_time_resolution(self, factor: int) -> "Schema":
def increase_time_resolution(self, factor: int) -> "Schedule":
raise NotImplementedError
def decrease_time_resolution(self, factor: int) -> "Schema":
def decrease_time_resolution(self, factor: int) -> "Schedule":
raise NotImplementedError
def move_operation(self, op_id: GraphID, time: int) -> "Schema":
assert op_id in self._start_times, "No operation with the specified op_id in this schema."
def move_operation(self, op_id: GraphID, time: int) -> "Schedule":
assert op_id in self._start_times, "No operation with the specified op_id in this schedule."
(backward_slack, forward_slack) = self.slacks(op_id)
if time < 0:
......
"""
B-ASIC test suite for the schema module and Schema class.
B-ASIC test suite for the schedule module and Schedule class.
"""
import pytest
from b_asic import Schema, Addition, ConstantMultiplication
from b_asic import Schedule, Addition, ConstantMultiplication
class TestInit:
......@@ -11,21 +11,21 @@ class TestInit:
sfg_simple_filter.set_latency_of_type(Addition.type_name(), 5)
sfg_simple_filter.set_latency_of_type(ConstantMultiplication.type_name(), 4)
schema = Schema(sfg_simple_filter)
schedule = Schedule(sfg_simple_filter)
assert schema._start_times == {"in1": 0, "add1": 4, "cmul1": 0, "out1": 0}
assert schedule._start_times == {"in1": 0, "add1": 4, "cmul1": 0, "out1": 0}
def test_complicated_single_outputs_normal_latency(self, precedence_sfg_delays):
precedence_sfg_delays.set_latency_of_type(Addition.type_name(), 4)
precedence_sfg_delays.set_latency_of_type(ConstantMultiplication.type_name(), 3)
schema = Schema(precedence_sfg_delays, scheduling_alg="ASAP")
schedule = Schedule(precedence_sfg_delays, scheduling_alg="ASAP")
for op in schema._sfg.get_operations_topological_order():
for op in schedule._sfg.get_operations_topological_order():
print(op.latency_offsets)
start_times_names = dict()
for op_id, start_time in schema._start_times.items():
for op_id, start_time in schedule._start_times.items():
op_name = precedence_sfg_delays.find_by_id(op_id).name
start_times_names[op_name] = start_time
......@@ -47,10 +47,10 @@ class TestInit:
precedence_sfg_delays.find_by_name("ADD3")[0].set_latency_offsets({'in0': 2, 'in1': 1, 'out0': 4})
precedence_sfg_delays.find_by_name("ADD4")[0].set_latency_offsets({'in0': 6, 'in1': 7, 'out0': 9})
schema = Schema(precedence_sfg_delays, scheduling_alg="ASAP")
schedule = Schedule(precedence_sfg_delays, scheduling_alg="ASAP")
start_times_names = dict()
for op_id, start_time in schema._start_times.items():
for op_id, start_time in schedule._start_times.items():
op_name = precedence_sfg_delays.find_by_id(op_id).name
start_times_names[op_name] = start_time
......@@ -58,10 +58,10 @@ class TestInit:
'A1': 0, 'A2': 0, 'ADD3': 3, 'ADD4': 8, 'OUT1': 17}
def test_independent_sfg(self, sfg_two_inputs_two_outputs_independent_with_cmul):
schema = Schema(sfg_two_inputs_two_outputs_independent_with_cmul, scheduling_alg="ASAP")
schedule = Schedule(sfg_two_inputs_two_outputs_independent_with_cmul, scheduling_alg="ASAP")
start_times_names = dict()
for op_id, start_time in schema._start_times.items():
for op_id, start_time in schedule._start_times.items():
op_name = sfg_two_inputs_two_outputs_independent_with_cmul.find_by_id(op_id).name
start_times_names[op_name] = start_time
......@@ -74,20 +74,20 @@ class TestSlacks:
precedence_sfg_delays.set_latency_of_type(Addition.type_name(), 1)
precedence_sfg_delays.set_latency_of_type(ConstantMultiplication.type_name(), 3)
schema = Schema(precedence_sfg_delays, scheduling_alg="ASAP")
assert schema.forward_slack(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id) == 7
assert schema.backward_slack(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id) == 0
schedule = Schedule(precedence_sfg_delays, scheduling_alg="ASAP")
assert schedule.forward_slack(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id) == 7
assert schedule.backward_slack(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id) == 0
assert schema.forward_slack(precedence_sfg_delays.find_by_name("A2")[0].graph_id) == 0
assert schema.backward_slack(precedence_sfg_delays.find_by_name("A2")[0].graph_id) == 16
assert schedule.forward_slack(precedence_sfg_delays.find_by_name("A2")[0].graph_id) == 0
assert schedule.backward_slack(precedence_sfg_delays.find_by_name("A2")[0].graph_id) == 16
def test_slacks_normal_latency(self, precedence_sfg_delays):
precedence_sfg_delays.set_latency_of_type(Addition.type_name(), 1)
precedence_sfg_delays.set_latency_of_type(ConstantMultiplication.type_name(), 3)
schema = Schema(precedence_sfg_delays, scheduling_alg="ASAP")
assert schema.slacks(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id) == (0, 7)
assert schema.slacks(precedence_sfg_delays.find_by_name("A2")[0].graph_id) == (16, 0)
schedule = Schedule(precedence_sfg_delays, scheduling_alg="ASAP")
assert schedule.slacks(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id) == (0, 7)
assert schedule.slacks(precedence_sfg_delays.find_by_name("A2")[0].graph_id) == (16, 0)
class TestRescheduling:
......@@ -95,13 +95,13 @@ class TestRescheduling:
precedence_sfg_delays.set_latency_of_type(Addition.type_name(), 4)
precedence_sfg_delays.set_latency_of_type(ConstantMultiplication.type_name(), 3)
schema = Schema(precedence_sfg_delays, scheduling_alg="ASAP")
schedule = Schedule(precedence_sfg_delays, scheduling_alg="ASAP")
schema.move_operation(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id, 4)
schema.move_operation(precedence_sfg_delays.find_by_name("A2")[0].graph_id, 2)
schedule.move_operation(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id, 4)
schedule.move_operation(precedence_sfg_delays.find_by_name("A2")[0].graph_id, 2)
start_times_names = dict()
for op_id, start_time in schema._start_times.items():
for op_id, start_time in schedule._start_times.items():
op_name = precedence_sfg_delays.find_by_id(op_id).name
start_times_names[op_name] = start_time
......@@ -112,36 +112,36 @@ class TestRescheduling:
precedence_sfg_delays.set_latency_of_type(Addition.type_name(), 1)
precedence_sfg_delays.set_latency_of_type(ConstantMultiplication.type_name(), 3)
schema = Schema(precedence_sfg_delays, scheduling_alg="ASAP")
schedule = Schedule(precedence_sfg_delays, scheduling_alg="ASAP")
add3_id = precedence_sfg_delays.find_by_name("ADD3")[0].graph_id
schema.move_operation(add3_id, 4)
assert schema.forward_slack(add3_id) == 3
assert schema.backward_slack(add3_id) == 4
schedule.move_operation(add3_id, 4)
assert schedule.forward_slack(add3_id) == 3
assert schedule.backward_slack(add3_id) == 4
a2_id = precedence_sfg_delays.find_by_name("A2")[0].graph_id
assert schema.forward_slack(a2_id) == 4
assert schema.backward_slack(a2_id) == 16
assert schedule.forward_slack(a2_id) == 4
assert schedule.backward_slack(a2_id) == 16
schema.move_operation(a2_id, 2)
schedule.move_operation(a2_id, 2)
assert schema.forward_slack(add3_id) == 3
assert schema.backward_slack(add3_id) == 2
assert schedule.forward_slack(add3_id) == 3
assert schedule.backward_slack(add3_id) == 2
assert schema.forward_slack(a2_id) == 2
assert schema.backward_slack(a2_id) == 18
assert schedule.forward_slack(a2_id) == 2
assert schedule.backward_slack(a2_id) == 18
def test_move_operation_incorrect_move_backward(self, precedence_sfg_delays):
precedence_sfg_delays.set_latency_of_type(Addition.type_name(), 1)
precedence_sfg_delays.set_latency_of_type(ConstantMultiplication.type_name(), 3)
schema = Schema(precedence_sfg_delays, scheduling_alg="ASAP")
schedule = Schedule(precedence_sfg_delays, scheduling_alg="ASAP")
with pytest.raises(ValueError):
schema.move_operation(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id, -4)
schedule.move_operation(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id, -4)
def test_move_operation_incorrect_move_forward(self, precedence_sfg_delays):
precedence_sfg_delays.set_latency_of_type(Addition.type_name(), 1)
precedence_sfg_delays.set_latency_of_type(ConstantMultiplication.type_name(), 3)
schema = Schema(precedence_sfg_delays, scheduling_alg="ASAP")
schedule = Schedule(precedence_sfg_delays, scheduling_alg="ASAP")
with pytest.raises(ValueError):
schema.move_operation(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id, 10)
schedule.move_operation(precedence_sfg_delays.find_by_name("ADD3")[0].graph_id, 10)
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