Skip to content

Commit d9a713c

Browse files
authored
feat!: Compress binary ECCs using zlib (#498)
Breaking change for the compiled `.rwr` ECC sets. The format is now compressed using `zstd`. Comparative figures for the `nam_6_3.rwr` included in the python package: - File size reduced from `69MB` to `4.4MB`. - Load time on my machine reduced from `~560ms` to `~420ms`. - (offline) ECC compilation time increased from `2.4s` to `3s`. This is using the highest compression rate. Faster encodings produce files of around `5MB`. Closes #488 BREAKING CHANGE: `.rwr` ECC files generated with older versions are no longer supported. Please recompile them, or compress the file with `zstd`.
1 parent 8c7c338 commit d9a713c

File tree

14 files changed

+135
-41
lines changed

14 files changed

+135
-41
lines changed

Cargo.lock

Lines changed: 73 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ typetag = "0.2.8"
6767
urlencoding = "2.1.2"
6868
webbrowser = "1.0.0"
6969
cool_asserts = "2.0.3"
70+
zstd = "0.13.2"

badger-optimiser/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ publish = false
1212
[dependencies]
1313
clap = { workspace = true, features = ["derive"] }
1414
serde_json = { workspace = true }
15-
tket2 = { path = "../tket2", features = ["portmatching", "rewrite-tracing"] }
15+
tket2 = { path = "../tket2", features = [
16+
"portmatching",
17+
"rewrite-tracing",
18+
"binary-eccs",
19+
] }
1620
hugr = { workspace = true }
1721
itertools = { workspace = true }
1822
tket-json-rs = { workspace = true }

badger-optimiser/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
140140
circ.enable_rewrite_tracing();
141141
}
142142

143-
println!("Loading optimiser...");
143+
print!("Loading optimiser...");
144+
let load_ecc_start = std::time::Instant::now();
144145
let Ok(optimiser) = load_optimiser(ecc_path) else {
146+
println!();
145147
eprintln!("Unable to load ECC file {ecc_path:?}. Is it a JSON file of Quartz-generated ECCs? Or a pre-compiled `.rwr` ECC set?");
146148
exit(1);
147149
};
150+
println!(" done in {:?}", load_ecc_start.elapsed());
151+
148152
println!(
149153
"Using {n_threads} threads. Queue size is {}.",
150154
opts.queue_size

compile-rewriter/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ publish = false
99

1010
[dependencies]
1111
clap = { workspace = true, features = ["derive"] }
12-
tket2 = { path = "../tket2", features = ["portmatching"] }
12+
tket2 = { path = "../tket2", features = ["portmatching", "binary-eccs"] }
1313
hugr = { workspace = true }
1414
itertools = { workspace = true }

compile-rewriter/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,16 @@ fn main() {
5252
);
5353
exit(1);
5454
};
55-
println!("Saving to file...");
55+
print!("Saving to file...");
5656
let output_file = if output_path.is_dir() {
5757
output_path.join("matcher.rwr")
5858
} else {
5959
output_path.to_path_buf()
6060
};
61+
let write_time = Instant::now();
6162
let output_file = rewriter.save_binary(output_file).unwrap();
63+
println!(" done in {:?}", write_time.elapsed());
64+
6265
println!("Written rewriter to {:?}", output_file);
6366

6467
// Print the file size of output_file in megabytes

test_files/nam_4_2.rwr

41.3 KB
Binary file not shown.

test_files/nam_6_3.rwr

-64.5 MB
Binary file not shown.

test_files/small_eccs.rwr

-50.5 KB
Binary file not shown.

tket2-py/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ bench = false
2121
[dependencies]
2222
tket2 = { path = "../tket2", version = "0.1.0-alpha.1", features = [
2323
"portmatching",
24+
"binary-eccs",
2425
] }
2526
serde = { workspace = true, features = ["derive"] }
2627
serde_json = { workspace = true }

0 commit comments

Comments
 (0)