Skip to content

Commit

Permalink
Do not generate redundant connections and expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
sukritkalra committed Nov 2, 2023
1 parent 98ba0ad commit 13ae25b
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions schedulers/tetrisched_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@ def schedule(
)
self._logger.warning(f"[{sim_time.time}] Failed to place any tasks.")

# if sim_time == EventTime(2, EventTime.Unit.US):
# raise RuntimeError("Stopping the Simulation.")

scheduler_end_time = time.time()
scheduler_runtime = EventTime(
int((scheduler_end_time - scheduler_start_time) * 1e6), EventTime.Unit.US
Expand Down Expand Up @@ -633,7 +630,7 @@ def _construct_task_graph_strl(
task_expression = None

# Retrieve the STRL expressions for all the children of this Task.
child_expressions = []
child_expressions = {}
for child in task_graph.get_children(task):
child_expression = self._construct_task_graph_strl(
current_time,
Expand All @@ -645,7 +642,7 @@ def _construct_task_graph_strl(
placement_rewards,
)
if child_expression:
child_expressions.append(child_expression)
child_expressions[child_expression.id] = child_expression

# If there are no children, cache and return the expression for this Task.
if len(child_expressions) == 0:
Expand All @@ -664,11 +661,11 @@ def _construct_task_graph_strl(
child_expression = tetrisched.strl.MinExpression(
f"{task.unique_name}_children"
)
for child in child_expressions:
for child in child_expressions.values():
child_expression.addChild(child)
else:
# If there is just one child, then we can just use that subtree.
child_expression = child_expressions[0]
child_expression = next(iter(child_expressions.values()))

# Construct a LessThanExpression to order the two trees.
# If the current Task has to be scheduled, then we need to ensure that it
Expand Down Expand Up @@ -719,7 +716,7 @@ def construct_task_graph_strl(
task_strls = {}

# Construct the STRL expression for all the roots of the TaskGraph.
root_task_strls = []
root_task_strls = {}
for root in task_graph.get_source_tasks():
self._logger.debug(
f"[{current_time.time}] Constructing the STRL for root "
Expand All @@ -736,14 +733,14 @@ def construct_task_graph_strl(
placement_rewards,
)
if root_task_strl:
root_task_strls.append(root_task_strl)
root_task_strls[root_task_strl.id] = root_task_strl

if len(root_task_strls) == 0:
# No roots, possibly empty TaskGraph, return None.
return None
elif len(root_task_strls) == 1:
# Single root, reduce constraints and just bubble this up.
return root_task_strls[0]
return next(iter(root_task_strls.values()))
else:
# Construct a MinExpression to order the roots of the TaskGraph.
self._logger.debug(
Expand All @@ -754,6 +751,6 @@ def construct_task_graph_strl(
min_expression_task_graph = tetrisched.strl.MinExpression(
f"{task_graph.name}_min_expression"
)
for root_task_strl in root_task_strls:
for root_task_strl in root_task_strls.values():
min_expression_task_graph.addChild(root_task_strl)
return min_expression_task_graph

0 comments on commit 13ae25b

Please sign in to comment.