diff --git a/bins/inbreeding/consts.nu b/bins/inbreeding/consts.nu index 080ce247133fc02919b422099634c0170a21c583..177d568cedaf2db37854e65516e47f9fa3a68afc 100644 --- a/bins/inbreeding/consts.nu +++ b/bins/inbreeding/consts.nu @@ -1,13 +1,2 @@ export const BIN = "./target/release/inbreeding" export const CACHE = ($nu.home-path | path join .cache komodo inbreeding) - -const FMT = { - env: "(?<env>.*)", - seed: "(?<seed>[a-zA-Z0-9]*)", - params: '(?<k>\d+)-(?<n>\d+)-(?<nb_bytes>\d+)', - strat: "(?<strategy>.*)" , -} - -export const ARG_EXPERIMENT_FORMAT = $FMT.seed + '-' + $FMT.env + '-' + $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 fd2e70f48e848236247aa18917f2dac69e475dce..cb02c629618ff77d696dd724f456aa9572350f0c 100644 --- a/bins/inbreeding/inspect.nu +++ b/bins/inbreeding/inspect.nu @@ -1,4 +1,5 @@ use consts.nu +use parse.nu [ "parse full-experiment" ] use path.nu [ "remove-cache-prefix" ] def get-seeds [] [ nothing -> list<string> ] { @@ -22,11 +23,7 @@ export def main [seed: string@get-seeds]: [ | ls $in | insert m { ls $in.name | length } | select name m - | update name { - remove-cache-prefix - | parse --regex $consts.FULL_EXPERIMENT_FORMAT - | reject seed - } + | update name { remove-cache-prefix | parse full-experiment | reject seed } | flatten --all name | into int k | into int n diff --git a/bins/inbreeding/list.nu b/bins/inbreeding/list.nu index 208b541a2c191042492355688ec3132532864197..38a386ba51a9ea09d012e8f182a01fb78e85abc6 100644 --- a/bins/inbreeding/list.nu +++ b/bins/inbreeding/list.nu @@ -1,4 +1,5 @@ use consts.nu +use parse.nu [ "parse full-experiment" ] use path.nu [ "remove-cache-prefix" ] # return experiment names following `$ARG_EXPERIMENT_FORMAT` @@ -9,8 +10,7 @@ export def main []: nothing -> list<string> { | ls $in | get name | each { remove-cache-prefix } - | parse --regex $consts.FULL_EXPERIMENT_FORMAT - | reject strategy - | each { values | str join '-' } + | where ($it | path split | first | str length) == 64 + | each { parse full-experiment | reject strategy | values | str join '-' } | uniq } diff --git a/bins/inbreeding/load.nu b/bins/inbreeding/load.nu index 595604bcdcce22099c464e19f20308da5b84e9c3..8581c85b11182e1163326e3b2aeda536c26179b4 100644 --- a/bins/inbreeding/load.nu +++ b/bins/inbreeding/load.nu @@ -1,4 +1,5 @@ use consts.nu +use parse.nu [ "parse arg-experiment", "parse experiment" ] use path.nu [ "remove-cache-prefix" ] use ../../.nushell error "error throw" @@ -12,19 +13,7 @@ export def main [ measurements: table<strategy: string, diversity: table<x: int, y: float, e: float>>, > ] { - let exp = $experiment - | parse --regex $consts.ARG_EXPERIMENT_FORMAT - | into record - | into int k - | into int n - | into int nb_bytes - if $exp == {} { - error throw { - err: "invalid experiment", - label: $"should have format '($consts.ARG_EXPERIMENT_FORMAT)', found ($experiment)", - span: (metadata $experiment).span, - } - } + let exp = $experiment | parse arg-experiment --span (metadata $experiment).span let experiment_path = [ $consts.CACHE, @@ -45,7 +34,7 @@ export def main [ let measurements = $experiment_files | select name - | insert . { get name | remove-cache-prefix | parse --regex $consts.EXPERIMENT_FORMAT } + | insert . { get name | remove-cache-prefix | parse experiment } | flatten --all | insert diversity { ls $in.name diff --git a/bins/inbreeding/parse.nu b/bins/inbreeding/parse.nu new file mode 100644 index 0000000000000000000000000000000000000000..6f251e74af4d4f1214d5454b2526f94f80be7496 --- /dev/null +++ b/bins/inbreeding/parse.nu @@ -0,0 +1,52 @@ +const FMT = { + env: "(?<env>.*)", + seed: "(?<seed>[a-zA-Z0-9]*)", + params: '(?<k>\d+)-(?<n>\d+)-(?<nb_bytes>\d+)', + strat: "(?<strategy>.*)" , +} + +const ARG_EXPERIMENT_FORMAT = $FMT.seed + '-' + $FMT.env + '-' + $FMT.params +const EXPERIMENT_FORMAT = $FMT.env + '-' + $FMT.strat + '-' + $FMT.params +const FULL_EXPERIMENT_FORMAT = $FMT.seed + (char path_sep) + $EXPERIMENT_FORMAT + +export def "parse full-experiment" []: [ + string -> record< + seed: string, env: string, strategy: string, k: int, n: int, nb_bytes: int + > +] { + parse --regex $FULL_EXPERIMENT_FORMAT + | into record + | into int k + | into int n + | into int nb_bytes +} + +export def "parse experiment" []: [ + string -> record<env: string, strategy: string, k: int, n: int, nb_bytes: int> +] { + parse --regex $EXPERIMENT_FORMAT + | into record + | into int k + | into int n + | into int nb_bytes +} + +export def "parse arg-experiment" [--span: record<start: int, end: int>]: [ + string -> record<seed: string, env: string, k: int, n: int, nb_bytes: int> +] { + let exp = $in + | parse --regex $ARG_EXPERIMENT_FORMAT + | into record + | into int k + | into int n + | into int nb_bytes + if $exp == {} { + error throw { + err: "invalid experiment", + label: $"should have format '($ARG_EXPERIMENT_FORMAT)', found ($experiment)", + span: $span, + } + } + + $exp +}