Repository navigation
Add micro-benchmarks for MPS ApplyGate methods - #1118
KrishGopi1 wants to merge 3 commits into
Conversation
Adds Google Benchmark micro-benchmarks for MPSSimulator::ApplyGate1 and ApplyGate2 at the left edge, middle, and right edge of the MPS, across several bond dimensions, along with `make benchmarks` and `make run-benchmarks` targets. Part of quantumlib#373.
There was a problem hiding this comment.
Code Review
This pull request introduces a micro-benchmark suite for MPSSimulator::ApplyGate* under a new benchmarks/ directory, along with the necessary Makefiles to build and run them. The review feedback highlights a critical issue in BM_ApplyGate2 where the state is modified in-place inside the benchmark loop, leading to exponential norm decay and numerical underflow. To resolve this and ensure accurate benchmark results, the reviewer suggests copying a pristine state template using std::memcpy at each iteration and adding the header.
| #include <cstdint> | ||
| #include <random> | ||
| #include <vector> |
There was a problem hiding this comment.
Add <cstring> to the includes to support std::memcpy for resetting the state in BM_ApplyGate2.
| #include <cstdint> | |
| #include <random> | |
| #include <vector> | |
| #include <cstdint> | |
| #include <cstring> | |
| #include <random> | |
| #include <vector> |
References
- Google C++ Style Guide requires standard library headers to be sorted alphabetically. (link)
|
Thanks for the review. I checked the concern about repeated in-place application in
The comment added in 73fe522 records that the in-place loop matches the reset-each-iteration timings for the gate and sizes used. |
Part of #373.
Summary
Adds Google Benchmark micro-benchmarks for the MPS simulator's gate
application methods.
The benchmarks cover:
The MPS states are initialized with random values to provide a
non-trivial workload.
Running
Requires Google Benchmark (e.g.
apt install libbenchmark-dev). Eigen isfetched by the existing
eigentarget.Results
Baseline from the default
make benchmarksbuild (-O3, no-marchflags), median of 5 runs on a 16-core x86 CPU at ~3.8 GHz. Absolute times
vary by machine and by roughly ±10% between runs.
Profiling
Timing the SVD in isolation, on a product of two random blocks of the
shape ApplyGate2 decomposes, under the same flags as the benchmark:
Eigen's BDCSVD takes roughly 80% (D=4), 83% (D=16), and 93% (D=64) of a
middle-position ApplyGate2 call. The block matrix multiplication takes
about 5-6% at each size.
Changing the BDCSVD switch size did not help, and JacobiSVD was about
9x (D=16) to 12x (D=64) slower.
Substantial further speedups of ApplyGate2 would likely require
investigating the SVD implementation itself.
No MPS simulator implementation code is changed by this PR.
🤖 Generated with Claude Code