code: def node2vec_walk_plus(graph, nodes, max_depth, p=1.0, q=1.0):
      """Implement of node2vec random walk.
  
      Reference paper: https://cs.stanford.edu/~jure/pubs/node2vec-kdd16.pdf.
  
      Args:
          graph: A pgl graph instance
          nodes: Walk starting from nodes
          max_depth: Max walking depth
          p: Return parameter
          q: In-out parameter
  
      Return:
          A list of walks.
      """
      if p == 1.0 and q == 1.0:
          return random_walk(graph, nodes, max_depth)
  
      walk = []
      # init
      for node in nodes:
          walk.append([node])
  
      cur_walk_ids = np.arange(0, len(nodes))
      cur_nodes = np.array(nodes)
      prev_nodes = np.array([-1] * len(nodes), dtype="int64")
      prev_succs = np.array([[]] * len(nodes), dtype="int64")
      for l in range(max_depth):
          # select the walks not end
          cur_succs = graph.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]
              prev_nodes = prev_nodes[mask]
              prev_succs = prev_succs[mask]
              cur_succs = cur_succs[mask]
          else:
              # stop when all nodes have no successor
              break
          num_nodes = cur_nodes.shape[0]
          nxt_nodes = np.zeros(num_nodes, dtype="int64")
  
          new_prev_succs = []
          for idx, (succ, prev_succ, walk_id, prev_node) in enumerate(
              zip(cur_succs, prev_succs, cur_walk_ids, prev_nodes)
          ):
              (
                  sampled_succ,
                  new_prev_succ,
              ) = graph_kernel.node2vec_plus_sample(
                  succ, prev_succ.astype(np.int64), prev_node, p, q
              )
              walk[walk_id].append(sampled_succ)
              nxt_nodes[idx] = sampled_succ
              new_prev_succs.append(new_prev_succ)
  
          prev_nodes = cur_nodes
          prev_succs = np.array(new_prev_succs, dtype=object)
          cur_nodes = nxt_nodes
      return walk
  
imports: import numpy
  from pgl import graph_kernel
label_desc: Use image node_id 3 for calling a global function with example usage: node2vec_walk_plus(graph, nodes, max_depth, p, q) and returns: walk, random_walk