Skip to content

Commit

Permalink
[feature/SPO_apply] Adding a note about the test timings in the C++ t…
Browse files Browse the repository at this point in the history
…ests of SummedPauliOps
  • Loading branch information
jamesETsmith committed Oct 31, 2024
1 parent 1e30e84 commit 9322d78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 11 additions & 1 deletion fast_pauli/cpp/examples/03_summed_pauli_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main()
// User settings
//
size_t const n_operators = 1000;
size_t const n_qubits = 12;
size_t const n_qubits = 10;
size_t const weight = 2;
size_t const n_states = 1000;
using fp_type = double;
Expand Down Expand Up @@ -63,7 +63,17 @@ int main()
//
// Apply the states
//
auto start_seq = std::chrono::high_resolution_clock::now();
summed_op.apply_weighted(std::execution::seq, new_states, states, weights);
auto end_seq = std::chrono::high_resolution_clock::now();
fmt::println("Time taken for sequential execution: {} seconds",
std::chrono::duration_cast<std::chrono::seconds>(end_seq - start_seq).count());

auto start_par = std::chrono::high_resolution_clock::now();
summed_op.apply_weighted(std::execution::par, new_states, states, weights);
auto end_par = std::chrono::high_resolution_clock::now();
fmt::println("Time taken for parallel execution: {} seconds",
std::chrono::duration_cast<std::chrono::seconds>(end_par - start_par).count());

return 0;
}
4 changes: 3 additions & 1 deletion fast_pauli/cpp/tests/test_summed_pauli_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ TEST_CASE("apply weighted many operators many PauliString")
std::vector<std::complex<double>> coeff_raw;
std::mdspan coeff = fast_pauli::rand<std::complex<double>, 2>(coeff_raw, {pauli_strings.size(), 1000});

// These timers report nearly equal times for serial vs parallel which is NOT the case when we benchmark this
// elsewhere. It's not clear what's going on here. See examples/03_summed_pauli_op.cpp for benchmarks.
auto start_seq = std::chrono::high_resolution_clock::now();
__check_apply_weighted(std::execution::seq, pauli_strings, coeff, 100);
auto end_seq = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -391,7 +393,7 @@ TEST_CASE("expectation values multiple operators and states")
{
size_t const n_operators = 1000;
size_t const n_qubits = 8;
size_t const n_states = 100;
size_t const n_states = 1000;

auto start = std::chrono::high_resolution_clock::now();
__check_exp_vals(std::execution::seq, n_operators, n_qubits, n_states);
Expand Down

0 comments on commit 9322d78

Please sign in to comment.