From 83b5c9aba3945c60a4284812bdb79b343478c9b3 Mon Sep 17 00:00:00 2001 From: liadomide Date: Fri, 28 Apr 2023 22:19:30 +0300 Subject: [PATCH] WID-207 Review var name. Small bug fixed in PSELauncher.update_progress --- package.json | 2 +- tvbwidgets/core/hpc/launcher.py | 13 +++++++------ tvbwidgets/core/pse/parameters.py | 7 +++---- tvbwidgets/ui/pse_launcher_widget.py | 15 +++++++-------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index d77a3463..f35385eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tvb-widgets", - "version": "1.4.0a1", + "version": "1.4.0", "description": "GUI widgets for EBRAINS showcases", "homepage": "https://github.com/the-virtual-brain/tvb-widgets", "license": "GPL-3.0-or-later", diff --git a/tvbwidgets/core/hpc/launcher.py b/tvbwidgets/core/hpc/launcher.py index bb3184ac..d4b67a32 100644 --- a/tvbwidgets/core/hpc/launcher.py +++ b/tvbwidgets/core/hpc/launcher.py @@ -4,9 +4,10 @@ # # (c) 2022-2023, TVB Widgets Team # -import time +import time import pyunicore.client +from typing import Callable from datetime import datetime from urllib.error import HTTPError from pyunicore.helpers.jobs import Status, Description @@ -15,7 +16,7 @@ from tvbwidgets.core.auth import get_current_token from tvbwidgets.core.hpc.config import HPCConfig from tvbwidgets.core.logger.builder import get_logger -from tvbwidgets.core.pse.parameters import PROGRESS_BAR_STATUS_FILE +from tvbwidgets.core.pse.parameters import PROGRESS_STATUS LOGGER = get_logger(__name__) @@ -213,13 +214,13 @@ def monitor_job(self, job): start_time = int(time.time()) # we replaced job.poll to our custom while, to update the progress bar as well while job.status.ordinal() < pyunicore.client.JobStatus.SUCCESSFUL.ordinal(): - state = int(self.read_file_from_hpc(job, PROGRESS_BAR_STATUS_FILE)) - self.update_progress(state + 1) + completed_count = int(self.read_file_from_hpc(job, PROGRESS_STATUS)) + self.update_progress(completed_count) time.sleep(2) if self.config.timeout > 0 and int(time.time()) > start_time + self.config.timeout: - # signalize an error + # signalize a problem in the front-end self.update_progress(error_msg="Connection Timeout") - raise TimeoutError(f"Timeout waiting for job to become {state.value}") + raise TimeoutError(f"Timeout waiting for job to complete. Already completed {completed_count}") if job.properties['status'] == Status.FAILED: LOGGER.error("Job finished with errors.") diff --git a/tvbwidgets/core/pse/parameters.py b/tvbwidgets/core/pse/parameters.py index 3c7d9e96..1a25d0b2 100644 --- a/tvbwidgets/core/pse/parameters.py +++ b/tvbwidgets/core/pse/parameters.py @@ -34,7 +34,7 @@ # Here put explicit module name string, for __name__ == __main__ LOGGER = get_logger("tvbwidgets.core.pse.parameters") -PROGRESS_BAR_STATUS_FILE = "progress_bar_status.txt" +PROGRESS_STATUS = "progress_status.txt" try: from dask.distributed import Client @@ -252,7 +252,7 @@ def monitor_execution(self): self.update_progress() else: with self.progress_file_lock: - with open(PROGRESS_BAR_STATUS_FILE, "r+") as f: + with open(PROGRESS_STATUS, "r+") as f: # set the cursor to the beginning of the file f.seek(0) status = int(f.read()) @@ -262,7 +262,6 @@ def monitor_execution(self): except Exception as e: LOGGER.error("Could not update the progress bar status", exc_info=e) - def __call__(self, n_jobs=-1): LOGGER.info("Simulation starts") self._init_checkpoint() @@ -407,7 +406,7 @@ def launch_local_param(simulator, param1, param2, x_values, y_values, metrics, f # TODO WID-208 deserialize this instance after being passed from the remote launcher sim = Simulator(connectivity=Connectivity.from_file()).configure() - with open(PROGRESS_BAR_STATUS_FILE, "w+") as f: + with open(PROGRESS_STATUS, "w+") as f: f.write("0") launch_local_param(sim, param1, param2, param1_values, param2_values, metrics, file_name, diff --git a/tvbwidgets/ui/pse_launcher_widget.py b/tvbwidgets/ui/pse_launcher_widget.py index 84d8a016..cd6a43aa 100644 --- a/tvbwidgets/ui/pse_launcher_widget.py +++ b/tvbwidgets/ui/pse_launcher_widget.py @@ -88,8 +88,8 @@ def _prepare_launch(self, where="Local"): y_values = self.compute_params_values(self.param_2.value) file_name = self.verify_file_name() self.progress.min = 0 - self.progress.max = len(x_values) * len(y_values) + 1 - self.update_progress(1) + self.progress.max = len(x_values) * len(y_values) + 1 # no of simulations + 1 for preparation step + self.update_progress(0) return file_name, x_values, y_values def handle_launch_buttons(self): @@ -142,16 +142,15 @@ def verify_file_name(self): else: return file_name - def update_progress(self, value=None, error_msg=None): - if error_msg is None: + def update_progress(self, jobs_completed=None, error_msg=None): + if error_msg is not None: self._update_info_message(error_msg, is_error=True) with self.progress_lock: - if value is None: + if jobs_completed is None: self.progress.value += 1 - elif value >= 0: - self.progress.value = value - + elif jobs_completed >= 0: + self.progress.value = jobs_completed + 1 def create_metrics(self): self.metrics_sm = widgets.SelectMultiple(