From 03ecf153f87d0125296bfcda082c3785233c0fb4 Mon Sep 17 00:00:00 2001
From: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Date: Fri, 1 Sep 2023 15:39:39 +0200
Subject: [PATCH] More deterministic sorting of processes

---
 b_asic/process.py                | 14 +++++++++++---
 examples/fivepointwinograddft.py |  7 ++++++-
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/b_asic/process.py b/b_asic/process.py
index 95f3695c..833a12a5 100644
--- a/b_asic/process.py
+++ b/b_asic/process.py
@@ -30,9 +30,17 @@ class Process:
         self._name = name
 
     def __lt__(self, other):
-        return self._start_time < other.start_time or (
-            self._start_time == other.start_time
-            and self.execution_time > other.execution_time
+        return (
+            self._start_time < other.start_time
+            or (
+                self._start_time == other.start_time
+                and self.execution_time > other.execution_time
+            )
+            or (  # Sorting on name to possibly get deterministic behavior
+                self._start_time == other.start_time
+                and self.execution_time == other.execution_time
+                and self._name < other.name
+            )
         )
 
     @property
diff --git a/examples/fivepointwinograddft.py b/examples/fivepointwinograddft.py
index 3cbd921c..b1a0186d 100644
--- a/examples/fivepointwinograddft.py
+++ b/examples/fivepointwinograddft.py
@@ -191,7 +191,12 @@ memories[3].assign()
 
 arch.move_process('cmul2.0', 'memory1', 'memory0')
 arch.move_process('bfly3.0', 'memory0', 'memory1')
-arch.move_process('bfly3.1', 'memory4', 'memory0')
+arch.move_process('cmul3.0', 'memory4', 'memory0')
 memories[0].assign()
 memories[1].assign()
 memories[4].assign()
+
+for memory in memories:
+    memory.show_content(title=f"Improved {memory.entity_name}")
+
+arch
-- 
GitLab