-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pickle support to allow for parallelization and add parallelizati…
…on tests Fixed pickle support by removing all ctypes pointers from the state in CadetDLLRunner.__getstate__ and recreating the dll interface in CadetDLLRunner.__setstate__ . Fixed "no attribute __frozen" error by casting Cadet state into addict.Dict on Cadet.__setstate__ .
- Loading branch information
1 parent
b99ef3c
commit 9cd4160
Showing
4 changed files
with
70 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from cadet import Cadet | ||
from joblib import Parallel, delayed | ||
from .test_dll import setup_model | ||
|
||
n_jobs = 2 | ||
|
||
|
||
def run_simulation(model): | ||
model.save() | ||
data = model.run_load() | ||
return data | ||
|
||
|
||
def test_parallelization_io(): | ||
model1 = Cadet() | ||
model1.root.input = {'model': 1} | ||
model1.filename = "sim_1.h5" | ||
model2 = Cadet() | ||
model2.root.input = {'model': 2} | ||
model2.filename = "sim_2.h5" | ||
|
||
models = [model1, model2] | ||
|
||
results_sequential = [run_simulation(model) for model in models] | ||
|
||
results_parallel = Parallel(n_jobs=n_jobs, verbose=0)( | ||
delayed(run_simulation)(model, ) for model in models | ||
) | ||
assert results_sequential == results_parallel | ||
|
||
|
||
def test_parallelization_simulation(): | ||
models = [setup_model(Cadet.autodetect_cadet(), file_name=f"LWE_{i}.h5") for i in range(2)] | ||
|
||
results_sequential = [run_simulation(model) for model in models] | ||
|
||
results_parallel = Parallel(n_jobs=n_jobs, verbose=0)( | ||
delayed(run_simulation)(model, ) for model in models | ||
) | ||
assert results_sequential == results_parallel |