示例#1
0
def main():
    """Parse commandline, wrap script, submit with qsub, delete when done."""
    wrapper = "#!/bin/bash\n%s\n%s\n"
    if len(sys.argv) > 1:
        jobscript = sys.argv[-1]
    else:
        print __doc__
        raise RuntimeError("No jobscript specified")
    wrapscript = jobscript + ".sh"
    
    # read PBS directives
    with open(jobscript) as f:
        directives = "\n".join(li.strip() 
            for li in f if li.strip().startswith("#PBS"))
    
    # fill in the wrapper with any directives and the jobscript
    assert not os.path.exists(wrapscript)
    with open(wrapscript, "w") as f:
        f.write(wrapper % (directives, os.path.realpath(jobscript)))
    
    # make the jobscript executable
    status, output = getstatusoutput("chmod u+x %s" % jobscript)
    assert status == 0, output
    
    # submit the wrapper job
    cmd = "qsub %s %s" % (" ".join(sys.argv[1:-1]), wrapscript)
    status, output = getstatusoutput(cmd)
    msg = "qsub returned %s\nCommand: %s\n\nOutput: %s"
    assert status == 0, msg % (status, cmd, output)
    
    os.remove(wrapscript)
    print output
示例#2
0
 def cythonize(self):
     """
     Return Cython code for this model (further hand-tweaking may be needed).
     
     This just imports and calls 
     :func:`cgp.physmod.cythonize.cythonize_model`.
     """
     modulename_cython = self.package + ".cy"
     modelname = self.hash
     modelfilename = os.path.join(self.packagedir, "cy.pyx")
     try:
         __import__(modulename_cython)
         return sys.modules[modulename_cython]
     except ImportError:
         pyx, setup = cythonize_model(self.py_code, modelname)
         pyx = urlcache("http://bebiservice.umb.no/bottle/cellml2cy", 
             data=urllib.urlencode(dict(cellml=self.cellml)))
         pyxname = modelfilename.replace("%s.py" % modelname, 
             "cython/%s/m.pyx" % modelname)
         dirname, _ = os.path.split(pyxname)
         setupname = os.path.join(dirname, "setup.py")
         # make the cython and model directories "packages"
         cyinitname = os.path.join(dirname, os.pardir, "__init__.py")
         modelinitname = os.path.join(dirname, "__init__.py")
         with write_if_not_exists(cyinitname):
             pass # just create an empty __init__.py file
         with write_if_not_exists(modelinitname):
             pass # just create an empty __init__.py file
         with open(pyxname, "w") as f:
             f.write(pyx)
         with open(setupname, "w") as f:
             f.write(setup)
         cmd = "python setup.py build_ext --inplace"
         status, output = getstatusoutput(cmd, cwd=dirname)
         # Apparently, errors fail to cause status != 0.
         # However, output does include any error messages.
         if "cannot find -lsundials_cvode" in output:
             raise OSError("Cython-compilation of ODE right-hand side "
                 "failed because SUNDIALS was not found.\n"
                 "Status code: %s\nCommand: %s\n"
                 "Output (including errors):\n%s" % (status, cmd, output))
         if status != 0:
             raise RuntimeError("'%s'\nreturned status %s:\n%s" % 
                 (cmd, status, output))
         try:
             __import__(modulename_cython)
             return sys.modules[modulename_cython]
         except StandardError, exc:
             raise ImportError("Exception raised: %s: %s\n\n"
                 "Cython compilation may have failed. "
                 "The compilation command was:\n%s\n\n"
                 "The output of the compilation command was:\n%s"
                 % (exc.__class__.__name__, exc, cmd, output))
示例#3
0
def submit(STAGE_ID, *options):
    """
    Submit the jobscript as an array job, passing any *options to qsub.
    
    This is equivalent to running::
    
        qsub -v STAGE_ID=2 -t 0-2 -W depend=afterok:123 arrayjob.py
    
    >>> submit(2, array_opt(3), "-W depend=afterok:123")        # doctest: +SKIP
    
    submit() returns the job ID assigned by the queue system.
    """
    if any([opt.startswith("-t") for opt in options]):
        wrapper = "qsubwrapmpi"
    else:
        wrapper = "qsubwrap"
    options = " ".join(options)
    cmd = "%s -v STAGE_ID=%s %s %s" % (wrapper, STAGE_ID, options, jobscript)
    status, output = getstatusoutput(cmd)
    result = output
    alog.info("Submitted (status, output, cmd): %s", (status, output, cmd))
    if status != 0:
        raise QsubException(status, output, cmd)
    return result.split(".", 1)[0]