diff --git a/Cargo.lock b/Cargo.lock index bcecdd41e7..90d555fdc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1400,8 +1400,8 @@ dependencies = [ [[package]] name = "quantum-sparse-sim" -version = "0.8.2" -source = "git+https://github.com/qir-alliance/qir-runner?rev=e1930df15ef02b3bf273a6f536f46bf6871448c5#e1930df15ef02b3bf273a6f536f46bf6871448c5" +version = "0.8.3" +source = "git+https://github.com/qir-alliance/qir-runner?rev=8cd6fa698521ecf96d459f88254e53dd6e5d6877#8cd6fa698521ecf96d459f88254e53dd6e5d6877" dependencies = [ "ndarray", "num-bigint", diff --git a/Cargo.toml b/Cargo.toml index e14362ef6a..995a6a9fd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,7 @@ wasm-bindgen-futures = "0.4" rand = "0.8" serde_json = "1.0" pyo3 = "0.24" -quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", rev = "e1930df15ef02b3bf273a6f536f46bf6871448c5" } +quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", rev = "8cd6fa698521ecf96d459f88254e53dd6e5d6877" } async-trait = "0.1" tokio = { version = "1.44", features = ["macros", "rt"] } diff --git a/source/compiler/qsc/benches/bench5x5.qs b/source/compiler/qsc/benches/bench5x5.qs new file mode 100644 index 0000000000..bccacccd20 --- /dev/null +++ b/source/compiler/qsc/benches/bench5x5.qs @@ -0,0 +1,59 @@ +/// Copied from https://github.com/microsoft/qsharp-runtime/tree/main/AdvantageBenchmark, +/// updated for the latest Q# syntax. Originally used for testing the performance of the Q# simulator. +operation Main() : Unit { + use qs = Qubit[25]; + ApplyToEach(H, qs); + CZ(qs[2], qs[3]); + CZ(qs[12], qs[13]); + CZ(qs[22], qs[23]); + CZ(qs[5], qs[6]); + CZ(qs[9], qs[10]); + CZ(qs[15], qs[16]); + CZ(qs[19], qs[20]); + ApplyToEach(H, qs); + CZ(qs[0], qs[1]); + CZ(qs[4], qs[5]); + CZ(qs[10], qs[11]); + CZ(qs[14], qs[15]); + CZ(qs[20], qs[21]); + CZ(qs[7], qs[8]); + CZ(qs[17], qs[18]); + ApplyToEach(H, qs); + CZ(qs[15], qs[20]); + CZ(qs[17], qs[22]); + CZ(qs[19], qs[24]); + CZ(qs[6], qs[11]); + CZ(qs[8], qs[13]); + ApplyToEach(H, qs); + CZ(qs[5], qs[10]); + CZ(qs[7], qs[12]); + CZ(qs[9], qs[14]); + CZ(qs[16], qs[21]); + CZ(qs[18], qs[23]); + ApplyToEach(H, qs); + CZ(qs[3], qs[4]); + CZ(qs[13], qs[14]); + CZ(qs[23], qs[24]); + CZ(qs[6], qs[7]); + CZ(qs[16], qs[17]); + ApplyToEach(H, qs); + CZ(qs[1], qs[2]); + CZ(qs[11], qs[12]); + CZ(qs[21], qs[22]); + CZ(qs[8], qs[9]); + CZ(qs[18], qs[19]); + ApplyToEach(H, qs); + CZ(qs[0], qs[5]); + CZ(qs[2], qs[7]); + CZ(qs[4], qs[9]); + CZ(qs[11], qs[16]); + CZ(qs[13], qs[18]); + ApplyToEach(H, qs); + CZ(qs[10], qs[15]); + CZ(qs[12], qs[17]); + CZ(qs[14], qs[19]); + CZ(qs[1], qs[6]); + CZ(qs[3], qs[8]); + ApplyToEach(H, qs); + MResetEachZ(qs); +} diff --git a/source/compiler/qsc/benches/eval.rs b/source/compiler/qsc/benches/eval.rs index 1b28ecf133..a84c132a0f 100644 --- a/source/compiler/qsc/benches/eval.rs +++ b/source/compiler/qsc/benches/eval.rs @@ -14,6 +14,7 @@ const TELEPORT: &str = include_str!("../../../../samples/algorithms/Teleportatio const DEUTSCHJOZSA: &str = include_str!("../../../../samples/algorithms/DeutschJozsa.qs"); const LARGE: &str = include_str!("./large.qs"); const ARRAY_LITERAL: &str = include_str!("./array_literal"); +const BENCH5X5: &str = include_str!("./bench5x5.qs"); pub fn teleport(c: &mut Criterion) { c.bench_function("Teleport evaluation", |b| { @@ -79,6 +80,28 @@ pub fn large_file(c: &mut Criterion) { }); } +pub fn bench5x5(c: &mut Criterion) { + c.bench_function("Bench 5x5 evaluation", |b| { + let sources = SourceMap::new([("bench5x5.qs".into(), BENCH5X5.into())], None); + let (std_id, store) = qsc::compile::package_store_with_stdlib(TargetCapabilityFlags::all()); + let mut evaluator = Interpreter::new( + sources, + PackageType::Exe, + TargetCapabilityFlags::all(), + LanguageFeatures::default(), + store, + &[(std_id, None)], + ) + .expect("code should compile"); + + b.iter(move || { + let mut out = Vec::new(); + let mut rec = GenericReceiver::new(&mut out); + assert!(evaluator.eval_entry(&mut rec).is_ok()); + }); + }); +} + pub fn array_append(c: &mut Criterion) { c.bench_function("Array append evaluation", |b| { let sources = SourceMap::new( @@ -213,6 +236,7 @@ criterion_group!( teleport, deutsch_jozsa, large_file, + bench5x5, array_append, array_update, array_literal,