Subject: Re: bug#50672: nnpack is not reproducible

From: Ludovic Courtès <[email-masked]>
Date: Fri, 22 Oct 2021 17:31:08 +0200

Hi,

Ludovic Courtès <[email-masked]> skribis:

> No, I’ve retitled it.  Now looking at PeachPy:
>
>   https://github.com/Maratyszcza/PeachPy/issues/88

For the record, I tried the attached patch in an attempt to sort things
as discussed in the issue above, but it doesn’t have the intended
effect.  There must be other unsorted dictionaries elsewhere.

Suggestions welcome!

Ludo’.

Make PeachPy processes deterministic:

  https://github.com/Maratyszcza/PeachPy/issues/88
  https://issues.guix.gnu.org/50672

diff --git a/peachpy/name.py b/peachpy/name.py
index b6a03dc..c069fc2 100644
--- a/peachpy/name.py
+++ b/peachpy/name.py
@@ -95,6 +95,10 @@ class Namespace:
             self.prenames[scope_name.prename].add(scope)
 
     def assign_names(self):
+        # Step 0: sort the dictionary for deterministic output
+        self.prenames = dict(sorted(self.prenames.items(),
+                                    key=lambda item: "" if item[0] == None else item[0]))
+
         # Step 1: assign names to symbols with prenames with no conflicts
         for prename in six.iterkeys(self.prenames):
             if prename is not None: