code: def gen_grid(args, config, config_budget={}):
      r"""Generate a batch of experiment configs based on the grid file"""
      task_name = (
          f"{get_fname(args.config)}_grid_{get_fname(args.grid)}"
      )
      fname_base = get_fname(args.config)
      out_dir = osp.join(args.out_dir, task_name)
      makedirs_rm_exist(out_dir)
      config["out_dir"] = os.path.join(config["out_dir"], task_name)
      outs = load_grid(args.grid)
  
      if args.sample:
          counts = design_space_count(outs, args.sample_num)
  
      for i, out in enumerate(outs):
          vars_label = [row[0].split(".") for row in out]
          vars_alias = [row[1] for row in out]
  
          if args.sample:
              vars_value = grid2list_sample(
                  [string_to_python(row[2]) for row in out],
                  sample=counts[i],
              )
          else:
              vars_value = grid2list(
                  [string_to_python(row[2]) for row in out]
              )
  
          if i == 0:
              print(f"Variable label: {vars_label}")
              print(f"Variable alias: {vars_alias}")
  
          for vars in vars_value:
              config_out = copy.deepcopy(config)
              fname_out = fname_base
              for j, var_label in enumerate(vars_label):
                  ptr = config_out
                  for item in var_label[:-1]:
                      if item not in ptr:
                          ptr[item] = {}
                      ptr = ptr[item]
                  ptr[var_label[-1]] = vars[j]
                  var_repr = str(vars[j]).strip("[]").strip("''")
                  fname_out += f"-{vars_alias[j]}={var_repr}"
              if len(config_budget) > 0:
                  config_out = match_baseline_cfg(
                      config_out, config_budget
                  )
              with open(
                  osp.join(out_dir, f"{fname_out[:250]}.yaml"), "w"
              ) as f:
                  yaml.dump(config_out, f, default_flow_style=False)
          print(f"{len(vars_value)} configurations saved to: {out_dir}")
  
imports: import argparse
  import copy
  import csv
  import os
  import os.path
  import random
  import numpy
  import yaml
  import graphgym.contrib
  from graphgym.utils.comp_budget import match_baseline_cfg
  from graphgym.utils.io import makedirs_rm_exist, string_to_python
label_desc: Use image node_id 12 for calling a global function with example usage: gen_grid(args, config, config_budget) without return types