Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Compress binary ECCs using zlib #498

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 73 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ typetag = "0.2.8"
urlencoding = "2.1.2"
webbrowser = "1.0.0"
cool_asserts = "2.0.3"
zstd = "0.13.2"
6 changes: 5 additions & 1 deletion badger-optimiser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ publish = false
[dependencies]
clap = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tket2 = { path = "../tket2", features = ["portmatching", "rewrite-tracing"] }
tket2 = { path = "../tket2", features = [
"portmatching",
"rewrite-tracing",
"binary-eccs",
] }
hugr = { workspace = true }
itertools = { workspace = true }
tket-json-rs = { workspace = true }
Expand Down
6 changes: 5 additions & 1 deletion badger-optimiser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
circ.enable_rewrite_tracing();
}

println!("Loading optimiser...");
print!("Loading optimiser...");
let load_ecc_start = std::time::Instant::now();
let Ok(optimiser) = load_optimiser(ecc_path) else {
println!();
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!(" done in {:?}", load_ecc_start.elapsed());

println!(
"Using {n_threads} threads. Queue size is {}.",
opts.queue_size
Expand Down
2 changes: 1 addition & 1 deletion compile-rewriter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ publish = false

[dependencies]
clap = { workspace = true, features = ["derive"] }
tket2 = { path = "../tket2", features = ["portmatching"] }
tket2 = { path = "../tket2", features = ["portmatching", "binary-eccs"] }
hugr = { workspace = true }
itertools = { workspace = true }
5 changes: 4 additions & 1 deletion compile-rewriter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ fn main() {
);
exit(1);
};
println!("Saving to file...");
print!("Saving to file...");
let output_file = if output_path.is_dir() {
output_path.join("matcher.rwr")
} else {
output_path.to_path_buf()
};
let write_time = Instant::now();
let output_file = rewriter.save_binary(output_file).unwrap();
println!(" done in {:?}", write_time.elapsed());

println!("Written rewriter to {:?}", output_file);

// Print the file size of output_file in megabytes
Expand Down
Binary file added test_files/nam_4_2.rwr
Binary file not shown.
Binary file modified test_files/nam_6_3.rwr
Binary file not shown.
Binary file modified test_files/small_eccs.rwr
Binary file not shown.
1 change: 1 addition & 0 deletions tket2-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bench = false
[dependencies]
tket2 = { path = "../tket2", version = "0.1.0-alpha.1", features = [
"portmatching",
"binary-eccs",
] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand Down
Binary file modified tket2-py/tket2/data/nam_6_3.rwr
Binary file not shown.
6 changes: 5 additions & 1 deletion tket2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ portmatching = ["dep:portmatching", "dep:rmp-serde"]
# Stores a trace of the applied rewrites
rewrite-tracing = []

default = []
# Support compressed binary encoded ECC files
binary-eccs = ["dep:zstd"]

default = ["binary-eccs"]

[dependencies]
lazy_static = { workspace = true }
Expand Down Expand Up @@ -62,6 +65,7 @@ chrono = { workspace = true }
bytemuck = { workspace = true }
crossbeam-channel = { workspace = true }
tracing = { workspace = true }
zstd = { workspace = true, optional = true }

[dev-dependencies]
rstest = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions tket2/src/optimiser/badger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ mod badger_default {
}

/// A sane default optimiser using a precompiled binary rewriter.
#[cfg(feature = "binary-eccs")]
pub fn default_with_rewriter_binary(
rewriter_path: impl AsRef<Path>,
) -> Result<Self, RewriterSerialisationError> {
Expand Down
Loading
Loading