Added progress bars; NOT WORKING - Serialization of progress bars not possible

This commit is contained in:
Andreas Tsouchlos 2022-11-15 17:45:25 +01:00
parent e9cd215457
commit b27093e516

View File

@ -35,6 +35,7 @@ class Simulator:
However, storing the state of the simulation as member variables allows for pausing and resuming the simulation
at a later state.
"""
def __init__(self, n: int, k: int,
decoders: typing.Sequence[typing.Any],
SNRs: typing.Sequence[float],
@ -69,9 +70,26 @@ class Simulator:
# Results & Miscellaneous
self._BERs = [[]]
self._overall_pbar = tqdm(total=len(self._decoders),
desc="Calculating the answer to life, the universe and everything",
leave=False,
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt}")
decoder = self._decoders[self._current_decoder_index]
self._decoder_pbar = tqdm(total=len(self._SNRs),
desc=f"Calculating BERs for {decoder.__class__.__name__}",
leave=False,
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt}")
self._snr_pbar = tqdm(total=self._target_frame_errors,
desc=f"Simulating for SNR = {self._SNRs[0]} dB",
leave=False,
bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]")
self._sim_running = False
self._sim_done = False
self._BERs = [[]]
def _simulate_transmission(self) -> int:
"""Simulate the transmission of a single codeword.
@ -97,6 +115,8 @@ class Simulator:
self._curr_num_frame_errors += 1
self._curr_num_bit_errors += bit_errors
self._snr_pbar.update(1)
def _advance_state(self) -> None:
"""Advance the state of the simulator.
@ -105,20 +125,29 @@ class Simulator:
"""
if self._curr_num_frame_errors >= self._target_frame_errors:
# TODO: Properly handle the multiple decoders
self._BERs[self._current_decoder_index]\
self._BERs[self._current_decoder_index] \
.append(self._curr_num_bit_errors / (self._curr_num_iterations * self._n))
self._curr_num_frame_errors = 0
self._curr_num_bit_errors = 0
self._curr_num_iterations = 0
if self._current_SNRs_index < len(self._SNRs)-1:
if self._current_SNRs_index < len(self._SNRs) - 1:
self._current_SNRs_index += 1
self._snr_pbar.reset()
self._snr_pbar.set_description(f"Simulating for SNR = {self._SNRs[self._current_SNRs_index]} dB")
self._decoder_pbar.update(1)
else:
if self._current_decoder_index < len(self._decoders)-1:
if self._current_decoder_index < len(self._decoders) - 1:
self._current_decoder_index += 1
self._current_SNRs_index = 0
self._BERs.append([])
self._decoder_pbar.reset()
decoder = self._decoders[self._current_decoder_index]
self._decoder_pbar.set_description(f"Calculating BERs for {decoder.__class__.__name__}")
self._overall_pbar.update(1)
else:
self._sim_running = False
self._sim_done = True
@ -173,6 +202,7 @@ class SimulationManager:
All actual work is outsourced to a provided simulator class.
"""
def __init__(self, save_dir: str, results_dir: str):
"""Construct a SimulationManager object.