Skip to content

Instantly share code, notes, and snippets.

Created June 10, 2018 04:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save iwiwi/14483b199f44da34eae7117d1cfd87dd to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import itertools
import sys
import os
import subprocess
import jinja2
def enumerate_combinations(**params):
product_args = []
for key, vals in params.items():
if not isinstance(vals, tuple) and not isinstance(vals, list):
vals = [vals]
product_args.append([(key, val) for val in vals])
for comb in itertools.product(*product_args):
yield dict(comb)
def qsub(template='-', **params):
if template == '-':
template =
template= open(template).read()
template = jinja2.Template(template)
info = {
'cwd': os.getcwd()
os.makedirs('tmp', exist_ok=True)
for comb in enumerate_combinations(**params):
with open('tmp/', 'w') as f:
f.write(template.render(**comb, **info))
subprocess.check_call(['qsub', 'tmp/'])
if __name__ == '__main__':
import fire
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment