Made Simulator object Picklable
This commit is contained in:
parent
b27093e516
commit
8098794804
@ -72,6 +72,12 @@ class Simulator:
|
||||
|
||||
self._BERs = [[]]
|
||||
|
||||
self._create_pbars()
|
||||
|
||||
self._sim_running = False
|
||||
self._sim_done = False
|
||||
|
||||
def _create_pbars(self):
|
||||
self._overall_pbar = tqdm(total=len(self._decoders),
|
||||
desc="Calculating the answer to life, the universe and everything",
|
||||
leave=False,
|
||||
@ -88,8 +94,31 @@ class Simulator:
|
||||
leave=False,
|
||||
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]")
|
||||
|
||||
self._sim_running = False
|
||||
self._sim_done = False
|
||||
def __getstate__(self):
|
||||
"""Custom serialization function called by the 'pickle' module
|
||||
when saving the state of a currently running simulation
|
||||
"""
|
||||
state = self.__dict__.copy()
|
||||
del state['_overall_pbar']
|
||||
del state['_decoder_pbar']
|
||||
del state['_snr_pbar']
|
||||
return state
|
||||
|
||||
def __setstate__(self, state):
|
||||
"""Custom deserialization function called by the 'pickle' module
|
||||
when loading a previously saved simulation
|
||||
"""
|
||||
self.__dict__.update(state)
|
||||
|
||||
self._create_pbars()
|
||||
|
||||
self._overall_pbar.update(self._current_decoder_index)
|
||||
self._decoder_pbar.update(self._current_SNRs_index)
|
||||
self._snr_pbar.update(self._curr_num_frame_errors)
|
||||
|
||||
self._overall_pbar.refresh()
|
||||
self._decoder_pbar.refresh()
|
||||
self._snr_pbar.refresh()
|
||||
|
||||
def _simulate_transmission(self) -> int:
|
||||
"""Simulate the transmission of a single codeword.
|
||||
@ -152,6 +181,10 @@ class Simulator:
|
||||
self._sim_running = False
|
||||
self._sim_done = True
|
||||
|
||||
self._snr_pbar.close()
|
||||
self._decoder_pbar.close()
|
||||
self._overall_pbar.close()
|
||||
|
||||
def start(self) -> None:
|
||||
"""Start the simulation.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user