code: def metapath_randomwalk(
      graph,
      start_nodes,
      metapath,
      walk_length,
      alias_name=None,
      events_name=None,
  ):
      """Implementation of metapath random walk in heterogeneous graph.
  
      Args:
          graph: instance of pgl heterogeneous graph
          start_nodes: start nodes to generate walk
          metapath: meta path for sample nodes.
              e.g: "c2p-p2a-a2p-p2c"
          walk_length: the walk length
  
      Return:
          a list of metapath walks.
  
      """
  
      edge_types = metapath.split("-")
  
      walk = []
      for node in start_nodes:
          walk.append([node])
  
      cur_walk_ids = np.arange(0, len(start_nodes))
      cur_nodes = np.array(start_nodes)
      mp_len = len(edge_types)
      for i in range(0, walk_length - 1):
          g = graph[edge_types[i % mp_len]]
  
          cur_succs = g.successor(cur_nodes)
          mask = [len(succ) > 0 for succ in cur_succs]
  
          if np.any(mask):
              cur_walk_ids = cur_walk_ids[mask]
              cur_nodes = cur_nodes[mask]
              cur_succs = cur_succs[mask]
          else:
              # stop when all nodes have no successor
              break
  
          if alias_name is not None and events_name is not None:
              sample_index = [
                  alias_sample(
                      [1],
                      g.node_feat[alias_name][node],
                      g.node_feat[events_name][node],
                  )[0]
                  for node in cur_nodes
              ]
          else:
              outdegree = [len(cur_succ) for cur_succ in cur_succs]
              sample_index = np.floor(
                  np.random.rand(cur_succs.shape[0]) * outdegree
              ).astype("int64")
  
          nxt_cur_nodes = []
          for s, ind, walk_id in zip(
              cur_succs, sample_index, cur_walk_ids
          ):
              walk[walk_id].append(s[ind])
              nxt_cur_nodes.append(s[ind])
          cur_nodes = np.array(nxt_cur_nodes)
  
      return walk
  
file_path: PGL/legacy/pgl/sample.py
imports: import time
  import copy
  import numpy
  import pgl
  from pgl.utils.logger import log
  from pgl import graph_kernel
label_desc: Use image node_id 9 for calling a global function with example usage: metapath_randomwalk(graph, start_nodes, metapath, walk_length, alias_name, events_name) and returns: walk