src/main.rs

changeset 9
21b0e537ac0e
parent 6
bcb508479948
child 20
90f77ad9a98d
--- a/src/main.rs	Fri Dec 02 18:14:03 2022 +0200
+++ b/src/main.rs	Fri Dec 02 21:20:04 2022 +0200
@@ -14,11 +14,11 @@
 #![feature(drain_filter)]
 
 use clap::Parser;
+use serde::{Serialize, Deserialize};
+use serde_json;
 use itertools::Itertools;
-use serde_json;
 use std::num::NonZeroUsize;
 
-use alg_tools::iterate::Verbose;
 use alg_tools::parallelism::{
     set_num_threads,
     set_max_threads,
@@ -43,7 +43,6 @@
 use types::{float, ClapFloat};
 use run::{
     DefaultAlgorithm,
-    Configuration,
     PlotLevel,
     Named,
     AlgorithmConfig,
@@ -54,7 +53,7 @@
 use DefaultAlgorithm::*;
 
 /// Command line parameters
-#[derive(Parser, Debug)]
+#[derive(Parser, Debug, Serialize)]
 #[clap(
     about = env!("CARGO_PKG_DESCRIPTION"),
     author = env!("CARGO_PKG_AUTHORS"),
@@ -63,12 +62,14 @@
     after_long_help = "",
 )]
 pub struct CommandLineArgs {
-    #[arg(long, short = 'm', value_name = "M")]
+    #[arg(long, short = 'm', value_name = "M", default_value_t = 2000)]
     /// Maximum iteration count
-    max_iter : Option<usize>,
+    max_iter : usize,
 
     #[arg(long, short = 'n', value_name = "N")]
     /// Output status every N iterations. Set to 0 to disable.
+    ///
+    /// The default is to output status based on logarithmic increments.
     verbose_iter : Option<usize>,
 
     #[arg(long, short = 'q')]
@@ -94,12 +95,12 @@
     #[arg(value_name = "JSON_FILE", long)]
     saved_algorithm : Vec<String>,
 
-    /// Write plots for every verbose iteration
+    /// Plot saving scheme
     #[arg(value_enum, long, short = 'p', default_value_t = PlotLevel::Data)]
     plot : PlotLevel,
 
     /// Directory for saving results
-    #[arg(long, short = 'o', default_value = "out")]
+    #[arg(long, short = 'o', required = true, default_value = "out")]
     outdir : String,
 
     #[arg(long, help_heading = "Multi-threading", default_value = "4")]
@@ -120,7 +121,7 @@
 }
 
 /// Command line experiment setup overrides
-#[derive(Parser, Debug)]
+#[derive(Parser, Debug, Serialize, Deserialize)]
 pub struct ExperimentOverrides<F : ClapFloat> {
     #[arg(long)]
     /// Regularisation parameter override.
@@ -143,7 +144,7 @@
 }
 
 /// Command line algorithm parametrisation overrides
-#[derive(Parser, Debug)]
+#[derive(Parser, Debug, Serialize, Deserialize)]
 pub struct AlgorithmOverrides<F : ClapFloat> {
     #[arg(long, value_names = &["COUNT", "EACH"])]
     /// Override bootstrap insertion iterations for --algorithm.
@@ -222,7 +223,6 @@
 
     for experiment_shorthand in cli.experiments.iter().unique() {
         let experiment = experiment_shorthand.get_experiment(&cli.experiment_overrides).unwrap();
-        let mut config : Configuration<float> = experiment.default_config();
         let mut algs : Vec<Named<AlgorithmConfig<float>>>
             = cli.algorithm.iter()
                             .map(|alg| experiment.algorithm_defaults(*alg, &cli.algoritm_overrides))
@@ -232,16 +232,7 @@
             let alg = serde_json::from_reader(f).unwrap();
             algs.push(alg);
         }
-        cli.max_iter.map(|m| config.iterator_options.max_iter = m);
-        cli.verbose_iter.map(|n| config.iterator_options.verbose_iter = Verbose::Every(n));
-        config.plot = cli.plot;
-        config.iterator_options.quiet = cli.quiet;
-        config.outdir = cli.outdir.clone();
-        if !algs.is_empty() {
-            config.algorithms = algs.clone();
-        }
-
-        experiment.runall(config)
+        experiment.runall(&cli, (!algs.is_empty()).then_some(algs))
                   .unwrap()
     }
 }

mercurial