From ba1c91fe203bedae53e28944c6fae3742b5a9ae0 Mon Sep 17 00:00:00 2001 From: mamu Date: Tue, 25 Jun 2024 10:35:28 +0900 Subject: [PATCH] Fix CI --- Cargo.lock | 33 +++++++++---------- Cargo.toml | 2 +- kurobako_core/src/domain.rs | 14 ++++---- .../src/epi/problem/external_program.rs | 2 +- kurobako_core/src/trial.rs | 8 +++-- kurobako_problems/src/hpobench.rs | 6 ++-- kurobako_problems/src/nasbench.rs | 11 +++---- kurobako_problems/src/sigopt/functions.rs | 13 +++++--- src/batch_eval.rs | 15 ++++----- src/dataset.rs | 2 +- src/dataset/surrogate.rs | 8 ++--- src/plot.rs | 2 +- src/plot/curve.rs | 11 ++----- src/plot/slice.rs | 3 +- src/problem.rs | 2 +- src/problem/ln.rs | 2 +- src/record/study.rs | 8 ++--- src/record/trial.rs | 2 +- src/solver.rs | 2 +- 19 files changed, 70 insertions(+), 76 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d06108b..b372733 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,12 +471,12 @@ dependencies = [ [[package]] name = "num" -version = "0.3.1" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b7a8e9be5e039e2ff869df49155f1c06bd01ade2117ec783e56ab0932b67a8f" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" dependencies = [ "num-bigint", - "num-complex 0.3.1", + "num-complex 0.4.6", "num-integer", "num-iter", "num-rational", @@ -485,11 +485,10 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.3.1" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e9a41747ae4633fce5adffb4d2e81ffc5e89593cb19917f8fb2cc5ff76507bf" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", ] @@ -506,28 +505,27 @@ dependencies = [ [[package]] name = "num-complex" -version = "0.3.1" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747d632c0c558b87dbabbe6a82f3b4ae03720d0646ac5b7b4dae89394be5f2c5" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", ] [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-iter" -version = "0.1.42" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" dependencies = [ "autocfg", "num-integer", @@ -536,11 +534,10 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.3.2" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "autocfg", "num-bigint", "num-integer", "num-traits", @@ -548,9 +545,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", "libm", diff --git a/Cargo.toml b/Cargo.toml index 6899e1e..dc0c27d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ kurobako_core = { path = "kurobako_core", version = "0.1" } kurobako_problems = { path = "kurobako_problems", version = "0.1" } kurobako_solvers = { path = "kurobako_solvers", version = "0.2" } nasbench = "0.1" -num = "0.3" +num = "0.4" num-integer = "0.1" ordered-float = "2" rand = "0.8" diff --git a/kurobako_core/src/domain.rs b/kurobako_core/src/domain.rs index db2e93e..0decfe9 100644 --- a/kurobako_core/src/domain.rs +++ b/kurobako_core/src/domain.rs @@ -65,8 +65,8 @@ impl VariableBuilder { Self { name: name.to_owned(), range: Range::Continuous { - low: std::f64::NEG_INFINITY, - high: std::f64::INFINITY, + low: f64::NEG_INFINITY, + high: f64::INFINITY, }, distribution: Distribution::Uniform, constraint: None, @@ -75,7 +75,7 @@ impl VariableBuilder { /// Sets the name of this variable. pub fn name(mut self, name: &str) -> Self { - self.name = name.to_owned(); + name.clone_into(&mut self.name); self } @@ -121,7 +121,7 @@ impl VariableBuilder { /// /// This is equivalent to `self.categorical(&["false", "true"])`. pub fn boolean(self) -> Self { - self.categorical(&["false", "true"]) + self.categorical(["false", "true"]) } /// Sets the range of this variable. @@ -242,11 +242,11 @@ fn is_not_finite(x: &f64) -> bool { } fn neg_infinity() -> f64 { - std::f64::NEG_INFINITY + f64::NEG_INFINITY } fn infinity() -> f64 { - std::f64::INFINITY + f64::INFINITY } /// Variable range. @@ -396,7 +396,7 @@ mod tests { let vars = vec![ var("a").continuous(-10.0, 10.0).finish()?, var("b").discrete(0, 5).finish()?, - var("c").categorical(&["foo", "bar", "baz"]).finish()?, + var("c").categorical(["foo", "bar", "baz"]).finish()?, ]; let constraint = Constraint::new("(a + b) < 2"); diff --git a/kurobako_core/src/epi/problem/external_program.rs b/kurobako_core/src/epi/problem/external_program.rs index 7471611..cb323f7 100644 --- a/kurobako_core/src/epi/problem/external_program.rs +++ b/kurobako_core/src/epi/problem/external_program.rs @@ -17,7 +17,7 @@ use structopt::StructOpt; thread_local! { static FACTORY_CACHE : RefCell, ExternalProgramProblemFactory)>> = - RefCell::new(None); + const { RefCell::new(None) }; } /// Recipe for the problem implemented by an external program. diff --git a/kurobako_core/src/trial.rs b/kurobako_core/src/trial.rs index 61117c7..ab1a8fd 100644 --- a/kurobako_core/src/trial.rs +++ b/kurobako_core/src/trial.rs @@ -71,6 +71,11 @@ pub struct EvaluatedTrial { pub struct IdGen { next: u64, } +impl Default for IdGen { + fn default() -> Self { + Self::new() + } +} impl IdGen { /// Makes a new `IdGen` instance. pub const fn new() -> Self { @@ -201,7 +206,6 @@ impl Deref for Values { mod nullable_f64_vec { use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use std::f64::NAN; pub fn deserialize<'de, D>(deserializer: D) -> Result, D::Error> where @@ -209,7 +213,7 @@ mod nullable_f64_vec { { let v: Vec> = Deserialize::deserialize(deserializer)?; Ok(v.into_iter() - .map(|v| if let Some(v) = v { v } else { NAN }) + .map(|v| if let Some(v) = v { v } else { f64::NAN }) .collect()) } diff --git a/kurobako_problems/src/hpobench.rs b/kurobako_problems/src/hpobench.rs index b120e9f..2ada784 100644 --- a/kurobako_problems/src/hpobench.rs +++ b/kurobako_problems/src/hpobench.rs @@ -70,13 +70,13 @@ impl ProblemFactory for HpobenchProblemFactory { arXiv preprint arXiv:1905.04970 (2019).", ) .attr("github", "https://github.com/automl/nas_benchmarks") - .param(domain::var("activation_fn_1").categorical(&["tanh", "relu"])) - .param(domain::var("activation_fn_2").categorical(&["tanh", "relu"])) + .param(domain::var("activation_fn_1").categorical(["tanh", "relu"])) + .param(domain::var("activation_fn_2").categorical(["tanh", "relu"])) .param(domain::var("batch_size").discrete(0, 4)) .param(domain::var("dropout_1").discrete(0, 3)) .param(domain::var("dropout_2").discrete(0, 3)) .param(domain::var("init_lr").discrete(0, 6)) - .param(domain::var("lr_schedule").categorical(&["cosine", "const"])) + .param(domain::var("lr_schedule").categorical(["cosine", "const"])) .param(domain::var("n_units_1").discrete(0, 6)) .param(domain::var("n_units_2").discrete(0, 6)) .value(domain::var("Validation MSE").continuous(0.0, f64::INFINITY)) diff --git a/kurobako_problems/src/nasbench.rs b/kurobako_problems/src/nasbench.rs index 8788a5c..77f19f9 100644 --- a/kurobako_problems/src/nasbench.rs +++ b/kurobako_problems/src/nasbench.rs @@ -214,7 +214,9 @@ impl Evaluator for NasbenchEvaluator { /// [nas_cifar10.py]: https://github.com/automl/nas_benchmarks/blob/c1bae6632bf15d45ba49c269c04dbbeb3f0379f0/tabular_benchmarks/nas_cifar10.py #[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[allow(missing_docs)] +#[derive(Default)] pub enum Encoding { + #[default] A, B, C, @@ -233,7 +235,7 @@ impl Encoding { fn common_params() -> Vec { let mut params = Vec::new(); for i in 0..5 { - params.push(domain::var(&format!("op{}", i)).categorical(&[ + params.push(domain::var(&format!("op{}", i)).categorical([ "conv1x1-bn-relu", "conv3x3-bn-relu", "maxpool3x3", @@ -297,7 +299,7 @@ impl Encoding { fn edges_a(params: &[f64]) -> HashSet { let mut edges = HashSet::new(); for (i, p) in params.iter().enumerate() { - if (*p - 1.0).abs() < std::f64::EPSILON { + if (*p - 1.0).abs() < f64::EPSILON { edges.insert(i); } } @@ -342,11 +344,6 @@ impl FromStr for Encoding { } } } -impl Default for Encoding { - fn default() -> Self { - Encoding::A - } -} /// Evaluation metric. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/kurobako_problems/src/sigopt/functions.rs b/kurobako_problems/src/sigopt/functions.rs index f884837..a26a0d5 100644 --- a/kurobako_problems/src/sigopt/functions.rs +++ b/kurobako_problems/src/sigopt/functions.rs @@ -4,7 +4,6 @@ use super::bessel::bessel0; use kurobako_core::{ErrorKind, Result}; use std::f64::consts::PI; -use std::f64::EPSILON; use std::fmt; use std::iter; @@ -122,7 +121,7 @@ impl TestFunction for Csendes { fn evaluate(&self, xs: &[f64]) -> f64 { xs.iter() - .map(|&x| x.powi(6) * (2.0 + (1.0 / (x + EPSILON)).sin())) + .map(|&x| x.powi(6) * (2.0 + (1.0 / (x + f64::EPSILON)).sin())) .sum() } } @@ -394,7 +393,7 @@ impl McCourtBase { e_mat: &'static [&'static [f64]], ) -> impl 'a + Iterator { e_mat.iter().zip(centers.iter()).map(move |(evec, center)| { - let mut max = std::f64::NEG_INFINITY; + let mut max = f64::NEG_INFINITY; for x in xs .iter() .zip(center.iter()) @@ -2374,7 +2373,7 @@ mod tests { fn shekel05_works() { assert_eq!( Shekel05.evaluate(&[4.0, 4.0, 4.0, 4.0]), - -10.152719932456289 + -10.152_719_932_456_29 ); } @@ -2402,7 +2401,11 @@ mod tests { #[test] fn styblinskitang_works() { assert_eq!( - StyblinskiTang.evaluate(&[-2.903534018185960, -2.903534018185960, -2.903534018185960]), + StyblinskiTang.evaluate(&[ + -2.903_534_018_185_96, + -2.903_534_018_185_96, + -2.903_534_018_185_96 + ]), -117.49849711131424 ); } diff --git a/src/batch_eval.rs b/src/batch_eval.rs index 68f9559..4802cb3 100644 --- a/src/batch_eval.rs +++ b/src/batch_eval.rs @@ -10,10 +10,10 @@ use kurobako_core::trial::{Params, Values}; use kurobako_core::{ErrorKind, Result}; use serde::Deserialize; use serde::Serialize; -use std::io; -use structopt::StructOpt; use serde_json::Error; +use std::io; use std::io::Write; +use structopt::StructOpt; /// Options of the `kurobako batch-evaluate` command. #[derive(Debug, Clone, StructOpt)] @@ -31,7 +31,7 @@ pub struct BatchEvaluateOpt { #[derive(Debug, Clone, Deserialize)] struct EvalCall { params: Params, - step: Option + step: Option, } #[derive(Debug, Clone, Serialize)] @@ -50,7 +50,7 @@ impl BatchEvaluateOpt { let problem = track!(problem_factory.create_problem(rng))?; let mut writer = io::stdout(); - loop{ + loop { let mut line = String::new(); let n = io::stdin().read_line(&mut line)?; if n == 0 { @@ -64,7 +64,6 @@ impl BatchEvaluateOpt { ErrorKind::InvalidInput ); - let evaluator_or_error = track!(problem.create_evaluator(params.clone())); let values = match evaluator_or_error { @@ -72,7 +71,7 @@ impl BatchEvaluateOpt { let s = step.unwrap_or_else(|| problem_spec.steps.last()); let (_, values) = track!(evaluator.evaluate(s))?; values - }, + } Err(e) => { if *e.kind() != ErrorKind::UnevaluableParams { return Err(e); @@ -82,8 +81,8 @@ impl BatchEvaluateOpt { } }; - serde_json::to_writer(&mut writer, &EvalReply{values}).map_err(Error::from)?; - writer.write("\n".as_bytes())?; + serde_json::to_writer(&mut writer, &EvalReply { values }).map_err(Error::from)?; + writer.write_all("\n".as_bytes())?; writer.flush()?; } Ok(()) diff --git a/src/dataset.rs b/src/dataset.rs index 1ab84d6..3a8e1a7 100644 --- a/src/dataset.rs +++ b/src/dataset.rs @@ -69,7 +69,7 @@ impl NasbenchOpt { ); let file = track!( - std::fs::File::open(&tfrecord_format_dataset_path).map_err(Error::from); + std::fs::File::open(tfrecord_format_dataset_path).map_err(Error::from); tfrecord_format_dataset_path )?; let nasbench = track!(nasbench::NasBench::from_tfrecord_reader( diff --git a/src/dataset/surrogate.rs b/src/dataset/surrogate.rs index 9cc821d..6de93c2 100644 --- a/src/dataset/surrogate.rs +++ b/src/dataset/surrogate.rs @@ -90,8 +90,8 @@ impl SurrogateOpt { let mut table = TableBuilder::new(); let column_types = trials[0] .distributions - .iter() - .map(|(_, d)| { + .values() + .map(|d| { if matches!(d, Distribution::CategoricalDistribution { .. }) { ColumnType::Categorical } else { @@ -208,11 +208,11 @@ impl SurrogateOpt { track!(std::fs::create_dir_all(&dir).map_err(Error::from))?; let spec_path = dir.join("spec.json"); - let spec_file = track!(std::fs::File::create(&spec_path).map_err(Error::from))?; + let spec_file = track!(std::fs::File::create(spec_path).map_err(Error::from))?; serde_json::to_writer(spec_file, &spec)?; let regressor_path = dir.join("model.bin"); - let regressor_file = track!(std::fs::File::create(®ressor_path).map_err(Error::from))?; + let regressor_file = track!(std::fs::File::create(regressor_path).map_err(Error::from))?; model.regressor.serialize(BufWriter::new(regressor_file))?; eprintln!("Saved the surrogate model to the direcotry {:?}", dir); diff --git a/src/plot.rs b/src/plot.rs index e15e32d..eb90929 100644 --- a/src/plot.rs +++ b/src/plot.rs @@ -34,7 +34,7 @@ impl PlotOpt { fn execute_gnuplot(script: &str) -> Result<()> { let output = track!(Command::new("gnuplot") - .args(&["-e", script]) + .args(["-e", script]) .output() .map_err(Error::from))?; if !output.status.success() { diff --git a/src/plot/curve.rs b/src/plot/curve.rs index 9f158fd..f6a8f06 100644 --- a/src/plot/curve.rs +++ b/src/plot/curve.rs @@ -276,17 +276,11 @@ impl<'a> Problem<'a> { } fn xmin(&self) -> String { - self.opt - .xmin - .map(|v| v.to_string()) - .unwrap_or_else(|| "".to_string()) + self.opt.xmin.map(|v| v.to_string()).unwrap_or_default() } fn xmax(&self) -> String { - self.opt - .xmax - .map(|v| v.to_string()) - .unwrap_or_else(|| "".to_string()) + self.opt.xmax.map(|v| v.to_string()).unwrap_or_default() } fn generate_data(&self) -> Result { @@ -362,4 +356,5 @@ struct Value { } #[derive(Debug)] +#[allow(dead_code)] struct BestValues {} diff --git a/src/plot/slice.rs b/src/plot/slice.rs index 1738663..3c420f2 100644 --- a/src/plot/slice.rs +++ b/src/plot/slice.rs @@ -56,8 +56,7 @@ impl PlotSliceOpt { .push(record); } - let pb = - ProgressBar::new(studies.iter().map(|(_, s)| s.params_len()).sum::() as u64); + let pb = ProgressBar::new(studies.values().map(|s| s.params_len()).sum::() as u64); let template = "(PLOT) [{elapsed_precise}] [{pos}/{len} {percent:>3}%] [ETA {eta:>3}] {msg}"; pb.set_style(ProgressStyle::default_bar().template(template)); diff --git a/src/problem.rs b/src/problem.rs index c1b64ba..7f39e81 100644 --- a/src/problem.rs +++ b/src/problem.rs @@ -120,7 +120,7 @@ impl ProblemFactory for KurobakoProblemFactory { fn specification(&self) -> Result { let mut spec = track!(self.inner.specification())?; if let Some(name) = &self.name { - spec.name = name.clone(); + spec.name.clone_from(name) } Ok(spec) } diff --git a/src/problem/ln.rs b/src/problem/ln.rs index ed21928..7fdbd7e 100644 --- a/src/problem/ln.rs +++ b/src/problem/ln.rs @@ -80,7 +80,7 @@ impl Problem for LnProblem { .params_domain .variables() .iter() - .zip(params.into_vec().into_iter()) + .zip(params.into_vec()) .map(|(var, val)| { if let Range::Continuous { .. } = var.range() { assert_eq!(var.distribution(), Distribution::LogUniform); diff --git a/src/record/study.rs b/src/record/study.rs index e76369b..77ca033 100644 --- a/src/record/study.rs +++ b/src/record/study.rs @@ -99,7 +99,7 @@ impl StudyRecordBuilder { recipe: self.recipe.problem, spec: self.problem, }, - trials: self.trials.into_iter().map(|(_, v)| v).collect(), + trials: self.trials.into_values().collect(), } } } @@ -163,7 +163,7 @@ impl StudyRecord { .collect::>(); trials.sort_by_key(|t| t.0); - let mut min = std::f64::INFINITY; + let mut min = f64::INFINITY; for (step, value) in trials { if value < min { min = value; @@ -238,7 +238,7 @@ impl StudyRecord { impl<'a> Eq for Entry<'a> {} impl<'a> PartialOrd for Entry<'a> { fn partial_cmp(&self, other: &Self) -> Option { - other.step().partial_cmp(&self.step()) + Some(self.cmp(other)) } } impl<'a> Ord for Entry<'a> { @@ -313,7 +313,7 @@ impl StudyRecord { trials.sort_by_key(|t| t.0); let mut prev_step = 0; - let mut current_min = std::f64::INFINITY; + let mut current_min = f64::INFINITY; let mut auc = 0.0; for (mut step, value) in trials { if step <= start_step { diff --git a/src/record/trial.rs b/src/record/trial.rs index 6148590..f7a07ea 100644 --- a/src/record/trial.rs +++ b/src/record/trial.rs @@ -79,7 +79,7 @@ impl TrialRecord { } pub fn start_step(&self) -> Option { - self.evaluations.get(0).map(|e| e.start_step) + self.evaluations.first().map(|e| e.start_step) } pub fn end_step(&self) -> Option { diff --git a/src/solver.rs b/src/solver.rs index 431a269..0eaa064 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -70,7 +70,7 @@ impl SolverFactory for KurobakoSolverFactory { fn specification(&self) -> Result { let mut spec = track!(self.inner.specification())?; if let Some(name) = &self.name { - spec.name = name.clone(); + spec.name.clone_from(name) } Ok(spec) }