Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Added time values to progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Nov 23, 2022
1 parent e6de73a commit d1599f3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,15 @@ def _run_swiftest_driver(self):

cmd = f"{env['SHELL']} -l {driver_script}"

def _type_scrub(output_data):
int_vars = ["ILOOP","NPL","NTP","NPLM"]
for k,v in output_data.items():
if k in int_vars:
output_data[k] = int(v)
else:
output_data[k] = float(v)
return output_data

try:
with subprocess.Popen(shlex.split(cmd),
stdout=subprocess.PIPE,
Expand All @@ -378,15 +387,21 @@ def _run_swiftest_driver(self):
universal_newlines=True) as p:
process_output = False
noutput = int((self.param['TSTOP'] - self.param['T0']) / self.param['DT'])
iloop = int((self.param['TSTART'] - self.param['T0']) / self.param['DT'])
pbar = tqdm(total=noutput)
for line in p.stdout:
if "SWIFTEST STOP" in line:
process_output = False

if process_output:
kvstream=line.replace('\n','').strip().split(';') # Removes the newline character,
output_data = {kv.split()[0]: kv.split()[1] for kv in kvstream[:-1]}
pbar.update(self.param['ISTEP_OUT'])
output_data = _type_scrub({kv.split()[0]: kv.split()[1] for kv in kvstream[:-1]})
message = f"Time: {output_data['T']} {self.TU_name}/{self.param['TSTOP']} {self.TU_name}"
pbar.set_description_str(message)
interval = output_data['ILOOP'] - iloop
if interval > 0:
pbar.update(interval)
iloop = output_data['ILOOP']

if "SWIFTEST START" in line:
process_output = True
Expand Down

0 comments on commit d1599f3

Please sign in to comment.