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, dtype="uint64")
      mp_len = len(edge_types)
      for i in range(0, walk_length - 1):
          cur_succs = graph.sample_successor(
              cur_nodes, max_degree=1, edge_type=edge_types[i % mp_len]
          )
          mask = np.array(
              [len(succ) > 0 for succ in cur_succs], dtype="bool"
          )
          #  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 = np.array(cur_succs, dtype="object")[mask]
          else:
              # stop when all nodes have no successor
              break
  
          nxt_cur_nodes = []
          for s, walk_id in zip(cur_succs, cur_walk_ids):
              walk[walk_id].append(s[0])
              nxt_cur_nodes.append(s[0])
          cur_nodes = np.array(nxt_cur_nodes, dtype="uint64")
      return walk
  
imports: import sys
  import time
  import copy
  import warnings
  import numpy
  import pgl
  from pgl import graph_kernel
  from pgl.utils.logger import log
label_desc: Use image node_id 10 for calling a global function with example usage: metapath_randomwalk(graph, start_nodes, metapath, walk_length, alias_name, events_name) and returns: walk