Skip to content

Commit

Permalink
Use random signal generator to benchmark phastft
Browse files Browse the repository at this point in the history
  • Loading branch information
smu160 committed Jan 31, 2024
1 parent b3363c1 commit 241b8fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions examples/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use phastft::fft_dif;
use phastft::utils::gen_random_signal;

fn bm_fft(num_qubits: usize) {
for i in 4..num_qubits {
println!("run PhastFT with {i} qubits");
let n = 1 << i;
let mut reals: Vec<f64> = (1..=n).map(f64::from).collect();
let mut imags: Vec<f64> = (1..=n).map(f64::from).collect();

let mut reals = vec![0.0; n];
let mut imags = vec![0.0; n];

gen_random_signal(&mut reals, &mut imags);

let now = std::time::Instant::now();
fft_dif(&mut reals, &mut imags);
Expand Down
4 changes: 2 additions & 2 deletions src/twiddles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ pub(crate) fn generate_twiddles_simd(dist: usize) -> (Vec<f64>, Vec<f64>) {
// This avoids data dependencies of the regular calculation and gets vectorized.
// We do it up front while the values we just calculated are still in the cache
// so we don't have to re-load them from memory later, which would be slow.
apply_symmetry_re(&first_ch_re, second_ch_re);
apply_symmetry_im(&first_ch_im, second_ch_im);
apply_symmetry_re(first_ch_re, second_ch_re);
apply_symmetry_im(first_ch_im, second_ch_im);
},
);

Expand Down
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::f64::consts::PI;
#[allow(dead_code)]
#[track_caller]
pub(crate) fn assert_f64_closeness(actual: f64, expected: f64, epsilon: f64) {
if !((actual - expected).abs() < epsilon) {
if (actual - expected).abs() >= epsilon {
panic!(
"Assertion failed: {} too far from expected value {} (with epsilon {})",
actual, expected, epsilon
Expand All @@ -18,7 +18,7 @@ pub(crate) fn assert_f64_closeness(actual: f64, expected: f64, epsilon: f64) {
#[allow(dead_code)]
#[track_caller]
pub(crate) fn assert_f32_closeness(actual: f32, expected: f32, epsilon: f32) {
if !((actual - expected).abs() < epsilon) {
if (actual - expected).abs() >= epsilon {
panic!(
"Assertion failed: {} too far from expected value {} (with epsilon {})",
actual, expected, epsilon
Expand All @@ -27,7 +27,7 @@ pub(crate) fn assert_f32_closeness(actual: f32, expected: f32, epsilon: f32) {
}

pub fn gen_random_signal(reals: &mut [f64], imags: &mut [f64]) {
assert!(reals.len() == imags.len() && reals.len() > 0);
assert!(reals.len() == imags.len() && !reals.is_empty());
let mut rng = thread_rng();
let between = Uniform::from(0.0..1.0);
let angle_dist = Uniform::from(0.0..2.0 * PI);
Expand Down

0 comments on commit 241b8fb

Please sign in to comment.