docstr: Assign initial nodes using breath-first search given initial sizes and
  limitations of spread range.
docstr_tok: ["Assign","initial","nodes","using","breath-first","search","given","initial","sizes","and","limitations","of","spread","range","."]
code: def _assign_by_bfs(
      cls,
      undirected_chunk_graph: ChunkGraph,
      start: ChunkData,
      band: BandType,
      initial_sizes: Dict[BandType, int],
      spread_limits: Dict[BandType, float],
      key_to_assign: OrderedSet,
      assigned_record: Dict[str, Union[str, BandType]],
  ):
      """
      Assign initial nodes using breath-first search given initial sizes and
      limitations of spread range.
      """
      if initial_sizes[band] <= 0:
          return
  
      assigned = 0
      spread_range = 0
      for chunk in undirected_chunk_graph.bfs(
          start=start, visit_predicate="all"
      ):
          op_key = chunk.op.key
          if op_key in assigned_record:
              continue
          spread_range += 1
          # `op_key` may not be in `key_to_assign`,
          # but we need to record it to avoid iterate the node repeatedly.
          assigned_record[op_key] = band
          if op_key not in key_to_assign:
              continue
          assigned += 1
          if (
              spread_range >= spread_limits[band]
              or assigned >= initial_sizes[band]
          ):
              break
      initial_sizes[band] -= assigned
  
imports: from abc import ABC, abstractmethod
  from collections import defaultdict
  from operator import itemgetter
  from typing import List, Dict, Union
  import numpy
  from ....core import ChunkGraph, ChunkData
  from ....core.operand import Operand, Fetch
  from ....lib.ordered_set import OrderedSet
  from ....resource import Resource
  from ....typing import BandType
  from ....utils import implements
label_desc: Use image node_id 3 for calling the GraphAssigner obj's underlying member method code with example usage: obj._assign_by_bfs(cls, undirected_chunk_graph, start, band, initial_sizes, spread_limits, key_to_assign, assigned_record) without return types