From a4bc628b2426a1f3eeac002bffbff3dc9fe495ea Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Wed, 29 May 2024 13:18:18 +0200 Subject: [PATCH 1/6] add missing error import --- bins/inbreeding/load.nu | 1 + 1 file changed, 1 insertion(+) diff --git a/bins/inbreeding/load.nu b/bins/inbreeding/load.nu index b0437ca6..7b2ee194 100644 --- a/bins/inbreeding/load.nu +++ b/bins/inbreeding/load.nu @@ -1,4 +1,5 @@ use consts.nu +use ../../.nushell error "error throw" def get-experiments []: nothing -> list<string> { $consts.CACHE -- GitLab From 5f615a502ea6e945e2f43df48129ab65c8343cee Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Wed, 29 May 2024 13:50:09 +0200 Subject: [PATCH 2/6] add k, n and #bytes to the experiment paths --- bins/inbreeding/load.nu | 33 ++++++++++++++++++++++++--------- bins/inbreeding/run.nu | 6 +++++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/bins/inbreeding/load.nu b/bins/inbreeding/load.nu index 7b2ee194..a30a990c 100644 --- a/bins/inbreeding/load.nu +++ b/bins/inbreeding/load.nu @@ -1,30 +1,44 @@ use consts.nu use ../../.nushell error "error throw" +const EXPERIMENT_FORMAT = "{seed}-{env}-{k}-{n}-{nb_bytes}" +const FULL_EXPERIMENT_FORMAT = "{seed}/{timestamp}-{env}-{strategy}-{k}-{n}-{nb_bytes}" +const OTHER_EXPERIMENT_FORMAT = "{timestamp}-{env}-{strategy}-{k}-{n}-{nb_bytes}" + +def remove-cache-prefix []: path -> string { + str replace $"($consts.CACHE)(char path_sep)" '' +} + def get-experiments []: nothing -> list<string> { $consts.CACHE - | path join '*' '*' '*' + | path join '*' '*' | into glob | ls $in | get name - | path split - | each { last 3 | reject 1 | str join "-" } + | each { remove-cache-prefix } + | parse $FULL_EXPERIMENT_FORMAT + | reject timestamp strategy + | each { values | str join '-' } | uniq } export def main [ - experiment: string@get-experiments, # something of the form '<seed>-<env>' + experiment: string@get-experiments, ]: nothing -> table<strategy: string, diversity: table<x: int, y: float, e: float>> { - let exp = $experiment | parse "{seed}-{env}" | into record + let exp = $experiment | parse $EXPERIMENT_FORMAT | into record if $exp == {} { error throw { err: "invalid experiment", - label: $"should have format '<seed>-<env>', found ($experiment)", + label: $"should have format '($EXPERIMENT_FORMAT)', found ($experiment)", span: (metadata $experiment).span, } } - let experiment_path = [$consts.CACHE, $exp.seed, '*', $exp.env, '*' ] + let experiment_path = [ + $consts.CACHE, + $exp.seed, + (['*', $exp.env, '*', $exp.k, $exp.n, $exp.nb_bytes] | str join '-') + ] | path join | into glob let experiment_files = try { @@ -38,8 +52,9 @@ export def main [ } $experiment_files - | insert strategy { get name | path split | last } - | select name strategy + | select name + | insert foo { get name | remove-cache-prefix | parse $OTHER_EXPERIMENT_FORMAT } + | flatten --all | insert diversity { ls $in.name | each { get name | open | lines } diff --git a/bins/inbreeding/run.nu b/bins/inbreeding/run.nu index f18f72c1..1d26c52c 100644 --- a/bins/inbreeding/run.nu +++ b/bins/inbreeding/run.nu @@ -25,7 +25,11 @@ export def main [ let now = date now | format date "%s%f" for s in $options.strategies { - let output_dir = [ $consts.CACHE, $"($prng_seed)", $now, $options.environment, $"($s)" ] | path join + let output_dir = [ + $consts.CACHE, + $"($prng_seed)", + ([$now, $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)`" -- GitLab From 9b66817c01b03530132eb54fbb334081bfb21e19 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Wed, 29 May 2024 14:01:42 +0200 Subject: [PATCH 3/6] simplify run --- bins/inbreeding/run.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bins/inbreeding/run.nu b/bins/inbreeding/run.nu index 1d26c52c..5b01dfce 100644 --- a/bins/inbreeding/run.nu +++ b/bins/inbreeding/run.nu @@ -28,7 +28,7 @@ export def main [ let output_dir = [ $consts.CACHE, $"($prng_seed)", - ([$now, $options.environment, $"($s)", $options.k, $options.n, $options.nb_bytes] | str join '-') + ([$now, $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)`" -- GitLab From 8fc68114e1e951b90c94eecaf3f12dcf64931df6 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Wed, 29 May 2024 14:05:45 +0200 Subject: [PATCH 4/6] better constant names --- bins/inbreeding/load.nu | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bins/inbreeding/load.nu b/bins/inbreeding/load.nu index a30a990c..f74dc405 100644 --- a/bins/inbreeding/load.nu +++ b/bins/inbreeding/load.nu @@ -1,14 +1,15 @@ use consts.nu use ../../.nushell error "error throw" -const EXPERIMENT_FORMAT = "{seed}-{env}-{k}-{n}-{nb_bytes}" -const FULL_EXPERIMENT_FORMAT = "{seed}/{timestamp}-{env}-{strategy}-{k}-{n}-{nb_bytes}" -const OTHER_EXPERIMENT_FORMAT = "{timestamp}-{env}-{strategy}-{k}-{n}-{nb_bytes}" +const ARG_EXPERIMENT_FORMAT = "{seed}-{env}-{k}-{n}-{nb_bytes}" +const EXPERIMENT_FORMAT = "{timestamp}-{env}-{strategy}-{k}-{n}-{nb_bytes}" +const FULL_EXPERIMENT_FORMAT = $"{seed}(char path_sep)($EXPERIMENT_FORMAT)" def remove-cache-prefix []: path -> string { str replace $"($consts.CACHE)(char path_sep)" '' } +# return experiment names following `$ARG_EXPERIMENT_FORMAT` def get-experiments []: nothing -> list<string> { $consts.CACHE | path join '*' '*' @@ -25,11 +26,11 @@ def get-experiments []: nothing -> list<string> { export def main [ experiment: string@get-experiments, ]: nothing -> table<strategy: string, diversity: table<x: int, y: float, e: float>> { - let exp = $experiment | parse $EXPERIMENT_FORMAT | into record + let exp = $experiment | parse $ARG_EXPERIMENT_FORMAT | into record if $exp == {} { error throw { err: "invalid experiment", - label: $"should have format '($EXPERIMENT_FORMAT)', found ($experiment)", + label: $"should have format '($ARG_EXPERIMENT_FORMAT)', found ($experiment)", span: (metadata $experiment).span, } } @@ -53,7 +54,7 @@ export def main [ $experiment_files | select name - | insert foo { get name | remove-cache-prefix | parse $OTHER_EXPERIMENT_FORMAT } + | insert foo { get name | remove-cache-prefix | parse $EXPERIMENT_FORMAT } | flatten --all | insert diversity { ls $in.name -- GitLab From 5dafc825d1e1409a5a6ce33a32ec25460fc6758a Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Wed, 29 May 2024 14:06:23 +0200 Subject: [PATCH 5/6] replace foo with . as "unnamed" column --- bins/inbreeding/load.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bins/inbreeding/load.nu b/bins/inbreeding/load.nu index f74dc405..9537b96b 100644 --- a/bins/inbreeding/load.nu +++ b/bins/inbreeding/load.nu @@ -54,7 +54,7 @@ export def main [ $experiment_files | select name - | insert foo { get name | remove-cache-prefix | parse $EXPERIMENT_FORMAT } + | insert . { get name | remove-cache-prefix | parse $EXPERIMENT_FORMAT } | flatten --all | insert diversity { ls $in.name -- GitLab From a6cb84c9cd3b7f6cfcd080e1785a26d80a43c2a0 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Wed, 29 May 2024 14:09:02 +0200 Subject: [PATCH 6/6] update README commands --- bins/inbreeding/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bins/inbreeding/README.md b/bins/inbreeding/README.md index 4519a70c..dc77e786 100644 --- a/bins/inbreeding/README.md +++ b/bins/inbreeding/README.md @@ -36,6 +36,6 @@ inbreeding build inbreeding run --options $OPTS --prng-seed $PRNG_SEED ``` ```bash -let experiment = $"($PRNG_SEED)-($OPTS.environment)" +let experiment = $"($PRNG_SEED)-($OPTS.environment)-($OPTS.k)-($OPTS.n)-($OPTS.nb_bytes)" inbreeding load $experiment | inbreeding plot --options { k: $OPTS.k } ``` -- GitLab