Skip to content

Commit

Permalink
Merge pull request #42 from optuna/fix-lint-errors
Browse files Browse the repository at this point in the history
Fix clippy warnings
  • Loading branch information
sile committed Apr 20, 2022
2 parents 85094ea + 8dd5f90 commit faa1f05
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 30 deletions.
5 changes: 3 additions & 2 deletions kurobako_core/src/epi/problem/external_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ impl ProblemRecipe for ExternalProgramProblemRecipe {
return Ok(factory.clone());
}
}
*f = Some((key, track!(self.create_new_factory(registry))?));
return Ok(f.as_ref().unwrap().1.clone());
let factory = track!(self.create_new_factory(registry))?;
*f = Some((key, factory.clone()));
Ok(factory)
})
}
}
Expand Down
2 changes: 0 additions & 2 deletions kurobako_problems/src/nasbench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ impl Problem for NasbenchProblem {

Ok(NasbenchEvaluator {
nasbench: Arc::clone(&self.nasbench),
encoding: self.encoding,
metrics: self.metrics.clone(),
model_spec,
sample_index: track!(self.rng.with_lock(|rng| rng.gen()))?,
Expand All @@ -172,7 +171,6 @@ impl Problem for NasbenchProblem {
#[derive(Debug)]
pub struct NasbenchEvaluator {
nasbench: Arc<NasBench>,
encoding: Encoding,
metrics: Vec<Metric>,
model_spec: ModelSpec,
sample_index: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'a, W: Write> MarkdownWriter<'a, W> {
}

pub fn list(&mut self) -> ListWriter<&mut W> {
ListWriter::new(&mut self.writer)
ListWriter::new(self.writer)
}

pub fn write_table(&mut self, table: &Table) -> Result<()> {
Expand Down
5 changes: 5 additions & 0 deletions src/plot/pareto_front.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,18 @@ impl<'a> Study<'a> {

let problem_steps = self.instances[0].problem.spec.steps.last();
for study in &self.instances {
eprintln!("trials: {:?}", study.trials.len());
dbg!(problem_steps);
let mut c = 0;
for trial in &study.trials {
if let Some(vs) = trial.values(problem_steps) {
c += 1;
let end_step = trial.end_step().unwrap_or_else(|| unreachable!());
let budget = end_step as f64 / problem_steps as f64;
track_writeln!(temp_file, "{} {} {}", budget, vs[1], vs[0])?;
}
}
dbg!(c);
}

Ok(temp_file.into_temp_path())
Expand Down
4 changes: 1 addition & 3 deletions src/problem/study.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ impl ProblemFactory for StudyProblemFactory {
track!(spec.finish())
}

fn create_problem(&self, rng: ArcRng) -> Result<Self::Problem> {
fn create_problem(&self, _rng: ArcRng) -> Result<Self::Problem> {
Ok(StudyProblem {
study: self.study.clone(),
vars: self.vars.clone(),
rng,
})
}
}
Expand All @@ -93,7 +92,6 @@ impl ProblemFactory for StudyProblemFactory {
pub struct StudyProblem {
study: JsonRecipe,
vars: Vec<Var>,
rng: ArcRng,
}
impl StudyProblem {
fn bind(&self, vals: &[f64]) -> Result<JsonRecipe> {
Expand Down
28 changes: 6 additions & 22 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use kurobako_core::problem::{
};
use kurobako_core::registry::FactoryRegistry;
use kurobako_core::rng::ArcRng;
use kurobako_core::solver::{
BoxSolver, Solver as _, SolverFactory as _, SolverRecipe as _, SolverSpec,
};
use kurobako_core::solver::{BoxSolver, Solver as _, SolverFactory as _, SolverRecipe as _};
use kurobako_core::trial::Values;
use kurobako_core::trial::{EvaluatedTrial, IdGen, NextTrial, TrialId};
use kurobako_core::{Error, ErrorKind, Result};
Expand Down Expand Up @@ -132,7 +130,7 @@ impl Runner {
recipes[i].take().unwrap_or_else(|| unreachable!())
};

let result = track!(StudyRunner::with_mpb(&recipe, &opt, &mpb, cancel.clone()))
let result = track!(StudyRunner::with_mpb(&recipe, &opt, &mpb))
.and_then(|runner| track!(runner.run()));

fn output(record: StudyRecord) -> Result<()> {
Expand Down Expand Up @@ -178,13 +176,10 @@ impl Runner {
#[derive(Debug)]
pub(crate) struct StudyRunner {
solver: BoxSolver,
solver_spec: SolverSpec,
problem: BoxProblem,
problem_spec: ProblemSpec,
study_record: StudyRecordBuilder,
rng: ArcRng,
pb: ProgressBar,
cancel: Cancel,
idg: IdGen,
threads: EvaluationThreads,
evaluators: HashMap<TrialId, EvaluatorState>,
Expand All @@ -199,17 +194,12 @@ impl StudyRunner {
quiet: true,
};
let mpb = MultiProgress::with_draw_target(ProgressDrawTarget::hidden());
let mut this = track!(Self::with_mpb(study, &opt, &mpb, Cancel::new()))?;
let mut this = track!(Self::with_mpb(study, &opt, &mpb))?;
this._mpb = Some(mpb);
Ok(this)
}

fn with_mpb(
study: &StudyRecipe,
opt: &RunnerOpt,
mpb: &MultiProgress,
cancel: Cancel,
) -> Result<Self> {
fn with_mpb(study: &StudyRecipe, opt: &RunnerOpt, mpb: &MultiProgress) -> Result<Self> {
let registry = FactoryRegistry::new::<KurobakoProblemRecipe, KurobakoSolverRecipe>();

let random_seed = study.seed.unwrap_or_else(rand::random);
Expand Down Expand Up @@ -241,18 +231,14 @@ impl StudyRunner {

let mut recipe = study.clone();
recipe.seed = Some(random_seed);
let study_record =
StudyRecordBuilder::new(recipe, solver_spec.clone(), problem_spec.clone());
let threads = EvaluationThreads::new(study, rng.clone());
let study_record = StudyRecordBuilder::new(recipe, solver_spec, problem_spec.clone());
let threads = EvaluationThreads::new(study, rng);
Ok(Self {
solver,
solver_spec,
problem,
problem_spec,
study_record,
rng,
pb,
cancel,
idg: IdGen::new(),
threads,
evaluators: HashMap::new(),
Expand Down Expand Up @@ -379,7 +365,6 @@ impl StudyRunner {
#[derive(Debug)]
struct EvaluationThreads {
threads: Vec<EvaluationThread>,
evaluators: HashMap<TrialId, EvaluatorState>,
scheduling: Scheduling,
rng: ArcRng,
}
Expand All @@ -389,7 +374,6 @@ impl EvaluationThreads {
threads: (0..recipe.concurrency.get())
.map(EvaluationThread::new)
.collect(),
evaluators: HashMap::new(),
scheduling: recipe.scheduling,
rng,
}
Expand Down

0 comments on commit faa1f05

Please sign in to comment.