Skip to content

Commit

Permalink
WID-207 Review var name. Small bug fixed in PSELauncher.update_progress
Browse files Browse the repository at this point in the history
  • Loading branch information
liadomide committed Apr 28, 2023
1 parent 36d8539 commit 83b5c9a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
13 changes: 7 additions & 6 deletions tvbwidgets/core/hpc/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)

Expand Down Expand Up @@ -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.")
Expand Down
7 changes: 3 additions & 4 deletions tvbwidgets/core/pse/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 7 additions & 8 deletions tvbwidgets/ui/pse_launcher_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 83b5c9a

Please sign in to comment.