class_docstr: Coloring a chunk graph according to an algorithm
  described in https://github.com/mars-project/mars/issues/2435
class_docstr_tok: ["Coloring","a","chunk","graph","according","to","an","algorithm","described","in","https",":","\/\/github.com\/mars-project\/mars\/issues\/2435"]
code: def _color_init_nodes(self) -> Dict[OperandType, int]:
      # for initial op with same band but different priority
      # we color them w/ different colors,
      # to prevent from wrong fusion.
      # e.g. md.read_csv ensure incremental index by generating
      # chunks with ascending priorities (smaller one has higher priority),
      # chunk 0 has higher priority than chunk 1,
      # so that when chunk 1 executing, it would know chunk 0's shape
      # TODO: make it general instead handle priority as a special case
      band_priority_to_colors = dict()
      for chunk, band in self.chunk_to_bands.items():
          band_priority = (band, chunk.op.priority)
          if band_priority not in band_priority_to_colors:
              band_priority_to_colors[band_priority] = self.next_color()
  
      band_priority_to_color_list = defaultdict(list)
      for (band, priority), color in band_priority_to_colors.items():
          band_priority_to_color_list[band, priority].append(color)
      color_to_size = defaultdict(lambda: 0)
      op_to_colors = dict()
      for chunk, band in self.chunk_to_bands.items():
          priority = chunk.op.priority
          color = band_priority_to_color_list[band, priority][-1]
          size = color_to_size[color]
          if size >= self.initial_same_color_num:
              color = self.next_color()
              band_priority_to_color_list[band, priority].append(color)
          color_to_size[color] += 1
          op_to_colors[chunk.op] = color
      return op_to_colors
  
file_path: mars/mars/services/task/analyzer/fusion.py
imports: import itertools
  from collections import defaultdict
  from typing import Dict, List
  from ....config import options
  from ....core import ChunkGraph
  from ....core.operand import VirtualOperand
  from ....typing import BandType, ChunkType, OperandType
label_desc: Use image node_id 4 for calling the Coloring obj's underlying member method code with example usage: obj._color_init_nodes() and returns: op_to_colors