From bfe5b0c32b0b9159e9cc3863e735a72d3b5227fc Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Thu, 30 May 2024 09:26:44 +0200
Subject: [PATCH] hash the whole experiment and remove timestamp

this is to have a complete identifier for each run, which does not
depend at all on the time at which the experiment runs.
---
 bins/inbreeding/consts.nu  | 3 +--
 bins/inbreeding/inspect.nu | 1 -
 bins/inbreeding/load.nu    | 4 ++--
 bins/inbreeding/run.nu     | 9 +++++----
 4 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/bins/inbreeding/consts.nu b/bins/inbreeding/consts.nu
index 96aa84ac..080ce247 100644
--- a/bins/inbreeding/consts.nu
+++ b/bins/inbreeding/consts.nu
@@ -5,10 +5,9 @@ const FMT = {
     env: "(?<env>.*)",
     seed: "(?<seed>[a-zA-Z0-9]*)",
     params: '(?<k>\d+)-(?<n>\d+)-(?<nb_bytes>\d+)',
-    timestamp: '(?<timestamp>\d+)',
     strat: "(?<strategy>.*)" ,
 }
 
 export const ARG_EXPERIMENT_FORMAT = $FMT.seed + '-' + $FMT.env + '-' + $FMT.params
-export const EXPERIMENT_FORMAT = $FMT.timestamp + '-' + $FMT.env + '-' + $FMT.strat + '-' + $FMT.params
+export const EXPERIMENT_FORMAT = $FMT.env + '-' + $FMT.strat + '-' + $FMT.params
 export const FULL_EXPERIMENT_FORMAT = $FMT.seed + (char path_sep) + $EXPERIMENT_FORMAT
diff --git a/bins/inbreeding/inspect.nu b/bins/inbreeding/inspect.nu
index 96a908a5..7a34aa8e 100644
--- a/bins/inbreeding/inspect.nu
+++ b/bins/inbreeding/inspect.nu
@@ -8,7 +8,6 @@ def get-seeds [] [ nothing -> list<string> ] {
 export def main [seed: string@get-seeds]: [
     nothing -> table<
         seed: string,
-        timestamp: string,
         env: string,
         strategy: string,
         k: string,
diff --git a/bins/inbreeding/load.nu b/bins/inbreeding/load.nu
index 894b2940..3896ff4d 100644
--- a/bins/inbreeding/load.nu
+++ b/bins/inbreeding/load.nu
@@ -11,7 +11,7 @@ def get-experiments []: nothing -> list<string> {
         | get name
         | each { remove-cache-prefix }
         | parse --regex $consts.FULL_EXPERIMENT_FORMAT
-        | reject timestamp strategy
+        | reject strategy
         | each { values | str join '-' }
         | uniq
 }
@@ -31,7 +31,7 @@ export def main [
     let experiment_path = [
         $consts.CACHE,
         $exp.seed,
-        (['*', $exp.env, '*', $exp.k, $exp.n, $exp.nb_bytes] | str join '-')
+        ([$exp.env, '*', $exp.k, $exp.n, $exp.nb_bytes] | str join '-')
     ]
         | path join
         | into glob
diff --git a/bins/inbreeding/run.nu b/bins/inbreeding/run.nu
index e27cdc85..82eb6084 100644
--- a/bins/inbreeding/run.nu
+++ b/bins/inbreeding/run.nu
@@ -69,19 +69,20 @@ export def main [
         }
     }
 
-    let now = date now | format date "%s%f"
+    let exp_hash = $options | reject strategies | sort | to nuon | hash sha256
 
     for s in $options.strategies {
         let output_dir = [
             $consts.CACHE,
             $"($prng_seed)",
-            ([$now, $options.environment, $s, $options.k, $options.n, $options.nb_bytes] | str join '-')
+            ([$options.environment, $s, $options.k, $options.n, $options.nb_bytes] | str join '-')
         ] | path join
         mkdir $output_dir
         print $"data will be dumped to `($output_dir)`"
 
         for i in 1..$options.nb_scenarii {
-            let output = [ $output_dir, $"($i)" ] | path join
+            let seed = [ $prng_seed, $exp_hash, $s, $i ] | str join | hash sha256
+            let output = [ $output_dir, $seed ] | path join
 
             ^$consts.BIN ...[
                 $options.nb_bytes,
@@ -94,7 +95,7 @@ export def main [
                 --test-case recoding
                 --strategy $s
                 --environment $options.environment
-                --prng-seed ([$prng_seed, $s, $i] | str join | hash sha256)
+                --prng-seed $seed
             ] out> $output
         }
 
-- 
GitLab