code: def main(nodes, edges):
      """Generate a random graph, submit jobs, then validate that the
      dependency order was enforced.
      Finally, plot the graph, with time on the x-axis, and
      in-degree on the y (just for spread).  All arrows must
      point at least slightly to the right if the graph is valid.
      """
      from matplotlib import pyplot as plt
      from matplotlib.cm import gist_rainbow
      from matplotlib.dates import date2num
  
      print("building DAG")
      G = random_dag(nodes, edges)
      jobs = {}
      pos = {}
      colors = {}
      for node in G:
          jobs[node] = randomwait
  
      client = parallel.Client()
      view = client.load_balanced_view()
      print("submitting %i tasks with %i dependencies" % (nodes, edges))
      results = submit_jobs(view, G, jobs)
      print("waiting for results")
      client.wait_interactive()
      for node in G:
          md = results[node].metadata
          start = date2num(md.started)
          runtime = date2num(md.completed) - start
          pos[node] = (start, runtime)
          colors[node] = md.engine_id
      validate_tree(G, results)
      nx.draw(
          G,
          pos,
          node_list=list(colors.keys()),
          node_color=list(colors.values()),
          cmap=gist_rainbow,
          with_labels=False,
      )
      x, y = zip(*pos.values())
      xmin, ymin = map(min, (x, y))
      xmax, ymax = map(max, (x, y))
      xscale = xmax - xmin
      yscale = ymax - ymin
      plt.xlim(xmin - xscale * 0.1, xmax + xscale * 0.1)
      plt.ylim(ymin - yscale * 0.1, ymax + yscale * 0.1)
      return G, results
  
file_path: ipyparallel/docs/source/examples/dagdeps.py
imports: from random import randint
  import networkx
  import ipyparallel
label_desc: Use image node_id 7 for calling a global function with example usage: main(nodes, edges) and returns: G,  results