Changed GenericMultithreadedSimulator interface to return results in a more usable form
This commit is contained in:
parent
0705fbbcaf
commit
a82a7c0ca8
@ -7,7 +7,9 @@ from functools import partial
|
||||
from multiprocessing import Lock
|
||||
|
||||
from utility import noise
|
||||
from cpp_modules.cpp_decoders import ProximalDecoder
|
||||
|
||||
# TODO: Fix ProximalDecoder_Dynamic
|
||||
# from cpp_modules.cpp_decoders import ProximalDecoder_Dynamic as ProximalDecoder
|
||||
|
||||
|
||||
def count_bit_errors(d: np.array, d_hat: np.array) -> int:
|
||||
@ -259,6 +261,22 @@ class ProximalDecoderSimulator:
|
||||
return pd.DataFrame(data)
|
||||
|
||||
|
||||
class HashableDict:
|
||||
"""Class behaving like an immutable dict. More importantly it is
|
||||
hashable and thus usable as a key type for another dict."""
|
||||
|
||||
def __init__(self, data_dict):
|
||||
assert (isinstance(data_dict, dict))
|
||||
for key, val in data_dict.items():
|
||||
self.__dict__[key] = val
|
||||
|
||||
def __getitem__(self, item):
|
||||
return self.__dict__[item]
|
||||
|
||||
def __str__(self):
|
||||
return str(self.__dict__)
|
||||
|
||||
|
||||
class GenericMultithreadedSimulator:
|
||||
def __init__(self, max_workers=8):
|
||||
self._task_func = None
|
||||
@ -273,9 +291,9 @@ class GenericMultithreadedSimulator:
|
||||
return self._task_params
|
||||
|
||||
@task_params.setter
|
||||
def task_params(self, params):
|
||||
assert isinstance(params, dict)
|
||||
self._task_params = params
|
||||
def task_params(self, sim_params):
|
||||
self._task_params = {HashableDict(iteration_params): iteration_params
|
||||
for iteration_params in sim_params}
|
||||
|
||||
@property
|
||||
def task_func(self):
|
||||
@ -314,7 +332,8 @@ class GenericMultithreadedSimulator:
|
||||
" before it can be stopped"
|
||||
self._executor.shutdown(wait=False, cancel_futures=True)
|
||||
|
||||
def get_current_results(self):
|
||||
@property
|
||||
def current_results(self):
|
||||
return self._results
|
||||
|
||||
def __getstate__(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user