code: def gen_grid_sample(
      args, config, config_budget={}, compare_alias_list=[]
  ):
      task_name = (
          f"{get_fname(args.config)}_grid_{get_fname(args.grid)}"
      )
      fname_start = get_fname(args.config)
      out_dir = f"{args.out_dir}/{task_name}"
      makedirs_rm_exist(out_dir)
      config["out_dir"] = osp.join(config["out_dir"], task_name)
      outs = load_search_file(args.grid)
  
      counts = []
      for out in outs:
          vars_grid = [string_to_python(row[2]) for row in out]
          count = 1
          for var in vars_grid:
              count *= len(var)
          counts.append(count)
      counts = np.array(counts)
      print("Total size of each chunk of experiment space:", counts)
      counts = counts / np.sum(counts)
      counts = np.round(counts * args.sample_num)
      counts[0] += args.sample_num - np.sum(counts)
      print(
          "Total sample size of each chunk of experiment space:", counts
      )
  
      for i, out in enumerate(outs):
          vars_label = [row[0].split(".") for row in out]
          vars_alias = [row[1] for row in out]
          if i == 0:
              print(f"Variable label: {vars_label}")
              print(f"Variable alias: {vars_alias}")
          vars_grid = [string_to_python(row[2]) for row in out]
          for alias in compare_alias_list:
              alias_id = vars_alias.index(alias)
              vars_grid_select = copy.deepcopy(vars_grid[alias_id])
              vars_grid[alias_id] = [vars_grid[alias_id][0]]
              vars_value = grid2list_sample(vars_grid, counts[i])
  
              vars_value_new = []
              for vars in vars_value:
                  for grid in vars_grid_select:
                      vars[alias_id] = grid
                      vars_value_new.append(copy.deepcopy(vars))
              vars_value = vars_value_new
  
              vars_grid[alias_id] = vars_grid_select
              for vars in vars_value:
                  config_out = config.copy()
                  fname_out = (
                      fname_start + f"-sample={vars_alias[alias_id]}"
                  )
                  for id, var in enumerate(vars):
                      if len(vars_label[id]) == 1:
                          config_out[vars_label[id][0]] = var
                      elif len(vars_label[id]) == 2:
                          if (
                              vars_label[id][0] in config_out
                          ):  # if key1 exist
                              config_out[vars_label[id][0]][
                                  vars_label[id][1]
                              ] = var
                          else:
                              config_out[vars_label[id][0]] = {
                                  vars_label[id][1]: var
                              }
                      else:
                          raise ValueError(
                              "Only 2-level config files are supported"
                          )
                      var_repr = str(var).strip("[]").strip("''")
                      fname_out += f"-{vars_alias[id]}={var_repr}"
                  if len(config_budget) > 0:
                      config_out = match_baseline_cfg(
                          config_out, config_budget, verbose=False
                      )
                  with open(f"{out_dir}/{fname_out}.yaml", "w") as f:
                      yaml.dump(config_out, f, default_flow_style=False)
              print(
                  f"Chunk {i + 1}/{len(outs)}: "
                  f"Perturbing design dimension {alias}, "
                  f"{len(vars_value)} configurations saved to: {out_dir}"
              )
  
file_path: pytorch_geometric/graphgym/configs_gen.py
imports: import argparse
  import copy
  import csv
  import os.path
  import random
  import numpy
  import yaml
  from torch_geometric.graphgym.utils.comp_budget import match_baseline_cfg
  from torch_geometric.graphgym.utils.io import makedirs_rm_exist, string_to_python
label_desc: Use image node_id 11 for calling a global function with example usage: gen_grid_sample(args, config, config_budget, compare_alias_list) without return types