-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Removed joblib from simulate_dipole, and added parallel exe…
…cution test. Signed-off-by: samadpls <[email protected]>
- Loading branch information
Showing
3 changed files
with
36 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
# Mainak Jas <[email protected]> | ||
|
||
from pathlib import Path | ||
import time | ||
import pytest | ||
import numpy as np | ||
import os | ||
|
@@ -290,3 +291,27 @@ def test_load_results(batch_simulate_instance, param_grid, tmp_path): | |
# Validation Tests | ||
with pytest.raises(TypeError, match='results must be'): | ||
batch_simulate_instance._save("invalid_results", start_idx, end_idx) | ||
|
||
|
||
def test_parallel_execution(batch_simulate_instance, param_grid): | ||
"""Test parallel execution of simulations and ensure speedup.""" | ||
|
||
param_combinations = batch_simulate_instance._generate_param_combinations( | ||
param_grid) | ||
|
||
start_time = time.perf_counter() | ||
results_serial = batch_simulate_instance.simulate_batch( | ||
param_combinations, n_jobs=1, backend='loky') | ||
end_time = time.perf_counter() | ||
serial_time = end_time - start_time | ||
|
||
start_time = time.perf_counter() | ||
results_parallel = batch_simulate_instance.simulate_batch( | ||
param_combinations, | ||
n_jobs=4, | ||
backend='loky') | ||
end_time = time.perf_counter() | ||
parallel_time = end_time - start_time | ||
|
||
assert (serial_time > parallel_time | ||
), "Parallel execution is not faster than serial execution!" |