Skip to content

Commit

Permalink
feat: Load pre-compiled ECCs in the badger runner
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Nov 24, 2023
1 parent 3e1a68d commit 00aecb0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions badger-optimiser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod tracing;

use crate::tracing::Tracer;

use std::ffi::OsStr;
use std::fs::File;
use std::io::BufWriter;
use std::num::NonZeroUsize;
Expand All @@ -12,7 +13,7 @@ use std::process::exit;
use clap::Parser;
use tket2::json::{load_tk1_json_file, save_tk1_json_file};
use tket2::optimiser::badger::log::BadgerLogger;
use tket2::optimiser::BadgerOptimiser;
use tket2::optimiser::{BadgerOptimiser, DefaultBadgerOptimiser};

#[cfg(feature = "peak_alloc")]
#[global_allocator]
Expand Down Expand Up @@ -121,12 +122,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let circ = load_tk1_json_file(input_path)?;

println!("Compiling rewriter...");
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
);
println!("Loading optimiser...");
let Ok(optimiser) = load_optimiser(ecc_path) else {
eprintln!("Unable to load ECC file {ecc_path:?}. Is it a JSON file of Quartz-generated ECCs? Or a pre-compiled `.rwr` ECC set?");
exit(1);
};
println!(
Expand Down Expand Up @@ -157,3 +155,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Done.");
Ok(())
}

fn load_optimiser(ecc_path: &Path) -> Result<DefaultBadgerOptimiser, Box<dyn std::error::Error>> {
Ok(match ecc_path.extension().and_then(OsStr::to_str) {
Some("json") => BadgerOptimiser::default_with_eccs_json_file(ecc_path)?,
Some("rwr") => BadgerOptimiser::default_with_rewriter_binary(ecc_path)?,
_ => Err("ECC file must be a `.json` file or a pre-compiled `.rwr` ECC set.".to_string())?,
})
}

0 comments on commit 00aecb0

Please sign in to comment.