From 0bd3a722271ca62601278c04e31e518b1d078a45 Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Fri, 22 Sep 2023 10:40:01 +0100 Subject: [PATCH] Remove duplicated best circuit output --- src/optimiser/taso.rs | 8 ++------ src/optimiser/taso/log.rs | 31 +++++++++---------------------- taso-optimiser/src/main.rs | 5 +++-- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/optimiser/taso.rs b/src/optimiser/taso.rs index 52f6ece6..66c91ab6 100644 --- a/src/optimiser/taso.rs +++ b/src/optimiser/taso.rs @@ -150,9 +150,7 @@ where } } - logger.log_processing_end(circ_cnt, false, timeout_flag); - logger.log_final(&best_circ, best_circ_cost); - + logger.log_processing_end(circ_cnt, best_circ_cost, false, timeout_flag); best_circ } @@ -281,14 +279,12 @@ where } } - logger.log_processing_end(circ_cnt, true, timeout_flag); + logger.log_processing_end(circ_cnt, best_circ_cost, true, timeout_flag); // Drop the channel so the threads know to stop. drop(tx_work); joins.into_iter().for_each(|j| j.join().unwrap()); - logger.log_final(&best_circ, best_circ_cost); - best_circ } } diff --git a/src/optimiser/taso/log.rs b/src/optimiser/taso/log.rs index 5fe734ad..39969ee6 100644 --- a/src/optimiser/taso/log.rs +++ b/src/optimiser/taso/log.rs @@ -2,14 +2,9 @@ use std::io; -use hugr::Hugr; - -use crate::json::save_tk1_json_writer; - /// Logging configuration for the TASO optimiser. #[derive(Default)] pub struct TasoLogger<'w> { - final_circ_writer: Option>, circ_candidates_csv: Option>>, } @@ -24,8 +19,6 @@ impl<'w> TasoLogger<'w> { /// Create a new logging configuration. /// /// Two writer objects must be provided: - /// - best_circ_json_writer: for the final optimised circuit, in TK1 JSON - /// format, /// - best_progress_csv_writer: for a log of the successive best candidate /// circuits, /// @@ -33,13 +26,9 @@ impl<'w> TasoLogger<'w> { /// or [`PROGRESS_TARGET`]. /// /// [`log`]: - pub fn new( - best_circ_json_writer: impl io::Write + 'w, - best_progress_csv_writer: impl io::Write + 'w, - ) -> Self { + pub fn new(best_progress_csv_writer: impl io::Write + 'w) -> Self { let boxed_candidates_writer: Box = Box::new(best_progress_csv_writer); Self { - final_circ_writer: Some(Box::new(best_circ_json_writer)), circ_candidates_csv: Some(csv::Writer::from_writer(boxed_candidates_writer)), } } @@ -56,12 +45,19 @@ impl<'w> TasoLogger<'w> { /// Log the final optimised circuit #[inline] - pub fn log_processing_end(&self, circuit_count: usize, needs_joining: bool, timeout: bool) { + pub fn log_processing_end( + &self, + circuit_count: usize, + best_cost: usize, + needs_joining: bool, + timeout: bool, + ) { if timeout { self.log("Timeout"); } self.log("Optimisation finished"); self.log(format!("Tried {circuit_count} circuits")); + self.log(format!("END RESULT: {}", best_cost)); if needs_joining { self.log("Joining worker threads"); } @@ -84,15 +80,6 @@ impl<'w> TasoLogger<'w> { } } - /// Log the final optimised circuit. - #[inline] - pub fn log_final(&mut self, best_circ: &Hugr, best_cost: usize) { - self.log(format!("END RESULT: {}", best_cost)); - if let Some(circ_writer) = self.final_circ_writer.as_mut() { - save_tk1_json_writer(best_circ, circ_writer).unwrap(); - } - } - /// Internal function to log general events, normally printed to stdout. #[inline] fn log(&self, msg: impl AsRef) { diff --git a/taso-optimiser/src/main.rs b/taso-optimiser/src/main.rs index c01ecaad..95368318 100644 --- a/taso-optimiser/src/main.rs +++ b/taso-optimiser/src/main.rs @@ -103,9 +103,10 @@ fn main() -> Result<(), Box> { let output_path = Path::new(&opts.output); let ecc_path = Path::new(&opts.eccs); - let final_circ_json = fs::File::create("final_circ.json")?; + // TODO: Remove this from the Logger, and use tracing events instead. let circ_candidates_csv = fs::File::create("best_circs.csv")?; - let taso_logger = TasoLogger::new(final_circ_json, circ_candidates_csv); + + let taso_logger = TasoLogger::new(circ_candidates_csv); let circ = load_tk1_json_file(input_path)?;