Skip to content
Snippets Groups Projects
Commit 0d615007 authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

refactor parsing in "inbreeding" (dragoon/komodo!140)

this simply makes "parsing" in the inbreeding modules more robust and centralized.
parent dae90f4c
No related branches found
No related tags found
No related merge requests found
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
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
......
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
}
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
......
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
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment