-
Notifications
You must be signed in to change notification settings - Fork 9
Fix SLURM submission with additional information #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pysqa/wrapper/slurm.py
(1 hunks)
🔇 Additional comments (1)
pysqa/wrapper/slurm.py (1)
50-56
: Good fix: handle sbatch --parsable outputs with semicolon.Splitting off the semicolon-suffixed part aligns with Slurm’s parsable output format. This resolves failures like "12345;cluster".
return int( | ||
queue_submit_output.splitlines()[-1] | ||
.rstrip() | ||
.lstrip() | ||
.split()[-1] | ||
.split(";")[0] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Make parsing resilient (blank lines, “Submitted…” form, array jobs).
Current logic can break on:
- Trailing blank line (IndexError).
- Array IDs like "12345_1" or "12345_[1-10]" (ValueError on int()).
- It can be simplified using strip()/partition() and made future-proof with a regex for leading digits.
Proposed refactor:
- Use last non-empty line, take last token, strip semicolon-suffix, then extract leading digits.
- Raise a clear error when parsing fails.
Apply this diff within the method:
- return int(
- queue_submit_output.splitlines()[-1]
- .rstrip()
- .lstrip()
- .split()[-1]
- .split(";")[0]
- )
+ lines = [ln.strip() for ln in queue_submit_output.splitlines() if ln.strip()]
+ if not lines:
+ raise ValueError("Empty sbatch output; cannot parse Slurm job ID.")
+ last = lines[-1]
+ token = last.split()[-1] # works for "Submitted batch job 12345" too
+ token = token.partition(";")[0] # remove parsable suffix like ";cluster"
+ m = re.match(r"^(\d+)", token)
+ if not m:
+ raise ValueError(f"Unable to parse Slurm job ID from: {last!r}")
+ return int(m.group(1))
Additionally, add the import at the top of the file:
import re
Tests to cover:
- "12345"
- "12345;cluster"
- "Submitted batch job 12345"
- "12345_1" and "12345_[1-10]"
- Output ending with a blank line
🤖 Prompt for AI Agents
In pysqa/wrapper/slurm.py around lines 50 to 56, the current parsing logic for
extracting job IDs from queue_submit_output is fragile and can fail on blank
lines, array job IDs, or different output formats. Refactor the code to first
find the last non-empty line, then extract the last token, strip any trailing
semicolon, and use a regex to extract only the leading digits from that token.
Add error handling to raise a clear exception if parsing fails. Also, add
"import re" at the top of the file. Write tests covering various output cases
including plain IDs, IDs with semicolons, "Submitted batch job" lines, array job
IDs, and outputs ending with blank lines.
Summary by CodeRabbit