Skip to content

Commit

Permalink
Queue table compatible to File table
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Oct 25, 2022
1 parent 7ffb98d commit 3f540cb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 22 deletions.
26 changes: 18 additions & 8 deletions pyiron_base/jobs/job/extension/server/queuestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@
QUEUE_SCRIPT_PREFIX = "pi_"


def queue_table(job_ids=None, project_only=True, full_table=False):
def queue_table(job_ids=None, working_directory_lst=None, project_only=True, full_table=False):
"""
Display the queuing system table as pandas.Dataframe
Args:
job_ids (list): check for a specific list of job IDs - empty list by default
working_directory_lst (list): list of working directories to include - empty list by default
project_only (bool): Query only for jobs within the current project - True by default
full_table (bool): Return all entries from the queuing system without filtering - False by default
Returns:
pandas.DataFrame: Output from the queuing system - optimized for the Sun grid engine
"""
job_ids = [] if job_ids is None else job_ids
if project_only and not job_ids:
working_directory_lst = [] if working_directory_lst is None else working_directory_lst
if project_only and not job_ids and not working_directory_lst:
return []
if state.queue_adapter is not None:
if full_table:
Expand All @@ -56,13 +58,21 @@ def queue_table(job_ids=None, project_only=True, full_table=False):
]
]
else:
job_name_lst = [QUEUE_SCRIPT_PREFIX + str(job_id) for job_id in job_ids]
return df[
[
True if job_name in job_name_lst else False
for job_name in list(df.jobname)
if len(job_ids) > len(working_directory_lst):
job_name_lst = [QUEUE_SCRIPT_PREFIX + str(job_id) for job_id in job_ids]
return df[
[
True if job_name in job_name_lst else False
for job_name in list(df.jobname)
]
]
else:
return df[
[
any([working_dir.startswith(p) for p in working_directory_lst])
for working_dir in list(df.working_directory)
]
]
]
else:
return None

Expand Down
60 changes: 46 additions & 14 deletions pyiron_base/project/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,18 @@ def queue_table(self, project_only=True, recursive=True, full_table=False):
Returns:
pandas.DataFrame: Output from the queuing system - optimized for the Sun grid engine
"""
return queue_table(
job_ids=self.get_job_ids(recursive=recursive),
project_only=project_only,
full_table=full_table,
)
if not isinstance(self.db, FileTable):
return queue_table(
job_ids=self.get_job_ids(recursive=recursive),
project_only=project_only,
full_table=full_table,
)
else:
return queue_table(
project_only=project_only,
full_table=full_table,
working_directory_lst=[self.path]
)

def queue_table_global(self, full_table=False):
"""
Expand All @@ -920,15 +927,40 @@ def queue_table_global(self, full_table=False):
"""
df = queue_table(job_ids=[], project_only=False, full_table=full_table)
if len(df) != 0 and self.db is not None:
return pandas.DataFrame(
[
self.db.get_item_by_id(
int(str(queue_ID).replace("pi_", "").replace(".sh", ""))
)
for queue_ID in df["jobname"]
if str(queue_ID).startswith("pi_")
]
)
if not isinstance(self.db, FileTable):
return pandas.DataFrame(
[
self.db.get_item_by_id(
int(str(queue_ID).replace("pi_", "").replace(".sh", ""))
)
for queue_ID in df["jobname"]
if str(queue_ID).startswith("pi_")
]
)
else:
def get_id_from_job_table(job_table, job_path):
job_dir = "_hdf5".join(job_path.split("_hdf5")[:-1])
job_name = os.path.basename(job_dir)
project = os.path.dirname(job_dir) + "/"
return job_table[
(job_table.job == job_name) &
(job_table.project == project)
].id.values[0]

job_table_df = self.job_table()

return pandas.DataFrame(
[
self.db.get_item_by_id(
int(get_id_from_job_table(
job_table=job_table_df,
job_path=working_directory
))
)
for queue_ID, working_directory in zip(df["jobname"], df["working_directory"])
if str(queue_ID).startswith("pi_")
]
)
else:
return None

Expand Down

0 comments on commit 3f540cb

Please sign in to comment.