Submit Commands Directly as Jobs via qsub
TL;DR
When using a supercomputer, you often need to submit jobs via qsub.
Sometimes you just want to run a one-liner, and having to create a script file first before submitting a command is quite tedious. To solve this, I used Python's argparse and subprocess to pseudo-submit commands as jobs directly from the command line.
The concept is simple: the script accepts a command and various parameters as arguments, formats them into a script file, and then submits that file via qsub.
Code
Usage
I recommend adding the directory containing the file to your PATH and creating a symbolic link so you can use it from anywhere. Assuming the file above is named qsubpy.py:
Then you can submit jobs like this:
If you want to specify resources:
If you do not need the generated script file, use --remove and the created shell script will be deleted. If you want to specify a name for the script file, use --name hoge.sh. By default, the file is named with the date plus a random 10-digit integer.
Personally, I have not felt a strong need for it, but you could easily add arguments for log file settings and so on, which would make it even more convenient.
Notes
- Adjust the shebang line to match your environment.
- If the file lacks execute permission, run
chmod u+x qsubpy.