Skip to content

Commit 238d086

Browse files
committed
Refactored benchmarks
Signed-off-by: Vlad Gheorghiu <vsoftco@gmail.com>
1 parent f14e508 commit 238d086

15 files changed

Lines changed: 61 additions & 68 deletions

INSTALL.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,23 @@ for details on how to compile and run the benchmarks.
108108
> Projects linking via `find_package(qpp)` must define these flags
109109
> independently if they are needed.
110110
111-
| Optional argument | Value | Description |
112-
| ----------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
113-
| `CMAKE_INSTALL_PREFIX` | `/path/to/install` | Specifies a custom installation directory for **Quantum++** header files -- useful when you lack administrative privileges or want a non-default install location |
114-
| | | |
115-
| `QPP_ENABLE_PYQPP` | `ON/OFF` [`OFF` by default] | Enables pyqpp C++ development, disabled by default |
116-
| `QPP_ENABLE_TESTING` | `ON/OFF` [`OFF` by default] | Enables unit testing with GoogleTest, disabled by default |
117-
| `QPP_MATLAB` | `ON/OFF` [`OFF` by default] | Enables (if available)/disables interoperability with MATLAB, allowing to detect MATLAB installation automatically. If enabled, allows applications to save/load **Quantum++** matrices and vectors to/from MATLAB. |
118-
| `QPP_OPENMP` | `ON/OFF` [`ON` by default] | Enables (if available)/disables OpenMP multi-processing library |
119-
| `QASMTOOLS_QASM2_SPECS` | `ON/OFF` [`OFF` by default] | Enables/disables using the OpenQASM 2.0 standard instead of Qiskit specifications -- see [`DISCREPANCIES.md`](https://github.com/softwareQinc/qpp/blob/main/DISCREPANCIES.md) |
120-
| | | |
121-
| `QPP_SANITIZE` | `ON/OFF` [`OFF` by default] | Enables code sanitizing |
122-
| | | |
123-
| `QPP_BIGINT` | `default`, etc. [`default` by default] | Signed big integer type (`qpp::bigint`) |
124-
| `QPP_FP` | `default`, etc. [`default` by default] | Floating-point type (`qpp::realT`) |
125-
| `QPP_IDX` | `default`, etc. [`default` by default] | Integer index type (`qpp::idx`) |
111+
| Optional argument | Value | Description |
112+
| ------------------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
113+
| `CMAKE_INSTALL_PREFIX` | `/path/to/install` | Specifies a custom installation directory for **Quantum++** header files -- useful when you lack administrative privileges or want a non-default install location |
114+
| | | |
115+
| `QASMTOOLS_QASM2_SPECS` | `ON/OFF` [`OFF` by default] | Enables/disables using the OpenQASM 2.0 standard instead of Qiskit specifications -- see [`DISCREPANCIES.md`](https://github.com/softwareQinc/qpp/blob/main/DISCREPANCIES.md) |
116+
| | | |
117+
| `QPP_ENABLE_PYQPP` | `ON/OFF` [`OFF` by default] | Enables pyqpp C++ development, disabled by default |
118+
| `QPP_ENABLE_TESTING` | `ON/OFF` [`OFF` by default] | Enables unit testing with GoogleTest, disabled by default |
119+
| `QPP_MATLAB` | `ON/OFF` [`OFF` by default] | Enables (if available)/disables interoperability with MATLAB, allowing to detect MATLAB installation automatically. If enabled, allows applications to save/load **Quantum++** matrices and vectors to/from MATLAB. |
120+
| `QPP_OPENMP` | `ON/OFF` [`ON` by default] | Enables (if available)/disables OpenMP multi-processing library |
121+
| `QPP_QUBIT_OPTIMIZATIONS` | `ON/OFF` [`ON` by default] | Enables optimized code paths for qubit-only systems (d = 2) |
122+
| | | |
123+
| `QPP_BIGINT` | `default`, etc. [`default` by default] | Signed big integer type (`qpp::bigint`) |
124+
| `QPP_FP` | `default`, etc. [`default` by default] | Floating-point type (`qpp::realT`) |
125+
| `QPP_IDX` | `default`, etc. [`default` by default] | Integer index type (`qpp::idx`) |
126+
| | | |
127+
| `QPP_SANITIZE` | `ON/OFF` [`OFF` by default] | Enables code sanitizing |
126128

127129
---
128130

benchmarks/src/apply_ctrl_fan_psi_bench.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,14 @@ TEST_CASE("qpp::applyCTRL_fan() state vector benchmark",
5959
}
6060

6161
// Benchmarked portion (executed repeatedly)
62-
BENCHMARK("Apply CTRL-fan to subsystems (psi) nq=" + std::to_string(nq)) {
62+
BENCHMARK("applyCTRL_fan/baseline/psi/nq=" + std::to_string(nq)) {
6363
// CRITICAL: Return the result so the compiler doesn't optimize the
6464
// calculation away.
6565
return qpp::applyCTRL_fan(psi, U, ctrl, target);
6666
};
6767

6868
// Benchmarked portion (executed repeatedly)
69-
BENCHMARK("Apply CTRL-fan to subsystems qubit optimizations (psi) nq=" +
70-
std::to_string(nq)) {
69+
BENCHMARK("applyCTRL_fan/qubit-kernel/psi/nq=" + std::to_string(nq)) {
7170
// CRITICAL: Return the result so the compiler doesn't optimize the
7271
// calculation away.
7372
return qpp::internal::kernels::qubit::apply_ctrl_fan_psi(

benchmarks/src/apply_ctrl_fan_rho_bench.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,14 @@ TEST_CASE("qpp::applyCTRL_fan() density matrix benchmark",
5959
}
6060

6161
// Benchmarked portion (executed repeatedly)
62-
BENCHMARK("Apply CTRL-fan gate to subsystems (rho) nq=" +
63-
std::to_string(nq)) {
62+
BENCHMARK("applyCTRL_fan/baseline/rho/nq=" + std::to_string(nq)) {
6463
// CRITICAL: Return the result so the compiler doesn't optimize the
6564
// calculation away.
6665
return qpp::applyCTRL_fan(rho, U, ctrl, target);
6766
};
6867

6968
// Benchmarked portion (executed repeatedly)
70-
BENCHMARK(
71-
"Apply CTRL-fan gate to subsystems qubit optimizations (rho) nq=" +
72-
std::to_string(nq)) {
69+
BENCHMARK("applyCTRL_fan/qubit-kernel/rho/nq=" + std::to_string(nq)) {
7370
// CRITICAL: Return the result so the compiler doesn't optimize the
7471
// calculation away.
7572
return qpp::internal::kernels::qubit::apply_ctrl_fan_rho(

benchmarks/src/apply_psi_bench.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,56 +53,56 @@ TEST_CASE("qpp::apply() state vector benchmark",
5353
qpp::cmat U4 = qpp::randU(16); // random 4 qubit gate
5454

5555
// Benchmarked portion (executed repeatedly)
56-
BENCHMARK("Apply gate to 1 subsystem (psi) nq=" + std::to_string(nq)) {
56+
BENCHMARK("apply/baseline/psi/nq=" + std::to_string(nq) + "/targets=1") {
5757
// CRITICAL: Return the result so the compiler doesn't optimize the
5858
// calculation away.
5959
return qpp::apply(psi, U1, {nq - 1});
6060
};
6161
// Benchmarked portion (executed repeatedly)
62-
BENCHMARK("Apply gate to 2 subsystems (psi) nq=" + std::to_string(nq)) {
62+
BENCHMARK("apply/baseline/psi/nq=" + std::to_string(nq) + "/targets=2") {
6363
// CRITICAL: Return the result so the compiler doesn't optimize the
6464
// calculation away.
6565
return qpp::apply(psi, U2, {nq - 2, nq - 1});
6666
};
6767
// Benchmarked portion (executed repeatedly)
68-
BENCHMARK("Apply gate to 3 subsystems (psi) nq=" + std::to_string(nq)) {
68+
BENCHMARK("apply/baseline/psi/nq=" + std::to_string(nq) + "/targets=3") {
6969
// CRITICAL: Return the result so the compiler doesn't optimize the
7070
// calculation away.
7171
return qpp::apply(psi, U3, {nq - 3, nq - 2, nq - 1});
7272
};
7373
// Benchmarked portion (executed repeatedly)
74-
BENCHMARK("Apply gate to 4 subsystems (psi) nq=" + std::to_string(nq)) {
74+
BENCHMARK("apply/baseline/psi/nq=" + std::to_string(nq) + "/targets=4") {
7575
// CRITICAL: Return the result so the compiler doesn't optimize the
7676
// calculation away.
7777
return qpp::apply(psi, U4, {nq - 4, nq - 3, nq - 2, nq - 1});
7878
};
7979

8080
// Benchmarked portion (executed repeatedly)
81-
BENCHMARK("Apply gate to 1 subsystem qubit optimizations (psi) nq=" +
82-
std::to_string(nq)) {
81+
BENCHMARK("apply/qubit-kernel/psi/nq=" + std::to_string(nq) +
82+
"/targets=1") {
8383
// CRITICAL: Return the result so the compiler doesn't optimize the
8484
// calculation away.
8585
return qpp::internal::kernels::qubit::apply_psi_1q(psi, U1, nq - 1, nq);
8686
};
8787
// Benchmarked portion (executed repeatedly)
88-
BENCHMARK("Apply gate to 2 subsystems qubit optimizations (psi) nq=" +
89-
std::to_string(nq)) {
88+
BENCHMARK("apply/qubit-kernel/psi/nq=" + std::to_string(nq) +
89+
"/targets=2") {
9090
// CRITICAL: Return the result so the compiler doesn't optimize the
9191
// calculation away.
9292
return qpp::internal::kernels::qubit::apply_psi_2q(psi, U2, nq - 2,
9393
nq - 1, nq);
9494
};
9595
// Benchmarked portion (executed repeatedly)
96-
BENCHMARK("Apply gate to 3 subsystems qubit optimizations (psi) nq=" +
97-
std::to_string(nq)) {
96+
BENCHMARK("apply/qubit-kernel/psi/nq=" + std::to_string(nq) +
97+
"/targets=3") {
9898
// CRITICAL: Return the result so the compiler doesn't optimize the
9999
// calculation away.
100100
return qpp::internal::kernels::qubit::apply_psi_3q(psi, U3, nq - 3,
101101
nq - 2, nq - 1, nq);
102102
};
103103
// Benchmarked portion (executed repeatedly)
104-
BENCHMARK("Apply gate to 4 subsystems qubit optimizations (psi) nq=" +
105-
std::to_string(nq)) {
104+
BENCHMARK("apply/qubit-kernel/psi/nq=" + std::to_string(nq) +
105+
"/targets=4") {
106106
// CRITICAL: Return the result so the compiler doesn't optimize the
107107
// calculation away.
108108
return qpp::internal::kernels::qubit::apply_psi_kq(

benchmarks/src/apply_rho_bench.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,56 +53,56 @@ TEST_CASE("qpp::apply() density matrix benchmark",
5353
qpp::cmat U4 = qpp::randU(16); // random 4 qubit gate
5454

5555
// Benchmarked portion (executed repeatedly)
56-
BENCHMARK("Apply gate to 1 subsystem (psi) nq=" + std::to_string(nq)) {
56+
BENCHMARK("apply/baseline/rho/nq=" + std::to_string(nq) + "/targets=1") {
5757
// CRITICAL: Return the result so the compiler doesn't optimize the
5858
// calculation away.
5959
return qpp::apply(rho, U1, {nq - 1});
6060
};
6161
// Benchmarked portion (executed repeatedly)
62-
BENCHMARK("Apply gate to 2 subsystems (psi) nq=" + std::to_string(nq)) {
62+
BENCHMARK("apply/baseline/rho/nq=" + std::to_string(nq) + "/targets=2") {
6363
// CRITICAL: Return the result so the compiler doesn't optimize the
6464
// calculation away.
6565
return qpp::apply(rho, U2, {nq - 2, nq - 1});
6666
};
6767
// Benchmarked portion (executed repeatedly)
68-
BENCHMARK("Apply gate to 3 subsystems (psi) nq=" + std::to_string(nq)) {
68+
BENCHMARK("apply/baseline/rho/nq=" + std::to_string(nq) + "/targets=3") {
6969
// CRITICAL: Return the result so the compiler doesn't optimize the
7070
// calculation away.
7171
return qpp::apply(rho, U3, {nq - 3, nq - 2, nq - 1});
7272
};
7373
// Benchmarked portion (executed repeatedly)
74-
BENCHMARK("Apply gate to 4 subsystems (psi) nq=" + std::to_string(nq)) {
74+
BENCHMARK("apply/baseline/rho/nq=" + std::to_string(nq) + "/targets=4") {
7575
// CRITICAL: Return the result so the compiler doesn't optimize the
7676
// calculation away.
7777
return qpp::apply(rho, U4, {nq - 4, nq - 3, nq - 2, nq - 1});
7878
};
7979

8080
// Benchmarked portion (executed repeatedly)
81-
BENCHMARK("Apply gate to 1 subsystem qubit optimizations (psi) nq=" +
82-
std::to_string(nq)) {
81+
BENCHMARK("apply/qubit-kernel/rho/nq=" + std::to_string(nq) +
82+
"/targets=1") {
8383
// CRITICAL: Return the result so the compiler doesn't optimize the
8484
// calculation away.
8585
return qpp::internal::kernels::qubit::apply_rho_1q(rho, U1, nq - 1, nq);
8686
};
8787
// Benchmarked portion (executed repeatedly)
88-
BENCHMARK("Apply gate to 2 subsystems qubit optimizations (psi) nq=" +
89-
std::to_string(nq)) {
88+
BENCHMARK("apply/qubit-kernel/rho/nq=" + std::to_string(nq) +
89+
"/targets=2") {
9090
// CRITICAL: Return the result so the compiler doesn't optimize the
9191
// calculation away.
9292
return qpp::internal::kernels::qubit::apply_rho_2q(rho, U2, nq - 2,
9393
nq - 1, nq);
9494
};
9595
// Benchmarked portion (executed repeatedly)
96-
BENCHMARK("Apply gate to 3 subsystems qubit optimizations (psi) nq=" +
97-
std::to_string(nq)) {
96+
BENCHMARK("apply/qubit-kernel/rho/nq=" + std::to_string(nq) +
97+
"/targets=3") {
9898
// CRITICAL: Return the result so the compiler doesn't optimize the
9999
// calculation away.
100100
return qpp::internal::kernels::qubit::apply_rho_3q(rho, U3, nq - 3,
101101
nq - 2, nq - 1, nq);
102102
};
103103
// Benchmarked portion (executed repeatedly)
104-
BENCHMARK("Apply gate to 4 subsystems qubit optimizations (psi) nq=" +
105-
std::to_string(nq)) {
104+
BENCHMARK("apply/qubit-kernel/rho/nq=" + std::to_string(nq) +
105+
"/targets=4") {
106106
// CRITICAL: Return the result so the compiler doesn't optimize the
107107
// calculation away.
108108
return qpp::internal::kernels::qubit::apply_rho_kq(

benchmarks/src/measure_seq_psi_bench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TEST_CASE("qpp::measure_seq() state vector benchmark",
5050
std::iota(subsys.begin(), subsys.end(), 0);
5151

5252
// Benchmarked portion (executed repeatedly)
53-
BENCHMARK("Sequential measurements (psi) nq=" + std::to_string(nq)) {
53+
BENCHMARK("measure_seq/baseline/psi/nq=" + std::to_string(nq)) {
5454
// CRITICAL: Return the result so the compiler doesn't optimize the
5555
// calculation away.
5656
return qpp::measure_seq(psi, subsys);

benchmarks/src/measure_seq_rho_bench.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TEST_CASE("qpp::measure_seq() density matrix benchmark",
5050
std::iota(subsys.begin(), subsys.end(), 0);
5151

5252
// Benchmarked portion (executed repeatedly)
53-
BENCHMARK("Sequential measurements (rho) nq=" + std::to_string(nq)) {
53+
BENCHMARK("measure_seq/baseline/rho/nq=" + std::to_string(nq)) {
5454
// CRITICAL: Return the result so the compiler doesn't optimize the
5555
// calculation away.
5656
return qpp::measure_seq(rho, subsys);

benchmarks/src/ptrace_psi_bench.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,14 @@ TEST_CASE("qpp::ptrace() state vector benchmark",
5353
std::vector<qpp::idx> dims(nq, 2);
5454

5555
// Benchmarked portion (executed repeatedly)
56-
BENCHMARK("Partial trace (psi) nq=" + std::to_string(nq)) {
56+
BENCHMARK("ptrace/baseline/psi/nq=" + std::to_string(nq)) {
5757
// CRITICAL: Return the result so the compiler doesn't optimize the
5858
// calculation away.
5959
return qpp::ptrace(psi, subsys);
6060
};
6161

6262
// Benchmarked portion (executed repeatedly)
63-
BENCHMARK("Partial trace qubit optimizations (psi) nq=" +
64-
std::to_string(nq)) {
63+
BENCHMARK("ptrace/qubit-kernel/psi/nq=" + std::to_string(nq)) {
6564
// CRITICAL: Return the result so the compiler doesn't optimize the
6665
// calculation away.
6766
return qpp::internal::kernels::qubit::ptrace_psi_kq(psi, subsys, nq);

0 commit comments

Comments
 (0)