From 8448ef57224e1a318d9a62ec19c5e0e9c95d917b Mon Sep 17 00:00:00 2001
From: STEVAN Antoine <antoine.stevan@isae-supaero.fr>
Date: Tue, 28 May 2024 07:35:50 +0000
Subject: [PATCH] dump inbreeding results raw (dragoon/komodo!115)

this will make `inbreeding run` dump all the data as-is to files on disk.
data will be arranged in the following way
- the `$CACHE` is `~/.cache/komodo/inbreeding/`
- each seed will have its own directory: `$CACHE/<seed>/`
- each strategy and environment will have their own directory: `$CACHE/<seed>/<date>/<env>/<strat>/`
- finally each recoding scenario will go to its own subdirectory: `$CACHE/<seed>/<date>/<env>/<strat>/<i>`

> :exclamation: **Important**
> the plotting pipeline is broken for now but will be fixed in later MRs soon...
---
 scripts/inbreeding/run.nu | 50 ++++++++++-----------------------------
 1 file changed, 12 insertions(+), 38 deletions(-)

diff --git a/scripts/inbreeding/run.nu b/scripts/inbreeding/run.nu
index 5cd2716b..6a523b70 100644
--- a/scripts/inbreeding/run.nu
+++ b/scripts/inbreeding/run.nu
@@ -1,8 +1,7 @@
 const BIN = "./target/release/examples/inbreeding"
+const CACHE = ($nu.home-path | path join .cache komodo inbreeding)
 
 export def main [
-    --output: path = "./inbreeding.nuon",
-    --baseline,
     --options: record<
         nb_bytes: int,
         k: int,
@@ -23,24 +22,16 @@ export def main [
         }
     }
 
-    if $baseline {
-        ^$BIN ...[
-            $options.nb_bytes,
-            -k $options.k
-            -n $options.n
-            --nb-measurements $options.nb_measurements
-            --measurement-schedule $options.measurement_schedule
-            --measurement-schedule-start $options.measurement_schedule_start
-            -t $options.max_t
-            --test-case end-to-end
-            --prng-seed $prng_seed
-        ] | lines | into float | save --force baseline.nuon
+    let now = date now | format date "%s%f"
 
-        print "baseline saved to `baseline.nuon`"
-    }
+    for s in $options.strategies {
+        let output_dir = [ $CACHE, $"($prng_seed)", $now, $options.environment, $"($s)" ] | 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
 
-    $options.strategies | each {|s|
-        let res = 1..$options.nb_scenarii | each {
             ^$BIN ...[
                 $options.nb_bytes,
                 -k $options.k
@@ -53,26 +44,9 @@ export def main [
                 --strategy $s
                 --environment $options.environment
                 --prng-seed $prng_seed
-            ]
-                | lines
-                | parse "{t}, {diversity}"
-                | into float diversity
-        }
-
-        let diversity = $res
-            | flatten
-            | group-by t --to-table
-            | update items { get diversity | math avg }
-            | rename --column { group: "t", items: "diversity" }
-            | into int t # NOTE: $.t needs to be converted to int here because
-                         # `group-by --to-table` converts the grouping key to
-                         # string
-
-        {
-            strategy: $s,
-            diversity: $diversity,
+            ] out> $output
         }
-    } | save --force $output
 
-    print $"results saved to `($output)`"
+        print $"data has been dumped to `($output_dir)`"
+    }
 }
-- 
GitLab