class_docstr: Breadth First Walk for heterogeneous graphs that generates a sampled number of paths from a starting node.
  It can be used to extract a random sub-graph starting from a set of initial nodes.
class_docstr_tok: ["Breadth","First","Walk","for","heterogeneous","graphs","that","generates","a","sampled","number","of","paths","from","a","starting","node",".","It","can","be","used","to","extract","a","random","sub-graph","starting","from","a","set","of","initial","nodes","."]
docstr: Performs a sampled breadth-first walk starting from the root nodes.
  
  Args:
      nodes (list): A list of root node ids such that from each node n BFWs will be generated
          with the number of samples per hop specified in n_size.
      n_size (int): The number of neighbouring nodes to expand at each depth of the walk. Sampling of
      n (int, default 1): Number of walks per node id. Neighbours with replacement is always used regardless
          of the node degree and number of neighbours requested.
      seed (int, optional): Random number generator seed; default is None
  
  Returns:
      A list of lists such that each list element is a sequence of ids corresponding to a sampled Heterogeneous
      BFW.
docstr_tok: ["Performs","a","sampled","breadth-first","walk","starting","from","the","root","nodes",".","Args",":","nodes","(","list",")",":","A","list","of","root","node","ids","such","that","from","each","node","n","BFWs","will","be","generated","with","the","number","of","samples","per","hop","specified","in","n_size",".","n_size","(","int",")",":","The","number","of","neighbouring","nodes","to","expand","at","each","depth","of","the","walk",".","Sampling","of","n","(","int",",","default","1",")",":","Number","of","walks","per","node","id",".","Neighbours","with","replacement","is","always","used","regardless","of","the","node","degree","and","number","of","neighbours","requested",".","seed","(","int",",","optional",")",":","Random","number","generator","seed",";","default","is","None","Returns",":","A","list","of","lists","such","that","each","list","element","is","a","sequence","of","ids","corresponding","to","a","sampled","Heterogeneous","BFW","."]
code: def run(self, nodes, n_size, n=1, seed=None):
      """
      Performs a sampled breadth-first walk starting from the root nodes.
  
      Args:
          nodes (list): A list of root node ids such that from each node n BFWs will be generated
              with the number of samples per hop specified in n_size.
          n_size (int): The number of neighbouring nodes to expand at each depth of the walk. Sampling of
          n (int, default 1): Number of walks per node id. Neighbours with replacement is always used regardless
              of the node degree and number of neighbours requested.
          seed (int, optional): Random number generator seed; default is None
  
      Returns:
          A list of lists such that each list element is a sequence of ids corresponding to a sampled Heterogeneous
          BFW.
      """
      self._check_sizes(n_size)
      self._check_common_parameters(nodes, n, len(n_size), seed)
      rs, _ = self._get_random_state(seed)
  
      adj = self.get_adjacency_types()
  
      walks = []
      d = len(n_size)  # depth of search
  
      for node in nodes:  # iterate over root nodes
          for _ in range(
              n
          ):  # do n bounded breadth first walks from each root node
              q = list()  # the queue of neighbours
              walk = list()  # the list of nodes in the subgraph of node
  
              # Start the walk by adding the head node, and node type to the frontier list q
              node_type = self.graph.node_type(node, use_ilocs=True)
              q.extend([(node, node_type, 0)])
  
              # add the root node to the walks
              walk.append([node])
              while len(q) > 0:
                  # remove the top element in the queue and pop the item from the front of the list
                  frontier = q.pop(0)
                  current_node, current_node_type, depth = frontier
                  depth = (
                      depth + 1
                  )  # the depth of the neighbouring nodes
  
                  # consider the subgraph up to and including depth d from root node
                  if depth <= d:
                      # Find edge types for current node type
                      current_edge_types = self.graph_schema.schema[
                          current_node_type
                      ]
  
                      # Create samples of neigbhours for all edge types
                      for et in current_edge_types:
                          neigh_et = adj[et][current_node]
  
                          # If there are no neighbours of this type then we return None
                          # in the place of the nodes that would have been sampled
                          # YT update: with the new way to get neigh_et from adj[et][current_node], len(neigh_et) is always > 0.
                          # In case of no neighbours of the current node for et, neigh_et == [None],
                          # and samples automatically becomes [None]*n_size[depth-1]
                          if len(neigh_et) > 0:
                              samples = rs.choices(
                                  neigh_et, k=n_size[depth - 1]
                              )
                          else:  # this doesn't happen anymore, see the comment above
                              _size = n_size[depth - 1]
                              samples = [-1] * _size
  
                          walk.append(samples)
                          q.extend(
                              [
                                  (sampled_node, et.n2, depth)
                                  for sampled_node in samples
                              ]
                          )
  
              # finished i-th walk from node so add it to the list of walks as a list
              walks.append(walk)
  
      return walks
  
imports: import numpy
  import warnings
  from collections import defaultdict, deque
  from scipy import stats
  from scipy.special import softmax
  from ..core.schema import GraphSchema
  from ..core.graph import StellarGraph
  from ..core.utils import is_real_iterable
  from ..core.validation import require_integer_in_range, comma_sep
  from ..random import random_state
  from abc import ABC, abstractmethod
label_desc: Use image node_id 1 for calling the SampledHeterogeneousBreadthFirstWalk obj's underlying member method code with example usage: obj.run(nodes, n_size, n, seed) and returns: walks