Skip to content

Commit

Permalink
Don't store extra info in the progress history
Browse files Browse the repository at this point in the history
It can be big now that it includes the residual plots
  • Loading branch information
samtygier-stfc committed Jan 3, 2025
1 parent c46a879 commit 13ab985
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
7 changes: 4 additions & 3 deletions mantidimaging/core/utility/progress_reporting/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

from mantidimaging.core.utility.memory_usage import get_memory_usage_linux_str

ProgressHistory = NamedTuple('ProgressHistory', [('time', float), ('step', int), ('msg', str),
('extra_info', dict | None)])
ProgressHistory = NamedTuple('ProgressHistory', [('time', float), ('step', int), ('msg', str)])


class ProgressHandler:
Expand Down Expand Up @@ -59,6 +58,7 @@ def __init__(self, num_steps: int = 1, task_name: str = 'Task') -> None:
# List of tuples defining progress history
# (timestamp, step, message)
self.progress_history: list[ProgressHistory] = []
self.extra_info: dict | None = None

# Lock used to synchronise modifications to the progress state
self.lock = threading.Lock()
Expand Down Expand Up @@ -193,8 +193,9 @@ def update(self,

msg = f"{f'{msg}' if len(msg) > 0 else ''} | {self.current_step}/{self.end_step} | " \
f"Time: {self._format_time(self.execution_time())}, ETA: {self._format_time(eta)}"
step_details = ProgressHistory(time.perf_counter(), self.current_step, msg, extra_info)
step_details = ProgressHistory(time.perf_counter(), self.current_step, msg)
self.progress_history.append(step_details)
self.extra_info = extra_info

# process progress callbacks
for cb in self.progress_handlers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,20 @@ def test_format_time(self):
def test_calculate_mean_time(self):
progress_history = []

progress_history.append(ProgressHistory(100, 0, "", None))
progress_history.append(ProgressHistory(100, 0, ""))
self.assertEqual(Progress.calculate_mean_time(progress_history), 0)

# first step 5 seconds
progress_history.append(ProgressHistory(105, 1, "", None))
progress_history.append(ProgressHistory(105, 1, ""))
self.assertEqual(Progress.calculate_mean_time(progress_history), 5)

# second step 10 seconds
progress_history.append(ProgressHistory(115, 2, "", None))
progress_history.append(ProgressHistory(115, 2, ""))
self.assertEqual(Progress.calculate_mean_time(progress_history), 7.5)

for i in range(1, 50):
# add many 2 second steps
progress_history.append(ProgressHistory(115 + (i * 2), 2 + (i * 2), "", None))
progress_history.append(ProgressHistory(115 + (i * 2), 2 + (i * 2), ""))
self.assertEqual(Progress.calculate_mean_time(progress_history), 2)


Expand Down
3 changes: 1 addition & 2 deletions mantidimaging/gui/dialogs/async_task/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ def update_progress_plot(self, iterations: list, losses: list) -> None:

def progress_update(self) -> None:
msg = self.progress.last_status_message()
progress_info = self.progress.progress_history
extra_info = progress_info[-1].extra_info
extra_info = self.progress.extra_info
self.progress_updated.emit(self.progress.completion(), msg if msg is not None else '')

if extra_info:
Expand Down

0 comments on commit 13ab985

Please sign in to comment.