From e8ed5f62a7de935b36c7a11e5767d21168c2a987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= <121866228+aborgna-q@users.noreply.github.com> Date: Wed, 8 Nov 2023 18:28:39 +0100 Subject: [PATCH] refactor: s/taso/badger/ (#228) Closes #224 --- Cargo.toml | 2 +- .../Cargo.toml | 2 +- .../src/main.rs | 12 +-- .../src/tracing.rs | 2 +- tket2-py/README.md | 2 +- tket2-py/src/optimiser.rs | 30 +++---- tket2-py/src/passes.rs | 16 ++-- tket2-py/test/test_optimiser.py | 4 +- tket2-py/test/test_pass.py | 8 +- tket2-py/tket2/passes.py | 18 ++-- tket2/src/optimiser.rs | 8 +- tket2/src/optimiser/{taso.rs => badger.rs} | 88 ++++++++++--------- .../{taso => badger}/eq_circ_class.rs | 0 .../{taso => badger}/hugr_pchannel.rs | 2 +- .../optimiser/{taso => badger}/hugr_pqueue.rs | 0 tket2/src/optimiser/{taso => badger}/log.rs | 18 ++-- .../optimiser/{taso => badger}/qtz_circuit.rs | 0 .../src/optimiser/{taso => badger}/worker.rs | 14 +-- tket2/src/rewrite/ecc_rewriter.rs | 2 +- tket2/tests/taso_termination.rs | 8 +- 20 files changed, 119 insertions(+), 117 deletions(-) rename {taso-optimiser => badger-optimiser}/Cargo.toml (96%) rename {taso-optimiser => badger-optimiser}/src/main.rs (93%) rename {taso-optimiser => badger-optimiser}/src/tracing.rs (96%) rename tket2/src/optimiser/{taso.rs => badger.rs} (85%) rename tket2/src/optimiser/{taso => badger}/eq_circ_class.rs (100%) rename tket2/src/optimiser/{taso => badger}/hugr_pchannel.rs (99%) rename tket2/src/optimiser/{taso => badger}/hugr_pqueue.rs (100%) rename tket2/src/optimiser/{taso => badger}/log.rs (91%) rename tket2/src/optimiser/{taso => badger}/qtz_circuit.rs (100%) rename tket2/src/optimiser/{taso => badger}/worker.rs (86%) diff --git a/Cargo.toml b/Cargo.toml index fc07a6dd..b8324214 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ lto = "thin" [workspace] resolver = "2" -members = ["tket2", "tket2-py", "compile-rewriter", "taso-optimiser"] +members = ["tket2", "tket2-py", "compile-rewriter", "badger-optimiser"] default-members = ["tket2"] [workspace.package] diff --git a/taso-optimiser/Cargo.toml b/badger-optimiser/Cargo.toml similarity index 96% rename from taso-optimiser/Cargo.toml rename to badger-optimiser/Cargo.toml index a8fcd5af..45a50b44 100644 --- a/taso-optimiser/Cargo.toml +++ b/badger-optimiser/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "taso-optimiser" +name = "badger-optimiser" edition = { workspace = true } version = { workspace = true } rust-version = { workspace = true } diff --git a/taso-optimiser/src/main.rs b/badger-optimiser/src/main.rs similarity index 93% rename from taso-optimiser/src/main.rs rename to badger-optimiser/src/main.rs index be58c97a..77ed69ca 100644 --- a/taso-optimiser/src/main.rs +++ b/badger-optimiser/src/main.rs @@ -11,8 +11,8 @@ use std::process::exit; use clap::Parser; use tket2::json::{load_tk1_json_file, save_tk1_json_file}; -use tket2::optimiser::taso::log::TasoLogger; -use tket2::optimiser::TasoOptimiser; +use tket2::optimiser::badger::log::BadgerLogger; +use tket2::optimiser::BadgerOptimiser; #[cfg(feature = "peak_alloc")] #[global_allocator] @@ -58,7 +58,7 @@ struct CmdLineArgs { #[arg( short, long, - default_value = "taso-optimisation.log", + default_value = "badger-optimisation.log", value_name = "LOGFILE", help = "Logfile to to output the progress of the optimisation." )] @@ -117,12 +117,12 @@ fn main() -> Result<(), Box> { // TODO: Remove this from the Logger, and use tracing events instead. let circ_candidates_csv = BufWriter::new(File::create("best_circs.csv")?); - let taso_logger = TasoLogger::new(circ_candidates_csv); + let badger_logger = BadgerLogger::new(circ_candidates_csv); let circ = load_tk1_json_file(input_path)?; println!("Compiling rewriter..."); - let Ok(optimiser) = TasoOptimiser::default_with_eccs_json_file(ecc_path) else { + let Ok(optimiser) = BadgerOptimiser::default_with_eccs_json_file(ecc_path) else { eprintln!( "Unable to load ECC file {:?}. Is it a JSON file of Quartz-generated ECCs?", ecc_path @@ -141,7 +141,7 @@ fn main() -> Result<(), Box> { println!("Optimising..."); let opt_circ = optimiser.optimise_with_log( &circ, - taso_logger, + badger_logger, opts.timeout, n_threads, opts.split_circ, diff --git a/taso-optimiser/src/tracing.rs b/badger-optimiser/src/tracing.rs similarity index 96% rename from taso-optimiser/src/tracing.rs rename to badger-optimiser/src/tracing.rs index 30172e3a..7b590e31 100644 --- a/taso-optimiser/src/tracing.rs +++ b/badger-optimiser/src/tracing.rs @@ -3,7 +3,7 @@ use std::fs::File; use std::io::BufWriter; use std::path::PathBuf; -use tket2::optimiser::taso::log::{LOG_TARGET, METRICS_TARGET, PROGRESS_TARGET}; +use tket2::optimiser::badger::log::{LOG_TARGET, METRICS_TARGET, PROGRESS_TARGET}; use tracing::{Metadata, Subscriber}; use tracing_appender::non_blocking; diff --git a/tket2-py/README.md b/tket2-py/README.md index 609ea527..5435981e 100644 --- a/tket2-py/README.md +++ b/tket2-py/README.md @@ -10,5 +10,5 @@ A clean python 3.10 environment with `maturin` installed. At which point running `maturin develop` in this directory should build and install the package in the environment. Run `pytest` in this directory to test everything is working. -Don't forget to use the `--release` flag when using TASO and other heavy +Don't forget to use the `--release` flag when using Badger and other heavy computational workloads. \ No newline at end of file diff --git a/tket2-py/src/optimiser.rs b/tket2-py/src/optimiser.rs index 3f1b4bfd..76d8c40e 100644 --- a/tket2-py/src/optimiser.rs +++ b/tket2-py/src/optimiser.rs @@ -1,42 +1,42 @@ -//! PyO3 wrapper for the TASO circuit optimiser. +//! PyO3 wrapper for the Badger circuit optimiser. use std::io::BufWriter; use std::{fs, num::NonZeroUsize, path::PathBuf}; use hugr::Hugr; use pyo3::prelude::*; -use tket2::optimiser::{DefaultTasoOptimiser, TasoLogger}; +use tket2::optimiser::{BadgerLogger, DefaultBadgerOptimiser}; use crate::circuit::update_hugr; /// The module definition pub fn module(py: Python) -> PyResult<&PyModule> { let m = PyModule::new(py, "_optimiser")?; - m.add_class::()?; + m.add_class::()?; Ok(m) } -/// Wrapped [`DefaultTasoOptimiser`]. +/// Wrapped [`DefaultBadgerOptimiser`]. /// /// Currently only exposes loading from an ECC file using the constructor /// and optimising using default logging settings. -#[pyclass(name = "TasoOptimiser")] -pub struct PyTasoOptimiser(DefaultTasoOptimiser); +#[pyclass(name = "BadgerOptimiser")] +pub struct PyBadgerOptimiser(DefaultBadgerOptimiser); #[pymethods] -impl PyTasoOptimiser { - /// Create a new [`PyDefaultTasoOptimiser`] from a precompiled rewriter. +impl PyBadgerOptimiser { + /// Create a new [`PyDefaultBadgerOptimiser`] from a precompiled rewriter. #[staticmethod] pub fn load_precompiled(path: PathBuf) -> Self { - Self(DefaultTasoOptimiser::default_with_rewriter_binary(path).unwrap()) + Self(DefaultBadgerOptimiser::default_with_rewriter_binary(path).unwrap()) } - /// Create a new [`PyDefaultTasoOptimiser`] from ECC sets. + /// Create a new [`PyDefaultBadgerOptimiser`] from ECC sets. /// /// This will compile the rewriter from the provided ECC JSON file. #[staticmethod] pub fn compile_eccs(path: &str) -> Self { - Self(DefaultTasoOptimiser::default_with_eccs_json_file(path).unwrap()) + Self(DefaultBadgerOptimiser::default_with_eccs_json_file(path).unwrap()) } /// Run the optimiser on a circuit. @@ -79,7 +79,7 @@ impl PyTasoOptimiser { } } -impl PyTasoOptimiser { +impl PyBadgerOptimiser { /// The Python optimise method, but on Hugrs. pub(super) fn optimise( &self, @@ -90,16 +90,16 @@ impl PyTasoOptimiser { log_progress: Option, queue_size: Option, ) -> Hugr { - let taso_logger = log_progress + let badger_logger = log_progress .map(|file_name| { let log_file = fs::File::create(file_name).unwrap(); let log_file = BufWriter::new(log_file); - TasoLogger::new(log_file) + BadgerLogger::new(log_file) }) .unwrap_or_default(); self.0.optimise_with_log( &circ, - taso_logger, + badger_logger, timeout, n_threads.unwrap_or(NonZeroUsize::new(1).unwrap()), split_circ.unwrap_or(false), diff --git a/tket2-py/src/passes.rs b/tket2-py/src/passes.rs index bd3ce2fb..c9aef2bb 100644 --- a/tket2-py/src/passes.rs +++ b/tket2-py/src/passes.rs @@ -6,7 +6,7 @@ use tket_json_rs::circuit_json::SerialCircuit; use crate::{ circuit::{try_update_hugr, try_with_hugr}, - optimiser::PyTasoOptimiser, + optimiser::PyBadgerOptimiser, }; /// The module definition @@ -15,7 +15,7 @@ use crate::{ pub fn module(py: Python) -> PyResult<&PyModule> { let m = PyModule::new(py, "_passes")?; m.add_function(wrap_pyfunction!(greedy_depth_reduce, m)?)?; - m.add_function(wrap_pyfunction!(taso_optimise, m)?)?; + m.add_function(wrap_pyfunction!(badger_optimise, m)?)?; m.add_class::()?; m.add( "PullForwardError", @@ -56,10 +56,10 @@ fn rebase_nam(circ: &PyObject) -> PyResult<()> { }) } -/// TASO optimisation pass. +/// Badger optimisation pass. /// /// HyperTKET's best attempt at optimising a circuit using circuit rewriting -/// and the given TASO optimiser. +/// and the given Badger optimiser. /// /// By default, the input circuit will be rebased to Nam, i.e. CX + Rz + H before /// optimising. This can be deactivated by setting `rebase` to `false`, in which @@ -71,9 +71,9 @@ fn rebase_nam(circ: &PyObject) -> PyResult<()> { /// /// Log files will be written to the directory `log_dir` if specified. #[pyfunction] -fn taso_optimise( +fn badger_optimise( circ: PyObject, - optimiser: &PyTasoOptimiser, + optimiser: &PyBadgerOptimiser, max_threads: Option, timeout: Option, log_dir: Option, @@ -92,7 +92,7 @@ fn taso_optimise( rebase_nam(&circ)?; } // Logic to choose how to split the circuit - let taso_splits = |n_threads: NonZeroUsize| match n_threads.get() { + let badger_splits = |n_threads: NonZeroUsize| match n_threads.get() { n if n >= 7 => ( vec![n, 3, 1], vec![timeout / 2, timeout / 10 * 3, timeout / 10 * 2], @@ -115,7 +115,7 @@ fn taso_optimise( (n_cx / 50).try_into().unwrap_or(1.try_into().unwrap()), max_threads, ); - let (split_threads, split_timeouts) = taso_splits(n_threads); + let (split_threads, split_timeouts) = badger_splits(n_threads); for (i, (n_threads, timeout)) in split_threads.into_iter().zip(split_timeouts).enumerate() { let log_file = log_dir.as_ref().map(|log_dir| { let mut log_file = log_dir.clone(); diff --git a/tket2-py/test/test_optimiser.py b/tket2-py/test/test_optimiser.py index eeab2ce7..d0692d1a 100644 --- a/tket2-py/test/test_optimiser.py +++ b/tket2-py/test/test_optimiser.py @@ -1,11 +1,11 @@ from pytket import Circuit -from tket2.optimiser import TasoOptimiser +from tket2.optimiser import BadgerOptimiser def test_simple_optimiser(): """a simple circuit matching test""" c = Circuit(3).CX(0, 1).CX(0, 1).CX(1, 2) - opt = TasoOptimiser.compile_eccs("test_files/cx_cx_eccs.json") + opt = BadgerOptimiser.compile_eccs("test_files/cx_cx_eccs.json") # optimise for 1s cc = opt.optimise(c, 3) diff --git a/tket2-py/test/test_pass.py b/tket2-py/test/test_pass.py index 392a48eb..b0f1284b 100644 --- a/tket2-py/test/test_pass.py +++ b/tket2-py/test/test_pass.py @@ -1,9 +1,9 @@ from pytket import Circuit, OpType -from tket2.passes import taso_pass +from tket2.passes import badger_pass -def test_simple_taso_pass_no_opt(): +def test_simple_badger_pass_no_opt(): c = Circuit(3).CCX(0, 1, 2) - taso = taso_pass(max_threads=1, timeout=0) - taso.apply(c) + badger = badger_pass(max_threads=1, timeout=0) + badger.apply(c) assert c.n_gates_of_type(OpType.CX) == 6 diff --git a/tket2-py/tket2/passes.py b/tket2-py/tket2/passes.py index 34dc76cb..28b2fe6b 100644 --- a/tket2-py/tket2/passes.py +++ b/tket2-py/tket2/passes.py @@ -12,33 +12,33 @@ from .tket2 import _passes __all__ = [ - "taso_pass", + "badger_pass", *_passes.__all__, ] -def taso_pass( +def badger_pass( rewriter: Optional[Path] = None, max_threads: Optional[int] = None, timeout: Optional[int] = None, log_dir: Optional[Path] = None, rebase: Optional[bool] = None, ) -> CustomPass: - """Construct a TASO pass. + """Construct a Badger pass. - The Taso optimiser requires a pre-compiled rewriter produced by the - `compile-rewriter `_ + The Badger optimiser requires a pre-compiled rewriter produced by the + `compile-rewriter `_ utility. If `rewriter` is not specified, a default one will be used. The arguments `max_threads`, `timeout`, `log_dir` and `rebase` are optional - and will be passed on to the TASO optimiser if provided.""" + and will be passed on to the Badger optimiser if provided.""" if rewriter is None: rewriter = Path(importlib.resources.files("tket2").joinpath("data/nam_6_3.rwr")) - opt = optimiser.TasoOptimiser.load_precompiled(rewriter) + opt = optimiser.BadgerOptimiser.load_precompiled(rewriter) def apply(circuit: Circuit) -> Circuit: - """Apply TASO optimisation to the circuit.""" - return _passes.taso_optimise( + """Apply Badger optimisation to the circuit.""" + return _passes.badger_optimise( circuit, opt, max_threads, diff --git a/tket2/src/optimiser.rs b/tket2/src/optimiser.rs index 4656d0be..d61277e3 100644 --- a/tket2/src/optimiser.rs +++ b/tket2/src/optimiser.rs @@ -1,9 +1,9 @@ //! Optimisers for circuit rewriting. //! -//! Currently, the only optimiser is TASO +//! Currently, the only optimiser is Badger -pub mod taso; +pub mod badger; #[cfg(feature = "portmatching")] -pub use taso::DefaultTasoOptimiser; -pub use taso::{TasoLogger, TasoOptimiser}; +pub use badger::DefaultBadgerOptimiser; +pub use badger::{BadgerLogger, BadgerOptimiser}; diff --git a/tket2/src/optimiser/taso.rs b/tket2/src/optimiser/badger.rs similarity index 85% rename from tket2/src/optimiser/taso.rs rename to tket2/src/optimiser/badger.rs index ff906770..a7a3c6b8 100644 --- a/tket2/src/optimiser/taso.rs +++ b/tket2/src/optimiser/badger.rs @@ -1,6 +1,6 @@ -//! TASO circuit optimiser. +//! Badger circuit optimiser. //! -//! This module implements the TASO circuit optimiser. It relies on a rewriter +//! This module implements the Badger circuit optimiser. It relies on a rewriter //! and a RewriteStrategy instance to repeatedly rewrite a circuit and optimising //! it according to some cost metric (typically gate count). //! @@ -22,7 +22,7 @@ use crossbeam_channel::select; pub use eq_circ_class::{load_eccs_json_file, EqCircClass}; use fxhash::FxHashSet; use hugr::hugr::HugrError; -pub use log::TasoLogger; +pub use log::BadgerLogger; use std::num::NonZeroUsize; use std::time::{Duration, Instant}; @@ -32,15 +32,15 @@ use hugr::Hugr; use crate::circuit::cost::CircuitCost; use crate::circuit::CircuitHash; -use crate::optimiser::taso::hugr_pchannel::{HugrPriorityChannel, PriorityChannelLog}; -use crate::optimiser::taso::hugr_pqueue::{Entry, HugrPQ}; -use crate::optimiser::taso::worker::TasoWorker; +use crate::optimiser::badger::hugr_pchannel::{HugrPriorityChannel, PriorityChannelLog}; +use crate::optimiser::badger::hugr_pqueue::{Entry, HugrPQ}; +use crate::optimiser::badger::worker::BadgerWorker; use crate::passes::CircuitChunks; use crate::rewrite::strategy::RewriteStrategy; use crate::rewrite::Rewriter; use crate::Circuit; -/// The TASO optimiser. +/// The Badger optimiser. /// /// Adapted from [Quartz][], and originally [TASO][]. /// @@ -57,13 +57,13 @@ use crate::Circuit; /// [Quartz]: https://arxiv.org/abs/2204.09033 /// [TASO]: https://dl.acm.org/doi/10.1145/3341301.3359630 #[derive(Clone, Debug)] -pub struct TasoOptimiser { +pub struct BadgerOptimiser { rewriter: R, strategy: S, } -impl TasoOptimiser { - /// Create a new TASO optimiser. +impl BadgerOptimiser { + /// Create a new Badger optimiser. pub fn new(rewriter: R, strategy: S) -> Self { Self { rewriter, strategy } } @@ -76,13 +76,13 @@ impl TasoOptimiser { } } -impl TasoOptimiser +impl BadgerOptimiser where R: Rewriter + Send + Clone + 'static, S: RewriteStrategy + Send + Sync + Clone + 'static, S::Cost: serde::Serialize + Send + Sync, { - /// Run the TASO optimiser on a circuit. + /// Run the Badger optimiser on a circuit. /// /// A timeout (in seconds) can be provided. pub fn optimise( @@ -103,13 +103,13 @@ where ) } - /// Run the TASO optimiser on a circuit with logging activated. + /// Run the Badger optimiser on a circuit with logging activated. /// /// A timeout (in seconds) can be provided. pub fn optimise_with_log( &self, circ: &Hugr, - log_config: TasoLogger, + log_config: BadgerLogger, timeout: Option, n_threads: NonZeroUsize, split_circuit: bool, @@ -121,16 +121,16 @@ where .unwrap(); } match n_threads.get() { - 1 => self.taso(circ, log_config, timeout, queue_size), - _ => self.taso_multithreaded(circ, log_config, timeout, n_threads, queue_size), + 1 => self.badger(circ, log_config, timeout, queue_size), + _ => self.badger_multithreaded(circ, log_config, timeout, n_threads, queue_size), } } - #[tracing::instrument(target = "taso::metrics", skip(self, circ, logger))] - fn taso( + #[tracing::instrument(target = "badger::metrics", skip(self, circ, logger))] + fn badger( &self, circ: &Hugr, - mut logger: TasoLogger, + mut logger: BadgerLogger, timeout: Option, queue_size: usize, ) -> Hugr { @@ -196,15 +196,15 @@ where best_circ } - /// Run the TASO optimiser on a circuit, using multiple threads. + /// Run the Badger optimiser on a circuit, using multiple threads. /// - /// This is the multi-threaded version of [`taso`]. See [`TasoOptimiser`] for + /// This is the multi-threaded version of [`badger`]. See [`BadgerOptimiser`] for /// more details. - #[tracing::instrument(target = "taso::metrics", skip(self, circ, logger))] - fn taso_multithreaded( + #[tracing::instrument(target = "badger::metrics", skip(self, circ, logger))] + fn badger_multithreaded( &self, circ: &Hugr, - mut logger: TasoLogger, + mut logger: BadgerLogger, timeout: Option, n_threads: NonZeroUsize, queue_size: usize, @@ -233,7 +233,9 @@ where // Each worker waits for circuits to scan for rewrites using all the // patterns and sends the results back to main. let joins: Vec<_> = (0..n_threads) - .map(|i| TasoWorker::spawn(i, pq.clone(), self.rewriter.clone(), self.strategy.clone())) + .map(|i| { + BadgerWorker::spawn(i, pq.clone(), self.rewriter.clone(), self.strategy.clone()) + }) .collect(); // Deadline for the optimisation timeout @@ -264,7 +266,7 @@ where logger.log_progress(processed_count, Some(queue_length), seen_count); } Err(crossbeam_channel::RecvError) => { - logger.log("The priority channel panicked. Stopping TASO optimisation."); + logger.log("The priority channel panicked. Stopping Badger optimisation."); let _ = pq.close(); break; } @@ -314,11 +316,11 @@ where } /// Split the circuit into chunks and process each in a separate thread. - #[tracing::instrument(target = "taso::metrics", skip(self, circ, logger))] + #[tracing::instrument(target = "badger::metrics", skip(self, circ, logger))] fn split_run( &self, circ: &Hugr, - mut logger: TasoLogger, + mut logger: BadgerLogger, timeout: Option, n_threads: NonZeroUsize, queue_size: usize, @@ -339,14 +341,14 @@ where .enumerate() .map(|(i, chunk)| { let (tx, rx) = crossbeam_channel::unbounded(); - let taso = self.clone(); + let badger = self.clone(); let chunk = mem::take(chunk); let chunk_cx_cost = chunk.circuit_cost(|op| self.strategy.op_cost(op)); logger.log(format!("Chunk {i} has {chunk_cx_cost:?} CX gates",)); let join = thread::Builder::new() .name(format!("chunk-{}", i)) .spawn(move || { - let res = taso.optimise( + let res = badger.optimise( &chunk, timeout, NonZeroUsize::new(1).unwrap(), @@ -381,7 +383,7 @@ where } #[cfg(feature = "portmatching")] -mod taso_default { +mod badger_default { use std::io; use std::path::Path; @@ -395,16 +397,16 @@ mod taso_default { pub type StrategyCost = NonIncreasingGateCountCost usize, fn(&OpType) -> usize>; - /// The default TASO optimiser using ECC sets. - pub type DefaultTasoOptimiser = - TasoOptimiser>; + /// The default Badger optimiser using ECC sets. + pub type DefaultBadgerOptimiser = + BadgerOptimiser>; - impl DefaultTasoOptimiser { + impl DefaultBadgerOptimiser { /// A sane default optimiser using the given ECC sets. pub fn default_with_eccs_json_file(eccs_path: impl AsRef) -> io::Result { let rewriter = ECCRewriter::try_from_eccs_json_file(eccs_path)?; let strategy = NonIncreasingGateCountCost::default_cx(); - Ok(TasoOptimiser::new(rewriter, strategy)) + Ok(BadgerOptimiser::new(rewriter, strategy)) } /// A sane default optimiser using a precompiled binary rewriter. @@ -413,12 +415,12 @@ mod taso_default { ) -> Result { let rewriter = ECCRewriter::load_binary(rewriter_path)?; let strategy = NonIncreasingGateCountCost::default_cx(); - Ok(TasoOptimiser::new(rewriter, strategy)) + Ok(BadgerOptimiser::new(rewriter, strategy)) } } } #[cfg(feature = "portmatching")] -pub use taso_default::DefaultTasoOptimiser; +pub use badger_default::DefaultBadgerOptimiser; use self::hugr_pchannel::Work; @@ -436,7 +438,7 @@ mod tests { use crate::{extension::REGISTRY, Circuit, T2Op}; - use super::{DefaultTasoOptimiser, TasoOptimiser}; + use super::{BadgerOptimiser, DefaultBadgerOptimiser}; #[fixture] fn rz_rz() -> Hugr { @@ -458,13 +460,13 @@ mod tests { } #[fixture] - fn taso_opt() -> DefaultTasoOptimiser { - TasoOptimiser::default_with_eccs_json_file("../test_files/small_eccs.json").unwrap() + fn badger_opt() -> DefaultBadgerOptimiser { + BadgerOptimiser::default_with_eccs_json_file("../test_files/small_eccs.json").unwrap() } #[rstest] - fn rz_rz_cancellation(rz_rz: Hugr, taso_opt: DefaultTasoOptimiser) { - let opt_rz = taso_opt.optimise(&rz_rz, None, 1.try_into().unwrap(), false, 100); + fn rz_rz_cancellation(rz_rz: Hugr, badger_opt: DefaultBadgerOptimiser) { + let opt_rz = badger_opt.optimise(&rz_rz, None, 1.try_into().unwrap(), false, 100); let cmds = opt_rz .commands() .map(|cmd| { diff --git a/tket2/src/optimiser/taso/eq_circ_class.rs b/tket2/src/optimiser/badger/eq_circ_class.rs similarity index 100% rename from tket2/src/optimiser/taso/eq_circ_class.rs rename to tket2/src/optimiser/badger/eq_circ_class.rs diff --git a/tket2/src/optimiser/taso/hugr_pchannel.rs b/tket2/src/optimiser/badger/hugr_pchannel.rs similarity index 99% rename from tket2/src/optimiser/taso/hugr_pchannel.rs rename to tket2/src/optimiser/badger/hugr_pchannel.rs index e6514ef3..e50d8980 100644 --- a/tket2/src/optimiser/taso/hugr_pchannel.rs +++ b/tket2/src/optimiser/badger/hugr_pchannel.rs @@ -233,7 +233,7 @@ where } /// Add circuits to queue. - #[tracing::instrument(target = "taso::metrics", skip(self, circs))] + #[tracing::instrument(target = "badger::metrics", skip(self, circs))] fn enqueue_circs(&mut self, circs: Vec>) { for Work { cost, hash, circ } in circs { if !self.seen_hashes.insert(hash) { diff --git a/tket2/src/optimiser/taso/hugr_pqueue.rs b/tket2/src/optimiser/badger/hugr_pqueue.rs similarity index 100% rename from tket2/src/optimiser/taso/hugr_pqueue.rs rename to tket2/src/optimiser/badger/hugr_pqueue.rs diff --git a/tket2/src/optimiser/taso/log.rs b/tket2/src/optimiser/badger/log.rs similarity index 91% rename from tket2/src/optimiser/taso/log.rs rename to tket2/src/optimiser/badger/log.rs index 9ef85554..3c01fdf6 100644 --- a/tket2/src/optimiser/taso/log.rs +++ b/tket2/src/optimiser/badger/log.rs @@ -1,16 +1,16 @@ -//! Logging utilities for the TASO optimiser. +//! Logging utilities for the Badger optimiser. use std::time::{Duration, Instant}; use std::{fmt::Debug, io}; -/// Logging configuration for the TASO optimiser. -pub struct TasoLogger<'w> { +/// Logging configuration for the Badger optimiser. +pub struct BadgerLogger<'w> { circ_candidates_csv: Option>>, last_circ_processed: usize, last_progress_time: Instant, } -impl<'w> Default for TasoLogger<'w> { +impl<'w> Default for BadgerLogger<'w> { fn default() -> Self { Self { circ_candidates_csv: Default::default(), @@ -22,13 +22,13 @@ impl<'w> Default for TasoLogger<'w> { } /// The logging target for general events. -pub const LOG_TARGET: &str = "taso::log"; +pub const LOG_TARGET: &str = "badger::log"; /// The logging target for progress events. More verbose than the general log. -pub const PROGRESS_TARGET: &str = "taso::progress"; +pub const PROGRESS_TARGET: &str = "badger::progress"; /// The logging target for function spans. -pub const METRICS_TARGET: &str = "taso::metrics"; +pub const METRICS_TARGET: &str = "badger::metrics"; -impl<'w> TasoLogger<'w> { +impl<'w> BadgerLogger<'w> { /// Create a new logging configuration. /// /// Two writer objects must be provided: @@ -119,7 +119,7 @@ impl<'w> TasoLogger<'w> { } /// A helper struct for logging improvements in circuit size seen during the -/// TASO execution. +/// Badger execution. // // TODO: Replace this fixed logging. Report back intermediate results. #[derive(serde::Serialize, Clone, Debug)] diff --git a/tket2/src/optimiser/taso/qtz_circuit.rs b/tket2/src/optimiser/badger/qtz_circuit.rs similarity index 100% rename from tket2/src/optimiser/taso/qtz_circuit.rs rename to tket2/src/optimiser/badger/qtz_circuit.rs diff --git a/tket2/src/optimiser/taso/worker.rs b/tket2/src/optimiser/badger/worker.rs similarity index 86% rename from tket2/src/optimiser/taso/worker.rs rename to tket2/src/optimiser/badger/worker.rs index a9e04d48..7b16bbd0 100644 --- a/tket2/src/optimiser/taso/worker.rs +++ b/tket2/src/optimiser/badger/worker.rs @@ -1,4 +1,4 @@ -//! Distributed workers for the taso optimiser. +//! Distributed workers for the badger optimiser. use std::thread::{self, JoinHandle}; @@ -9,8 +9,8 @@ use crate::rewrite::Rewriter; use super::hugr_pchannel::{PriorityChannelCommunication, Work}; -/// A worker that processes circuits for the TASO optimiser. -pub struct TasoWorker { +/// A worker that processes circuits for the Badger optimiser. +pub struct BadgerWorker { /// The worker ID. #[allow(unused)] id: usize, @@ -22,7 +22,7 @@ pub struct TasoWorker { strategy: S, } -impl TasoWorker +impl BadgerWorker where R: Rewriter + Send + 'static, S: RewriteStrategy + Send + 'static, @@ -36,7 +36,7 @@ where rewriter: R, strategy: S, ) -> JoinHandle<()> { - let name = format!("TasoWorker-{id}"); + let name = format!("BadgerWorker-{id}"); thread::Builder::new() .name(name) .spawn(move || { @@ -55,7 +55,7 @@ where /// /// Processes work until the main thread closes the channel send or receive /// channel. - #[tracing::instrument(target = "taso::metrics", skip(self))] + #[tracing::instrument(target = "badger::metrics", skip(self))] fn run_loop(&mut self) { loop { let Ok(Work { circ, cost, .. }) = self.priority_channel.recv() else { @@ -82,7 +82,7 @@ where }) .collect(); - let send = tracing::trace_span!(target: "taso::metrics", "TasoWorker::send_result") + let send = tracing::trace_span!(target: "badger::metrics", "BadgerWorker::send_result") .in_scope(|| self.priority_channel.send(new_circs)); if send.is_err() { // Terminating diff --git a/tket2/src/rewrite/ecc_rewriter.rs b/tket2/src/rewrite/ecc_rewriter.rs index dede628a..88198ed1 100644 --- a/tket2/src/rewrite/ecc_rewriter.rs +++ b/tket2/src/rewrite/ecc_rewriter.rs @@ -29,7 +29,7 @@ use hugr::Hugr; use crate::{ circuit::{remove_empty_wire, Circuit}, - optimiser::taso::{load_eccs_json_file, EqCircClass}, + optimiser::badger::{load_eccs_json_file, EqCircClass}, portmatching::{CircuitPattern, PatternMatcher}, }; diff --git a/tket2/tests/taso_termination.rs b/tket2/tests/taso_termination.rs index 718de8ae..04d285c4 100644 --- a/tket2/tests/taso_termination.rs +++ b/tket2/tests/taso_termination.rs @@ -4,7 +4,7 @@ use hugr::Hugr; use rstest::{fixture, rstest}; use tket2::{ json::TKETDecode, - optimiser::{DefaultTasoOptimiser, TasoOptimiser}, + optimiser::{BadgerOptimiser, DefaultBadgerOptimiser}, Circuit, }; use tket_json_rs::circuit_json::SerialCircuit; @@ -14,8 +14,8 @@ use tket_json_rs::circuit_json::SerialCircuit; /// This is the complete set of ECCs for 2-qubit circuits with up to /// 4 gates, using the NAM gateset (CX, Rz, H). #[fixture] -fn nam_4_2() -> DefaultTasoOptimiser { - TasoOptimiser::default_with_eccs_json_file("../test_files/Nam_4_2_complete_ECC_set.json") +fn nam_4_2() -> DefaultBadgerOptimiser { + BadgerOptimiser::default_with_eccs_json_file("../test_files/Nam_4_2_complete_ECC_set.json") .unwrap() } @@ -56,7 +56,7 @@ fn simple_circ() -> Hugr { #[rstest] //#[ignore = "Takes 200ms"] -fn taso_termination(simple_circ: Hugr, nam_4_2: DefaultTasoOptimiser) { +fn badger_termination(simple_circ: Hugr, nam_4_2: DefaultBadgerOptimiser) { let opt_circ = nam_4_2.optimise(&simple_circ, None, 1.try_into().unwrap(), false, 10); assert_eq!(opt_circ.commands().count(), 11); }