From a1b9f24cdfb623237a83a8de5772553e69997c61 Mon Sep 17 00:00:00 2001
From: Simon Bjurek <simbj106@student.liu.se>
Date: Mon, 24 Feb 2025 10:43:35 +0100
Subject: [PATCH] Updated pre commit config versions and added a sort y on
 start time method used by schedulers and scheduling GUI.

---
 .pre-commit-config.yaml                | 14 +++++++-------
 b_asic/schedule.py                     |  8 +++++++-
 b_asic/scheduler.py                    |  6 ++++++
 b_asic/scheduler_gui/scheduler_item.py |  5 ++---
 4 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 2ddbba5a..3fc8f67f 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,6 @@
 repos:
   - repo: https://github.com/pre-commit/pre-commit-hooks
-    rev: v4.6.0
+    rev: v5.0.0
     hooks:
       - id: mixed-line-ending
         exclude_types: [svg]
@@ -14,17 +14,17 @@ repos:
       - id: check-toml
 
   - repo: https://github.com/crate-ci/typos
-    rev: v1.22.9
+    rev: v1.29.9
     hooks:
       - id: typos
 
   - repo: https://github.com/psf/black
-    rev: 24.4.2
+    rev: 25.1.0
     hooks:
       - id: black
 
   - repo: https://github.com/pycqa/isort
-    rev: 5.13.2
+    rev: 6.0.0
     hooks:
       - id: isort
         name: isort (python)
@@ -36,17 +36,17 @@ repos:
 
   - repo: https://github.com/charliermarsh/ruff-pre-commit
     # Ruff version.
-    rev: "v0.5.0"
+    rev: "v0.9.7"
     hooks:
       - id: ruff
 
   - repo: https://github.com/adamchainz/blacken-docs
-    rev: 1.18.0
+    rev: 1.19.1
     hooks:
       - id: blacken-docs
 
   - repo: https://github.com/asottile/pyupgrade
-    rev: v3.16.0
+    rev: v3.19.1
     hooks:
       - id: pyupgrade
         args: [--py38-plus]
diff --git a/b_asic/schedule.py b/b_asic/schedule.py
index 6e231c2c..1d72ce0b 100644
--- a/b_asic/schedule.py
+++ b/b_asic/schedule.py
@@ -575,7 +575,7 @@ class Schedule:
                 if change_in_latency > (self.forward_slack(op.graph_id)):
                     passed = False
                     raise ValueError(
-                        f"Error: Can't increase latency for all components. Try increassing forward slack time by rescheduling. "
+                        f"Error: Can't increase latency for all components. Try increasing forward slack time by rescheduling. "
                         f"Error in: {op.graph_id}"
                     )
                     break
@@ -894,6 +894,12 @@ class Schedule:
             self._y_locations[graph_id] = y_location
         return operation_gap + y_location * (operation_height + operation_gap)
 
+    def sort_y_locations_on_start_times(self):
+        for i, graph_id in enumerate(
+            sorted(self._start_times, key=self._start_times.get)
+        ):
+            self.set_y_location(graph_id, i)
+
     def _plot_schedule(self, ax: Axes, operation_gap: float = OPERATION_GAP) -> None:
         """Draw the schedule."""
         line_cache = []
diff --git a/b_asic/scheduler.py b/b_asic/scheduler.py
index fc512557..311c0634 100644
--- a/b_asic/scheduler.py
+++ b/b_asic/scheduler.py
@@ -120,6 +120,8 @@ class ASAPScheduler(Scheduler):
         self._handle_outputs(schedule, non_schedulable_ops)
         schedule.remove_delays()
 
+        schedule.sort_y_locations_on_start_times()
+
 
 class ALAPScheduler(Scheduler):
     """Scheduler that implements the as-late-as-possible (ALAP) algorithm."""
@@ -151,6 +153,8 @@ class ALAPScheduler(Scheduler):
                 if not isinstance(outport.operation, Delay):
                     schedule.move_operation_alap(outport.operation.graph_id)
 
+        schedule.sort_y_locations_on_start_times()
+
 
 class ListScheduler(Scheduler, ABC):
     def __init__(
@@ -314,6 +318,8 @@ class ListScheduler(Scheduler, ABC):
             schedule.start_times[dc_op.graph_id] = 0
             schedule.move_operation_alap(dc_op.graph_id)
 
+        schedule.sort_y_locations_on_start_times()
+
     def _get_next_op_id(
         self, ready_ops_priority_table: list[tuple["GraphID", int, ...]]
     ) -> "GraphID":
diff --git a/b_asic/scheduler_gui/scheduler_item.py b/b_asic/scheduler_gui/scheduler_item.py
index dcd4b993..80e09ac6 100644
--- a/b_asic/scheduler_gui/scheduler_item.py
+++ b/b_asic/scheduler_gui/scheduler_item.py
@@ -313,9 +313,8 @@ class SchedulerItem(SchedulerEvent, QGraphicsItemGroup):  # PySide2 / PyQt5
 
     def _redraw_from_start(self) -> None:
         self.schedule._reset_y_locations()
-        for graph_id in dict(
-            sorted(self.schedule.start_times.items(), key=lambda item: item[1])
-        ):
+        self.schedule.sort_y_locations_on_start_times()
+        for graph_id in self.schedule.start_times.keys():
             self._set_position(graph_id)
         self._redraw_all_lines()
         self._update_axes()
-- 
GitLab