Skip to content

Commit 5305156

Browse files
authored
Update to latest simulator, new benchmark (#2690)
This change updates to the latest sparse simulator, which includes performance improvements. The change also adds a new benchmark taken from the old qsharp-runtime repo to help with evaluating simulator updates on a more complex program. Here are how the execution benchmarks (including the new one) change with the latest simulator: <img width="643" height="452" alt="image" src="https://github.com/user-attachments/assets/18ca8a8e-d7e9-43f3-8c46-e650232bcba9" /> Smaller programs like Teleport receive a minor boost, slightly bigger programs like Deutsch-Jozsa get a bigger boost, and the new benchmark shows a significant improvement. Certain programs like the Large File Parity sample incurr a small penalty, but the trade-offs seem well worthwhile. For very large programs, like the Ising samples on 25 qubits, this has shown significant performance boost, taking only 25% of the time after update.
1 parent 73ca361 commit 5305156

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 2 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ wasm-bindgen-futures = "0.4"
7373
rand = "0.8"
7474
serde_json = "1.0"
7575
pyo3 = "0.24"
76-
quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", rev = "e1930df15ef02b3bf273a6f536f46bf6871448c5" }
76+
quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", rev = "8cd6fa698521ecf96d459f88254e53dd6e5d6877" }
7777
async-trait = "0.1"
7878
tokio = { version = "1.44", features = ["macros", "rt"] }
7979

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/// Copied from https://github.com/microsoft/qsharp-runtime/tree/main/AdvantageBenchmark,
2+
/// updated for the latest Q# syntax. Originally used for testing the performance of the Q# simulator.
3+
operation Main() : Unit {
4+
use qs = Qubit[25];
5+
ApplyToEach(H, qs);
6+
CZ(qs[2], qs[3]);
7+
CZ(qs[12], qs[13]);
8+
CZ(qs[22], qs[23]);
9+
CZ(qs[5], qs[6]);
10+
CZ(qs[9], qs[10]);
11+
CZ(qs[15], qs[16]);
12+
CZ(qs[19], qs[20]);
13+
ApplyToEach(H, qs);
14+
CZ(qs[0], qs[1]);
15+
CZ(qs[4], qs[5]);
16+
CZ(qs[10], qs[11]);
17+
CZ(qs[14], qs[15]);
18+
CZ(qs[20], qs[21]);
19+
CZ(qs[7], qs[8]);
20+
CZ(qs[17], qs[18]);
21+
ApplyToEach(H, qs);
22+
CZ(qs[15], qs[20]);
23+
CZ(qs[17], qs[22]);
24+
CZ(qs[19], qs[24]);
25+
CZ(qs[6], qs[11]);
26+
CZ(qs[8], qs[13]);
27+
ApplyToEach(H, qs);
28+
CZ(qs[5], qs[10]);
29+
CZ(qs[7], qs[12]);
30+
CZ(qs[9], qs[14]);
31+
CZ(qs[16], qs[21]);
32+
CZ(qs[18], qs[23]);
33+
ApplyToEach(H, qs);
34+
CZ(qs[3], qs[4]);
35+
CZ(qs[13], qs[14]);
36+
CZ(qs[23], qs[24]);
37+
CZ(qs[6], qs[7]);
38+
CZ(qs[16], qs[17]);
39+
ApplyToEach(H, qs);
40+
CZ(qs[1], qs[2]);
41+
CZ(qs[11], qs[12]);
42+
CZ(qs[21], qs[22]);
43+
CZ(qs[8], qs[9]);
44+
CZ(qs[18], qs[19]);
45+
ApplyToEach(H, qs);
46+
CZ(qs[0], qs[5]);
47+
CZ(qs[2], qs[7]);
48+
CZ(qs[4], qs[9]);
49+
CZ(qs[11], qs[16]);
50+
CZ(qs[13], qs[18]);
51+
ApplyToEach(H, qs);
52+
CZ(qs[10], qs[15]);
53+
CZ(qs[12], qs[17]);
54+
CZ(qs[14], qs[19]);
55+
CZ(qs[1], qs[6]);
56+
CZ(qs[3], qs[8]);
57+
ApplyToEach(H, qs);
58+
MResetEachZ(qs);
59+
}

source/compiler/qsc/benches/eval.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const TELEPORT: &str = include_str!("../../../../samples/algorithms/Teleportatio
1414
const DEUTSCHJOZSA: &str = include_str!("../../../../samples/algorithms/DeutschJozsa.qs");
1515
const LARGE: &str = include_str!("./large.qs");
1616
const ARRAY_LITERAL: &str = include_str!("./array_literal");
17+
const BENCH5X5: &str = include_str!("./bench5x5.qs");
1718

1819
pub fn teleport(c: &mut Criterion) {
1920
c.bench_function("Teleport evaluation", |b| {
@@ -79,6 +80,28 @@ pub fn large_file(c: &mut Criterion) {
7980
});
8081
}
8182

83+
pub fn bench5x5(c: &mut Criterion) {
84+
c.bench_function("Bench 5x5 evaluation", |b| {
85+
let sources = SourceMap::new([("bench5x5.qs".into(), BENCH5X5.into())], None);
86+
let (std_id, store) = qsc::compile::package_store_with_stdlib(TargetCapabilityFlags::all());
87+
let mut evaluator = Interpreter::new(
88+
sources,
89+
PackageType::Exe,
90+
TargetCapabilityFlags::all(),
91+
LanguageFeatures::default(),
92+
store,
93+
&[(std_id, None)],
94+
)
95+
.expect("code should compile");
96+
97+
b.iter(move || {
98+
let mut out = Vec::new();
99+
let mut rec = GenericReceiver::new(&mut out);
100+
assert!(evaluator.eval_entry(&mut rec).is_ok());
101+
});
102+
});
103+
}
104+
82105
pub fn array_append(c: &mut Criterion) {
83106
c.bench_function("Array append evaluation", |b| {
84107
let sources = SourceMap::new(
@@ -213,6 +236,7 @@ criterion_group!(
213236
teleport,
214237
deutsch_jozsa,
215238
large_file,
239+
bench5x5,
216240
array_append,
217241
array_update,
218242
array_literal,

0 commit comments

Comments
 (0)