<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run_dependency_graph(jobgraph, logger=None, jgprefix="ANIm_SGE_JG", sgegroupsize=10000, sgeargs=None):
 """Creates and runs GridEngine scripts for jobs based on the passed jobgraph. - jobgraph - list of jobs, which may have dependencies. - verbose - flag for multiprocessing verbosity - logger - a logger module logger (optional) - jgprefix - a prefix for the submitted jobs, in the scheduler - sgegroupsize - the maximum size for an array job submission - sgeargs - additional arguments to qsub The strategy here is to loop over each job in the list of jobs (jobgraph), and create/populate a series of Sets of commands, to be run in reverse order with multiprocessing_run as asynchronous pools. The strategy here is to loop over each job in the dependency graph, and add the job to a new list of jobs, swapping out the Job dependency for the name of the Job on which it depends. """

    joblist = build_joblist(jobgraph)

    # Try to be informative by telling the user what jobs will run
    dep_count = 0  # how many dependencies are there
    if logger:
        logger.info("Jobs to run with scheduler")
        for job in joblist:
            logger.info("{0}: {1}".format(job.name, job.command))
            if len(job.dependencies):
                dep_count += len(job.dependencies)
                for dep in job.dependencies:
                    logger.info("\t[^ depends on: %s]" % dep.name)
    logger.info("There are %d job dependencies" % dep_count)

    # If there are no job dependencies, we can use an array (or series of
    # arrays) to schedule our jobs. This cuts down on problems with long
    # job lists choking up the queue.
    if dep_count == 0:
        logger.info("Compiling jobs into JobGroups")
        joblist = compile_jobgroups_from_joblist(joblist, jgprefix,
                                                 sgegroupsize)

    # Send jobs to scheduler
    logger.info("Running jobs with scheduler...")
    logger.info("Jobs passed to scheduler in order:")
    for job in joblist:
        logger.info("\t%s" % job.name)
    build_and_submit_jobs(os.curdir, joblist, sgeargs)
    logger.info("Waiting for SGE-submitted jobs to finish (polling)")
    for job in joblist:
        job.wait()