From bbdda83655a73a52db50eb43929c1fb0b89e90c0 Mon Sep 17 00:00:00 2001
From: Robier Al Kaadi <robal695@student.liu.se>
Date: Mon, 17 Jun 2024 09:01:02 +0000
Subject: [PATCH] Add set_latency_of_type

---
 b_asic/schedule.py | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/b_asic/schedule.py b/b_asic/schedule.py
index 0e6e50ce..7fe533fa 100644
--- a/b_asic/schedule.py
+++ b/b_asic/schedule.py
@@ -526,6 +526,37 @@ class Schedule:
         """
         self._sfg.set_execution_time_of_type(type_name, execution_time)
 
+    def set_latency_of_type(
+        self, type_name: TypeName, latency: int
+    ) -> None:
+        """
+        Set the latency of all operations with the given type name.
+
+        Parameters
+        ----------
+        type_name : TypeName
+            The type name of the operation. For example, obtained as
+            ``Addition.type_name()``.
+        latency : int
+            The latency of the operation.
+        """
+        passed = True
+        for op in self._sfg.operations:
+            if type_name == op.type_name() or type_name == op.graph_id:            
+                change_in_latency = latency - op.latency
+                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 in: {op.graph_id}" 
+                    )
+                    break
+        if change_in_latency < 0 or passed:
+                for op in self._sfg.operations:            
+                    if type_name == op.type_name() or type_name == op.graph_id:           
+                        cast(Operation, op).set_latency(latency)
+ 
+
     def move_y_location(
         self, graph_id: GraphID, new_y: int, insert: bool = False
     ) -> None:
-- 
GitLab