docs: def submit_job(pbs_script, pbs_config, pbs_vars=None):
      """Submit a userscript the scheduler."""
  
      # Initialisation
      if pbs_vars is None:
          pbs_vars = {}
  
      pbs_flags = []
  
      pbs_queue = pbs_config.get('queue', 'normal')
      pbs_flags.append('-q {queue}'.format(queue=pbs_queue))
  
      pbs_project = pbs_config.get('project', os.environ['PROJECT'])
      pbs_flags.append('-P {project}'.format(project=pbs_project))
  
      pbs_resources = ['walltime', 'ncpus', 'mem', 'jobfs']
  
      for res_key in pbs_resources:
          res_flags = []
          res_val = pbs_config.get(res_key)
          if res_val:
              res_flags.append('{key}={val}'.format(key=res_key, val=res_val))
  
          if res_flags:
              pbs_flags.append('-l {res}'.format(res=','.join(res_flags)))
  
      # TODO: Need to pass lab.config_path somehow...
      pbs_jobname = pbs_config.get('jobname', os.path.basename(os.getcwd()))
      if pbs_jobname:
          # PBSPro has a 15-character jobname limit
          pbs_flags.append('-N {name}'.format(name=pbs_jobname[:15]))
  
      pbs_priority = pbs_config.get('priority')
      if pbs_priority:
          pbs_flags.append('-p {priority}'.format(priority=pbs_priority))
  
      pbs_flags.append('-l wd')
  
      pbs_join = pbs_config.get('join', 'n')
      if pbs_join not in ('oe', 'eo', 'n'):
          print('payu: error: unknown qsub IO stream join setting.')
          sys.exit(-1)
      else:
          pbs_flags.append('-j {join}'.format(join=pbs_join))
  
      # Append environment variables to qsub command
      # TODO: Support full export of environment variables: `qsub -V`
      pbs_vstring = ','.join('{0}={1}'.format(k, v)
                             for k, v in pbs_vars.items())
      pbs_flags.append('-v ' + pbs_vstring)
  
      # Append any additional qsub flags here
      pbs_flags_extend = pbs_config.get('qsub_flags')
      if pbs_flags_extend:
          pbs_flags.append(pbs_flags_extend)
  
      if not os.path.isabs(pbs_script):
          # NOTE: PAYU_PATH is always set if `set_env_vars` was always called.
          #       This is currently always true, but is not explicitly enforced.
          #       So this conditional check is a bit redundant.
          payu_bin = pbs_vars.get('PAYU_PATH', os.path.dirname(sys.argv[0]))
          pbs_script = os.path.join(payu_bin, pbs_script)
          assert os.path.isfile(pbs_script)
  
      # Set up environment modules here for PBS.
      envmod.setup()
      envmod.module('load', 'pbs')
  
      # Construct job submission command
      cmd = 'qsub {flags} -- {python} {script}'.format(
          flags=' '.join(pbs_flags),
          python=sys.executable,
          script=pbs_script
      )
      print(cmd)
  
      subprocess.check_call(shlex.split(cmd))