Skip to content

Commit

Permalink
Improve on the query script
Browse files Browse the repository at this point in the history
  • Loading branch information
linsword13 committed Dec 12, 2024
1 parent a415baa commit dc518c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_slurm_workflow():
ws._re_read()
workspace("setup", "--dry-run", global_args=["-D", ws.root])

# assert the batch_submit is overriden, pointing to the generated script
# assert the batch_submit is overridden, pointing to the generated script
all_exec_file = os.path.join(ws.root, "all_experiments")
with open(all_exec_file) as f:
content = f.read()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

_ensure_job_id_snippet = r"""
job_id=$(< {experiment_run_dir}/.slurm_job)
if [ -z "${job_id:-}"]; then
if [ -z "${job_id:-}" ]; then
echo "No valid job_id found" 1>&2
exit 1
fi
Expand Down Expand Up @@ -133,7 +133,25 @@ def __init__(self, dry_run=False):
)

def generate_query_command(self, job_id):
return f"squeue -j {job_id}"
return rf"""
status=$(squeue -h -o "%t" -j {job_id})
if [ -z "$status" ]; then
status=$(sacct -j {job_id} -o state -X -n)
fi
if [ ! -z "$status" ]; then
# Define a mapping between sacct/squeue status to ramble counterpart
declare -A status_map
status_map["PD"]="SETUP"
status_map["R"]="RUNNING"
status_map["CF"]="SETUP"
status_map["CG"]="COMPLETE"
status_map["COMPLETED"]="COMPLETE"
if [ -v status_map["$status"] ]; then
status=${{status_map["$status"]}}
fi
fi
echo job {job_id} has status: $status
"""

def generate_cancel_command(self, job_id):
return f"scancel {job_id}"
Expand Down

0 comments on commit dc518c6

Please sign in to comment.