diff --git a/Cargo.toml b/Cargo.toml index 6bea0559..33f9c941 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,78 +1,22 @@ -[package] -name = "tket2" -version = "0.1.0" -edition = "2021" - -[lib] -bench = false -name = "tket2" -path = "src/lib.rs" - [profile.release] lto = "thin" -[dependencies] -lazy_static = "1.4.0" -cgmath = "0.18.0" -num-rational = "0.4" -num-complex = { version = "0.4", optional = true } -tket-json-rs = { workspace = true } -rayon = "1.5" -thiserror = "1.0.28" -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -downcast-rs = "1.2.0" -priority-queue = "1.3.0" -smol_str = "0.2.0" -typetag = "0.2.8" -itertools = { workspace = true } -petgraph = { version = "0.6.3", default-features = false } -serde_yaml = "0.9.22" -# portmatching = { version = "0.2.0", optional = true, features = ["serde"]} -portmatching = { optional = true, git = "https://github.com/lmondada/portmatching", rev = "738c91c", features = [ - "serde", -] } -derive_more = "0.99.17" -quantinuum-hugr = { workspace = true } -portgraph = { workspace = true, features = ["serde"] } -pyo3 = { workspace = true, optional = true, features = ["multiple-pymethods"] } -strum_macros = "0.25.2" -strum = "0.25.0" -fxhash = "0.2.1" -rmp-serde = { version = "1.1.2", optional = true } -delegate = "0.10.0" -csv = { version = "1.2.2" } -chrono = { version = "0.4.30" } -bytemuck = "1.14.0" -stringreader = "0.1.1" -crossbeam-channel = "0.5.8" -tracing = { workspace = true } - -[features] -pyo3 = [ - "dep:pyo3", - "tket-json-rs/pyo3", - "portgraph/pyo3", - "quantinuum-hugr/pyo3", -] -portmatching = ["dep:portmatching", "dep:rmp-serde"] - -[dev-dependencies] -rstest = "0.18.1" -criterion = { version = "0.5.1", features = ["html_reports"] } -webbrowser = "0.8.10" -urlencoding = "2.1.2" - -[[bench]] -name = "bench_main" -harness = false - [workspace] +resolver = "2" +members = ["tket2", "pyrs", "compile-rewriter", "taso-optimiser"] +default-members = ["tket2"] -members = ["pyrs", "compile-rewriter", "taso-optimiser"] +[workspace.package] +version = "0.1.0" +rust-version = "1.70" +edition = "2021" +homepage = "https://github.com/CQCL/tket2" +license-file = "LICENCE" +# authors [workspace.dependencies] +tket2 = { path = "./tket2" } quantinuum-hugr = { git = "https://github.com/CQCL-DEV/hugr", rev = "0beb165" } portgraph = { version = "0.10" } pyo3 = { version = "0.20" } diff --git a/compile-rewriter/Cargo.toml b/compile-rewriter/Cargo.toml index c7cb8b9e..513b744a 100644 --- a/compile-rewriter/Cargo.toml +++ b/compile-rewriter/Cargo.toml @@ -1,12 +1,15 @@ [package] name = "compile-matcher" -version = "0.1.0" -edition = "2021" +edition = { workspace = true } +version = { workspace = true } +rust-version = { workspace = true } +homepage = { workspace = true } +license-file = { workspace = true } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] clap = { version = "4.4.2", features = ["derive"] } -tket2 = { path = "../", features = ["portmatching"] } +tket2 = { workspace = true, features = ["portmatching"] } quantinuum-hugr = { workspace = true } itertools = { workspace = true } diff --git a/pyrs/Cargo.toml b/pyrs/Cargo.toml index ab53c31f..89c98c06 100644 --- a/pyrs/Cargo.toml +++ b/pyrs/Cargo.toml @@ -9,7 +9,7 @@ name = "pyrs" crate-type = ["cdylib"] [dependencies] -tket2 = { path = "../", features = ["pyo3", "portmatching"] } +tket2 = { workspace = true, features = ["pyo3", "portmatching"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tket-json-rs = { workspace = true, features = ["pyo3"] } diff --git a/taso-optimiser/Cargo.toml b/taso-optimiser/Cargo.toml index 5d82ccb7..a8fcd5af 100644 --- a/taso-optimiser/Cargo.toml +++ b/taso-optimiser/Cargo.toml @@ -1,14 +1,17 @@ [package] name = "taso-optimiser" -version = "0.1.0" -edition = "2021" +edition = { workspace = true } +version = { workspace = true } +rust-version = { workspace = true } +homepage = { workspace = true } +license-file = { workspace = true } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] clap = { version = "4.4.2", features = ["derive"] } serde_json = "1.0" -tket2 = { path = "../", features = ["portmatching"] } +tket2 = { workspace = true, features = ["portmatching"] } quantinuum-hugr = { workspace = true } itertools = { workspace = true } tket-json-rs = { workspace = true } diff --git a/tests/taso_termination.rs b/tests/taso_termination.rs deleted file mode 100644 index 65d393e0..00000000 --- a/tests/taso_termination.rs +++ /dev/null @@ -1,63 +0,0 @@ -#[cfg(feature = "portmatching")] -mod require_portmatching { - use hugr::Hugr; - use rstest::{fixture, rstest}; - use tket2::{ - json::TKETDecode, - optimiser::{DefaultTasoOptimiser, TasoOptimiser}, - Circuit, - }; - use tket_json_rs::circuit_json::SerialCircuit; - - /// A set of equivalence circuit classes (ECC) - /// - /// 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") - .unwrap() - } - - /// The following circuit - /// ┌──────────┐ ┌───────────┐ - ///q_0: ──■──┤ Rz(π/10) ├──■─────────────────────────■────■──┤ Rz(-π/10) ├ - /// │ └──────────┘┌─┴─┐┌───┐┌─────────┐┌───┐┌─┴─┐ │ └───────────┘ - ///q_1: ──┼──────────────┤ X ├┤ H ├┤ Rz(π/5) ├┤ H ├┤ X ├──┼─────────────── - /// ┌─┴─┐ └───┘└───┘└─────────┘└───┘└───┘┌─┴─┐ - ///q_2: ┤ X ├───────────────────────────────────────────┤ X ├───────────── - /// └───┘ └───┘ - #[fixture] - fn simple_circ() -> Hugr { - // The TK1 json of the circuit - let json = r#"{ - "bits": [], - "commands": [ - {"args": [["q", [0]], ["q", [2]]], "op": {"type": "CX"}}, - {"args": [["q", [0]]], "op": {"params": ["0.1"], "type": "Rz"}}, - {"args": [["q", [0]], ["q", [1]]], "op": {"type": "CX"}}, - {"args": [["q", [1]]], "op": {"type": "H"}}, - {"args": [["q", [1]]], "op": {"params": ["0.2"], "type": "Rz"}}, - {"args": [["q", [1]]], "op": {"type": "H"}}, - {"args": [["q", [0]], ["q", [1]]], "op": {"type": "CX"}}, - {"args": [["q", [0]], ["q", [2]]], "op": {"type": "CX"}}, - {"args": [["q", [0]]], "op": {"params": ["-0.1"], "type": "Rz"}}], - "created_qubits": [], - "discarded_qubits": [], - "implicit_permutation": [ - [["q", [0]], ["q", [0]]], [["q", [1]], ["q", [1]]], [["q", [2]], ["q", [2]]] - ], - "phase": "0.0", - "qubits": [["q", [0]], ["q", [1]], ["q", [2]]] - }"#; - let ser: SerialCircuit = serde_json::from_str(json).unwrap(); - ser.decode().unwrap() - } - - #[rstest] - //#[ignore = "Takes 200ms"] - fn taso_termination(simple_circ: Hugr, nam_4_2: DefaultTasoOptimiser) { - let opt_circ = nam_4_2.optimise(&simple_circ, None, 1.try_into().unwrap(), false, 10); - assert_eq!(opt_circ.commands().count(), 11); - } -} diff --git a/tket2/Cargo.toml b/tket2/Cargo.toml new file mode 100644 index 00000000..94328feb --- /dev/null +++ b/tket2/Cargo.toml @@ -0,0 +1,68 @@ +[package] +name = "tket2" +edition = { workspace = true } +version = { workspace = true } +rust-version = { workspace = true } +homepage = { workspace = true } +license-file = { workspace = true } + +[lib] +bench = false +name = "tket2" +path = "src/lib.rs" + +[features] +pyo3 = [ + "dep:pyo3", + "tket-json-rs/pyo3", + "portgraph/pyo3", + "quantinuum-hugr/pyo3", +] +portmatching = ["dep:portmatching", "dep:rmp-serde"] + +[dependencies] +lazy_static = "1.4.0" +cgmath = "0.18.0" +num-rational = "0.4" +num-complex = { version = "0.4", optional = true } +tket-json-rs = { workspace = true } +rayon = "1.5" +thiserror = "1.0.28" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +downcast-rs = "1.2.0" +priority-queue = "1.3.0" +smol_str = "0.2.0" +typetag = "0.2.8" +itertools = { workspace = true } +petgraph = { version = "0.6.3", default-features = false } +serde_yaml = "0.9.22" +# portmatching = { version = "0.2.0", optional = true, features = ["serde"]} +portmatching = { optional = true, git = "https://github.com/lmondada/portmatching", rev = "738c91c", features = [ + "serde", +] } +derive_more = "0.99.17" +quantinuum-hugr = { workspace = true } +portgraph = { workspace = true, features = ["serde"] } +pyo3 = { workspace = true, optional = true, features = ["multiple-pymethods"] } +strum_macros = "0.25.2" +strum = "0.25.0" +fxhash = "0.2.1" +rmp-serde = { version = "1.1.2", optional = true } +delegate = "0.10.0" +csv = { version = "1.2.2" } +chrono = { version = "0.4.30" } +bytemuck = "1.14.0" +stringreader = "0.1.1" +crossbeam-channel = "0.5.8" +tracing = { workspace = true } + +[dev-dependencies] +rstest = "0.18.1" +criterion = { version = "0.5.1", features = ["html_reports"] } +webbrowser = "0.8.10" +urlencoding = "2.1.2" + +[[bench]] +name = "bench_main" +harness = false diff --git a/benches/bench_main.rs b/tket2/benches/bench_main.rs similarity index 100% rename from benches/bench_main.rs rename to tket2/benches/bench_main.rs diff --git a/benches/benchmarks/generators.rs b/tket2/benches/benchmarks/generators.rs similarity index 100% rename from benches/benchmarks/generators.rs rename to tket2/benches/benchmarks/generators.rs diff --git a/benches/benchmarks/hash.rs b/tket2/benches/benchmarks/hash.rs similarity index 100% rename from benches/benchmarks/hash.rs rename to tket2/benches/benchmarks/hash.rs diff --git a/benches/benchmarks/mod.rs b/tket2/benches/benchmarks/mod.rs similarity index 100% rename from benches/benchmarks/mod.rs rename to tket2/benches/benchmarks/mod.rs diff --git a/src/circuit.rs b/tket2/src/circuit.rs similarity index 100% rename from src/circuit.rs rename to tket2/src/circuit.rs diff --git a/src/circuit/command.rs b/tket2/src/circuit/command.rs similarity index 100% rename from src/circuit/command.rs rename to tket2/src/circuit/command.rs diff --git a/src/circuit/cost.rs b/tket2/src/circuit/cost.rs similarity index 100% rename from src/circuit/cost.rs rename to tket2/src/circuit/cost.rs diff --git a/src/circuit/hash.rs b/tket2/src/circuit/hash.rs similarity index 100% rename from src/circuit/hash.rs rename to tket2/src/circuit/hash.rs diff --git a/src/circuit/units.rs b/tket2/src/circuit/units.rs similarity index 100% rename from src/circuit/units.rs rename to tket2/src/circuit/units.rs diff --git a/src/circuit/units/filter.rs b/tket2/src/circuit/units/filter.rs similarity index 100% rename from src/circuit/units/filter.rs rename to tket2/src/circuit/units/filter.rs diff --git a/src/extension.rs b/tket2/src/extension.rs similarity index 100% rename from src/extension.rs rename to tket2/src/extension.rs diff --git a/src/json.rs b/tket2/src/json.rs similarity index 100% rename from src/json.rs rename to tket2/src/json.rs diff --git a/src/json/decoder.rs b/tket2/src/json/decoder.rs similarity index 100% rename from src/json/decoder.rs rename to tket2/src/json/decoder.rs diff --git a/src/json/encoder.rs b/tket2/src/json/encoder.rs similarity index 100% rename from src/json/encoder.rs rename to tket2/src/json/encoder.rs diff --git a/src/json/op.rs b/tket2/src/json/op.rs similarity index 100% rename from src/json/op.rs rename to tket2/src/json/op.rs diff --git a/src/json/tests.rs b/tket2/src/json/tests.rs similarity index 99% rename from src/json/tests.rs rename to tket2/src/json/tests.rs index 195ee444..21a3d982 100644 --- a/src/json/tests.rs +++ b/tket2/src/json/tests.rs @@ -74,7 +74,7 @@ fn json_roundtrip(#[case] circ_s: &str, #[case] num_commands: usize, #[case] num #[rstest] #[cfg_attr(miri, ignore)] // Opening files is not supported in (isolated) miri -#[case::barenco_tof_10("test_files/barenco_tof_10.json")] +#[case::barenco_tof_10("../test_files/barenco_tof_10.json")] fn json_file_roundtrip(#[case] circ: impl AsRef) { let reader = BufReader::new(std::fs::File::open(circ).unwrap()); let ser: circuit_json::SerialCircuit = serde_json::from_reader(reader).unwrap(); diff --git a/src/lib.rs b/tket2/src/lib.rs similarity index 100% rename from src/lib.rs rename to tket2/src/lib.rs diff --git a/src/ops.rs b/tket2/src/ops.rs similarity index 100% rename from src/ops.rs rename to tket2/src/ops.rs diff --git a/src/optimiser.rs b/tket2/src/optimiser.rs similarity index 100% rename from src/optimiser.rs rename to tket2/src/optimiser.rs diff --git a/src/optimiser/taso.rs b/tket2/src/optimiser/taso.rs similarity index 99% rename from src/optimiser/taso.rs rename to tket2/src/optimiser/taso.rs index a54a6471..ff906770 100644 --- a/src/optimiser/taso.rs +++ b/tket2/src/optimiser/taso.rs @@ -459,7 +459,7 @@ mod tests { #[fixture] fn taso_opt() -> DefaultTasoOptimiser { - TasoOptimiser::default_with_eccs_json_file("test_files/small_eccs.json").unwrap() + TasoOptimiser::default_with_eccs_json_file("../test_files/small_eccs.json").unwrap() } #[rstest] diff --git a/src/optimiser/taso/eq_circ_class.rs b/tket2/src/optimiser/taso/eq_circ_class.rs similarity index 100% rename from src/optimiser/taso/eq_circ_class.rs rename to tket2/src/optimiser/taso/eq_circ_class.rs diff --git a/src/optimiser/taso/hugr_pchannel.rs b/tket2/src/optimiser/taso/hugr_pchannel.rs similarity index 100% rename from src/optimiser/taso/hugr_pchannel.rs rename to tket2/src/optimiser/taso/hugr_pchannel.rs diff --git a/src/optimiser/taso/hugr_pqueue.rs b/tket2/src/optimiser/taso/hugr_pqueue.rs similarity index 100% rename from src/optimiser/taso/hugr_pqueue.rs rename to tket2/src/optimiser/taso/hugr_pqueue.rs diff --git a/src/optimiser/taso/log.rs b/tket2/src/optimiser/taso/log.rs similarity index 100% rename from src/optimiser/taso/log.rs rename to tket2/src/optimiser/taso/log.rs diff --git a/src/optimiser/taso/qtz_circuit.rs b/tket2/src/optimiser/taso/qtz_circuit.rs similarity index 96% rename from src/optimiser/taso/qtz_circuit.rs rename to tket2/src/optimiser/taso/qtz_circuit.rs index 11ea2982..ef5cd19b 100644 --- a/src/optimiser/taso/qtz_circuit.rs +++ b/tket2/src/optimiser/taso/qtz_circuit.rs @@ -145,7 +145,7 @@ mod tests { #[cfg_attr(miri, ignore)] // Opening files is not supported in (isolated) miri fn test_read_rep() { let rep_map: HashMap = - load_representative_set("test_files/h_rz_cxrepresentative_set.json"); + load_representative_set("../test_files/h_rz_cxrepresentative_set.json"); for c in rep_map.values().take(1) { println!("{}", c.dot_string()); @@ -156,7 +156,7 @@ mod tests { #[cfg_attr(miri, ignore)] // Opening files is not supported in (isolated) miri fn test_read_complete() { let _ecc: HashMap> = - load_ecc_set("test_files/h_rz_cxcomplete_ECC_set.json").unwrap(); + load_ecc_set("../test_files/h_rz_cxcomplete_ECC_set.json").unwrap(); // ecc.values() // .flatten() diff --git a/src/optimiser/taso/worker.rs b/tket2/src/optimiser/taso/worker.rs similarity index 100% rename from src/optimiser/taso/worker.rs rename to tket2/src/optimiser/taso/worker.rs diff --git a/src/passes.rs b/tket2/src/passes.rs similarity index 100% rename from src/passes.rs rename to tket2/src/passes.rs diff --git a/src/passes/_classical.rs b/tket2/src/passes/_classical.rs similarity index 100% rename from src/passes/_classical.rs rename to tket2/src/passes/_classical.rs diff --git a/src/passes/_squash.rs b/tket2/src/passes/_squash.rs similarity index 100% rename from src/passes/_squash.rs rename to tket2/src/passes/_squash.rs diff --git a/src/passes/chunks.rs b/tket2/src/passes/chunks.rs similarity index 100% rename from src/passes/chunks.rs rename to tket2/src/passes/chunks.rs diff --git a/src/passes/commutation.rs b/tket2/src/passes/commutation.rs similarity index 100% rename from src/passes/commutation.rs rename to tket2/src/passes/commutation.rs diff --git a/src/portmatching.rs b/tket2/src/portmatching.rs similarity index 100% rename from src/portmatching.rs rename to tket2/src/portmatching.rs diff --git a/src/portmatching/matcher.rs b/tket2/src/portmatching/matcher.rs similarity index 100% rename from src/portmatching/matcher.rs rename to tket2/src/portmatching/matcher.rs diff --git a/src/portmatching/pattern.rs b/tket2/src/portmatching/pattern.rs similarity index 100% rename from src/portmatching/pattern.rs rename to tket2/src/portmatching/pattern.rs diff --git a/src/portmatching/pyo3.rs b/tket2/src/portmatching/pyo3.rs similarity index 100% rename from src/portmatching/pyo3.rs rename to tket2/src/portmatching/pyo3.rs diff --git a/src/rewrite.rs b/tket2/src/rewrite.rs similarity index 100% rename from src/rewrite.rs rename to tket2/src/rewrite.rs diff --git a/src/rewrite/ecc_rewriter.rs b/tket2/src/rewrite/ecc_rewriter.rs similarity index 99% rename from src/rewrite/ecc_rewriter.rs rename to tket2/src/rewrite/ecc_rewriter.rs index feabd8f5..dede628a 100644 --- a/src/rewrite/ecc_rewriter.rs +++ b/tket2/src/rewrite/ecc_rewriter.rs @@ -335,7 +335,7 @@ mod tests { fn ecc_rewriter_from_file() { // In this example, all circuits are valid patterns, thus // PatternID == TargetID. - let test_file = "test_files/small_eccs.json"; + let test_file = "../test_files/small_eccs.json"; let rewriter = ECCRewriter::try_from_eccs_json_file(test_file).unwrap(); assert_eq!(rewriter.rewrite_rules.len(), rewriter.matcher.n_patterns()); assert_eq!(rewriter.targets.len(), 5 * 4 + 5 * 3); @@ -370,7 +370,7 @@ mod tests { /// obtain convex patterns #[test] fn ecc_rewriter_empty_params() { - let test_file = "test_files/cx_cx_eccs.json"; + let test_file = "../test_files/cx_cx_eccs.json"; let rewriter = ECCRewriter::try_from_eccs_json_file(test_file).unwrap(); let cx_cx = cx_cx(); diff --git a/src/rewrite/strategy.rs b/tket2/src/rewrite/strategy.rs similarity index 100% rename from src/rewrite/strategy.rs rename to tket2/src/rewrite/strategy.rs diff --git a/src/utils.rs b/tket2/src/utils.rs similarity index 100% rename from src/utils.rs rename to tket2/src/utils.rs diff --git a/tket2/tests/taso_termination.rs b/tket2/tests/taso_termination.rs new file mode 100644 index 00000000..718de8ae --- /dev/null +++ b/tket2/tests/taso_termination.rs @@ -0,0 +1,62 @@ +#![cfg(feature = "portmatching")] + +use hugr::Hugr; +use rstest::{fixture, rstest}; +use tket2::{ + json::TKETDecode, + optimiser::{DefaultTasoOptimiser, TasoOptimiser}, + Circuit, +}; +use tket_json_rs::circuit_json::SerialCircuit; + +/// A set of equivalence circuit classes (ECC) +/// +/// 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") + .unwrap() +} + +/// The following circuit +/// ┌──────────┐ ┌───────────┐ +///q_0: ──■──┤ Rz(π/10) ├──■─────────────────────────■────■──┤ Rz(-π/10) ├ +/// │ └──────────┘┌─┴─┐┌───┐┌─────────┐┌───┐┌─┴─┐ │ └───────────┘ +///q_1: ──┼──────────────┤ X ├┤ H ├┤ Rz(π/5) ├┤ H ├┤ X ├──┼─────────────── +/// ┌─┴─┐ └───┘└───┘└─────────┘└───┘└───┘┌─┴─┐ +///q_2: ┤ X ├───────────────────────────────────────────┤ X ├───────────── +/// └───┘ └───┘ +#[fixture] +fn simple_circ() -> Hugr { + // The TK1 json of the circuit + let json = r#"{ + "bits": [], + "commands": [ + {"args": [["q", [0]], ["q", [2]]], "op": {"type": "CX"}}, + {"args": [["q", [0]]], "op": {"params": ["0.1"], "type": "Rz"}}, + {"args": [["q", [0]], ["q", [1]]], "op": {"type": "CX"}}, + {"args": [["q", [1]]], "op": {"type": "H"}}, + {"args": [["q", [1]]], "op": {"params": ["0.2"], "type": "Rz"}}, + {"args": [["q", [1]]], "op": {"type": "H"}}, + {"args": [["q", [0]], ["q", [1]]], "op": {"type": "CX"}}, + {"args": [["q", [0]], ["q", [2]]], "op": {"type": "CX"}}, + {"args": [["q", [0]]], "op": {"params": ["-0.1"], "type": "Rz"}}], + "created_qubits": [], + "discarded_qubits": [], + "implicit_permutation": [ + [["q", [0]], ["q", [0]]], [["q", [1]], ["q", [1]]], [["q", [2]], ["q", [2]]] + ], + "phase": "0.0", + "qubits": [["q", [0]], ["q", [1]], ["q", [2]]] + }"#; + let ser: SerialCircuit = serde_json::from_str(json).unwrap(); + ser.decode().unwrap() +} + +#[rstest] +//#[ignore = "Takes 200ms"] +fn taso_termination(simple_circ: Hugr, nam_4_2: DefaultTasoOptimiser) { + let opt_circ = nam_4_2.optimise(&simple_circ, None, 1.try_into().unwrap(), false, 10); + assert_eq!(opt_circ.commands().count(), 11); +}