code: def node2vec_randomwalk_with_walktimes(
      graph,
      start_nodes,
      metapath,
      walk_length,
      walk_times=10,
      p=1.0,
      q=1.0,
  ):
      """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.
  
      """
      MAX_NEIGHBORS = 50
      if q == 1.0 and p == 1.0:
          warnings.warn(
              "node2vec with p==1.0 and q==1.0 with degenerate into deepwalk"
          )
          return metapath_randomwalk_with_walktimes(
              graph=graph,
              start_nodes=start_nodes,
              metapath=metapath,
              walk_length=walk_length,
              walk_times=walk_times,
          )
  
      edge_types = metapath.split("-")
      if len(set(edge_types)) > 1:
          raise ValueError("node2vec must have single metapath")
  
      n1, n2 = edge_types[0].split("2")
      if n1 != n2:
          raise ValueError(
              "node2vec must have same node types between edges."
          )
  
      walk = []
      cur_nodes = []
      prev_nodes = []
      neighbors = graph.sample_successor(
          np.array(start_nodes, dtype="uint64"),
          max_degree=max(walk_times, MAX_NEIGHBORS),
          edge_type=edge_types[0],
      )
  
      prev_succs = []
      for neigh, walk_id in zip(neighbors, start_nodes):
          for node_id in neigh[:walk_times]:
              walk.append([walk_id, node_id])
              cur_nodes.append(node_id)
              prev_nodes.append(walk_id)
              prev_succs.append(neigh)
  
      if len(walk) == 0:
          return walk
  
      cur_walk_ids = np.arange(0, len(walk))
      cur_nodes = np.array(cur_nodes, dtype="uint64")
      prev_nodes = np.array(prev_nodes, dtype="uint64")
      prev_succs = np.array(prev_succs, dtype="object")
      #  if np.random.random() - 0.02 < 0:
      #      sys.stderr.write("length of walks %s\n" % (len(walk)))
  
      mp_len = len(edge_types)
      for i in range(1, walk_length - 1):
          cur_succs = graph.sample_successor(
              cur_nodes,
              max_degree=MAX_NEIGHBORS,
              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]
              prev_succs = prev_succs[mask]
              prev_nodes = prev_nodes[mask]
              cur_succs = np.array(cur_succs, dtype="object")[mask]
          else:
              # stop when all nodes have no successor
              break
  
          num_nodes = cur_nodes.shape[0]
          nxt_nodes = np.zeros(num_nodes, dtype="uint64")
  
          for idx, (succ, prev_succ, walk_id, prev_node) in enumerate(
              zip(cur_succs, prev_succs, cur_walk_ids, prev_nodes)
          ):
              succ = np.array(succ, dtype="int64")
              prev_succ = np.array(prev_succ, dtype="int64")
              sampled_succ = graph_kernel.node2vec_sample(
                  succ, prev_succ, prev_node, p, q
              )
              if sampled_succ is None:
                  sampled_succ = succ[-1]
              walk[walk_id].append(sampled_succ)
              nxt_nodes[idx] = sampled_succ
  
          prev_nodes, prev_succs = cur_nodes, cur_succs
          cur_nodes = nxt_nodes.astype("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 16 for calling a global function with example usage: node2vec_randomwalk_with_walktimes(graph, start_nodes, metapath, walk_length, walk_times, p, q) and returns: walk, metapath_randomwalk_with_walktimes, walk