Skip to content

Commit

Permalink
Support multi-threading
Browse files Browse the repository at this point in the history
  • Loading branch information
lmondada committed Sep 14, 2023
1 parent c8fb9de commit 18d3c43
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/rewrite/ecc_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct TargetID(usize);
/// Valid rewrites turn a non-representative circuit into its representative,
/// or a representative circuit into any of the equivalent non-representative
/// circuits.
#[derive(Debug, Clone)]
pub struct ECCRewriter {
/// Matcher for finding patterns.
matcher: PatternMatcher,
Expand Down
1 change: 1 addition & 0 deletions src/rewrite/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl RewriteStrategy for GreedyRewriteStrategy {
/// strictly reduces the gate count. The default is gamma = 1.0001, as set
/// in the Quartz paper. This essentially allows rewrites that improve or leave
/// the number of nodes unchanged.
#[derive(Debug, Clone)]
pub struct ExhaustiveRewriteStrategy {
/// The gamma parameter.
pub gamma: f64,
Expand Down
26 changes: 24 additions & 2 deletions taso-optimiser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hugr::Hugr;
use tket2::{
circuit::Circuit,
json::{load_tk1_json_file, TKETDecode},
passes::taso::taso,
passes::taso::{taso, taso_mpsc},
rewrite::{strategy::ExhaustiveRewriteStrategy, ECCRewriter},
};
use tket_json_rs::circuit_json::SerialCircuit;
Expand Down Expand Up @@ -42,6 +42,15 @@ struct CmdLineArgs {
help = "Sets the ECC file to use. It is a JSON file of Quartz-generated ECCs."
)]
eccs: String,
/// Number of threads (default=1)
#[arg(
short,
long,
default_value = 1,
value_name = "N_THREADS",
help = "The number of threads to use."
)]
n_threads: usize,
}

fn save_tk1_json_file(path: impl AsRef<Path>, circ: &Hugr) -> Result<(), std::io::Error> {
Expand All @@ -66,7 +75,20 @@ fn main() {
let strategy = ExhaustiveRewriteStrategy::default();

println!("Optimising...");
let opt_circ = taso(circ, rewriter, strategy, |c| c.num_gates(), Some(100));
let opt_circ = if opts.n_threads == 1 {
println!("Using single-threaded TASO");
taso(circ, rewriter, strategy, |c| c.num_gates(), Some(100))
} else {
println!("Using multi-threaded TASO with {} threads", opts.n_threads);
taso_mpsc(
circ,
rewriter,
strategy,
|c| c.num_gates(),
Some(100),
opts.n_threads,
)
};

println!("Saving result");
save_tk1_json_file(output_path, &opt_circ).unwrap();
Expand Down

0 comments on commit 18d3c43

Please sign in to comment.