code: def perturb_input(data, hard_edge_mask, subset):
      """add 2 additional empty node into the motif graph"""
      num_add_node = 2
      num_perturb_graph = 10
      subgraph_x = data.x[subset]
      subgraph_edge_index = data.edge_index[:, hard_edge_mask]
      row, col = data.edge_index
  
      mappings = row.new_full((data.num_nodes,), -1)
      mappings[subset] = torch.arange(subset.size(0), device=row.device)
      subgraph_edge_index = mappings[subgraph_edge_index]
  
      subgraph_y = data.y[subset]
  
      num_node_subgraph = subgraph_x.shape[0]
  
      # add two nodes to the subgraph, the node features are all 0.1
      subgraph_x = torch.cat(
          [
              subgraph_x,
              torch.ones(2, subgraph_x.shape[1]).to(subgraph_x.device),
          ],
          dim=0,
      )
      subgraph_y = torch.cat(
          [
              subgraph_y,
              torch.zeros(num_add_node)
              .type(torch.long)
              .to(subgraph_y.device),
          ],
          dim=0,
      )
  
      perturb_input_list = []
      for _ in range(num_perturb_graph):
          to_node = torch.randint(0, num_node_subgraph, (num_add_node,))
          frm_node = torch.arange(
              num_node_subgraph, num_node_subgraph + num_add_node, 1
          )
          add_edges = torch.cat(
              [
                  torch.stack([to_node, frm_node], dim=0),
                  torch.stack([frm_node, to_node], dim=0),
                  torch.stack([frm_node, frm_node], dim=0),
              ],
              dim=1,
          )
          perturb_subgraph_edge_index = torch.cat(
              [
                  subgraph_edge_index,
                  add_edges.to(subgraph_edge_index.device),
              ],
              dim=1,
          )
          perturb_input_list.append(
              Data(
                  x=subgraph_x,
                  edge_index=perturb_subgraph_edge_index,
                  y=subgraph_y,
              )
          )
  
      return perturb_input_list
  
file_path: DIG/benchmarks/xgraph/utils.py
imports: import json
  import os
  import torch
  import random
  import numpy
  from abc import ABC
  from torch_geometric.data import Data
label_desc: Use image node_id 3 for calling a global function with example usage: perturb_input(data, hard_edge_mask, subset) and returns: perturb_input_list