code: def k_hop_subgraph(
      src, dst, num_hops, g, sample_ratio=1.0, directed=False
  ):
      # Extract the k-hop enclosing subgraph around link (src, dst) from g
      nodes = [src, dst]
      visited = set([src, dst])
      fringe = set([src, dst])
      for _ in range(num_hops):
          if not directed:
              _, fringe = g.out_edges(list(fringe))
              fringe = fringe.tolist()
          else:
              _, out_neighbors = g.out_edges(list(fringe))
              in_neighbors, _ = g.in_edges(list(fringe))
              fringe = in_neighbors.tolist() + out_neighbors.tolist()
          fringe = set(fringe) - visited
          visited = visited.union(fringe)
  
          if sample_ratio < 1.0:
              fringe = random.sample(
                  fringe, int(sample_ratio * len(fringe))
              )
          if len(fringe) == 0:
              break
  
          nodes = nodes + list(fringe)
  
      subg = g.subgraph(nodes, store_ids=True)
  
      return subg
  
file_path: dgl/examples/pytorch/ogb/ngnn_seal/utils.py
imports: import random
  import sys
  import numpy
  import torch
  from dgl.sampling import global_uniform_negative_sampling
  from scipy.sparse.csgraph import shortest_path
label_desc: Use image node_id 1 for calling a global function with example usage: k_hop_subgraph(src, dst, num_hops, g, sample_ratio, directed) and returns: subg