parameters: (self, item, cluster)
docstring: Controller class initializer.
  
      Args:
        item: The metagraph to place wrapped in a cluster.
        cluster: A cluster of devices on which to place the item.
docstring_summary: Controller class initializer.
docstring_tokens: Controller class initializer .
function: def __init__(self, item, cluster):
      """Controller class initializer.
  
      Args:
        item: The metagraph to place wrapped in a cluster.
        cluster: A cluster of devices on which to place the item.
      """
      self.item = item
  
      self._node = {}
      for node in item.metagraph.graph_def.node:
        self._node[node.name] = node
  
      self._fanout = defaultdict(lambda: [])
      for node in item.metagraph.graph_def.node:
        for fanin in self._get_node_fanin(node):
          self._fanout[fanin.name].append(node)
  
      important_op_names = item.IdentifyImportantOps(sort_topologically=True)
  
      # List of important ops (these are the ops to place) sorted in topological
      # order. The order of this collection is deterministic.
      self.important_ops = []
      for name in important_op_names:
        self.important_ops.append(self._node[name])
  
      self.node_properties = item.GetOpProperties()
  
      self.cluster = cluster
      self.devices = cluster.ListDevices()
  
      self.colocation_constraints = item.GetColocationGroups()
  
      self.placement_constraints = cluster.GetSupportedDevices(item)
      for node_name, dev in self.placement_constraints.items():
        if len(dev) == 1:
          # Place the node on the supported device
          node = self._node[node_name]
          node.device = dev[0]
          fanout = self.get_node_fanout(node)
          # Update the fanout of the fanin to bypass the node
          for fanin in self._get_node_fanin(node):
            fanout_of_fanin = self.get_node_fanout(fanin)
            fanout_of_fanin += fanout
            fanout_of_fanin.remove(node)
          # Remove node from the list of important ops since we don't need to
          # place the node.
          if node in self.important_ops:
            self.important_ops.remove(node)
            important_op_names.remove(node.name)
  
      # List of important op names, in non deterministic order.
      self.important_op_names = frozenset(important_op_names)
function_tokens: def __init__ ( self , item , cluster ) : self . item = item self . _node = { } for node in item . metagraph . graph_def . node : self . _node [ node . name ] = node self . _fanout = defaultdict ( lambda : [ ] ) for node in item . metagraph . graph_def . node : for fanin in self . _get_node_fanin ( node ) : self . _fanout [ fanin . name ] . append ( node ) important_op_names = item . IdentifyImportantOps ( sort_topologically = True ) # List of important ops (these are the ops to place) sorted in topological # order. The order of this collection is deterministic. self . important_ops = [ ] for name in important_op_names : self . important_ops . append ( self . _node [ name ] ) self . node_properties = item . GetOpProperties ( ) self . cluster = cluster self . devices = cluster . ListDevices ( ) self . colocation_constraints = item . GetColocationGroups ( ) self . placement_constraints = cluster . GetSupportedDevices ( item ) for node_name , dev in self . placement_constraints . items ( ) : if len ( dev ) == 1 : # Place the node on the supported device node = self . _node [ node_name ] node . device = dev [ 0 ] fanout = self . get_node_fanout ( node ) # Update the fanout of the fanin to bypass the node for fanin in self . _get_node_fanin ( node ) : fanout_of_fanin = self . get_node_fanout ( fanin ) fanout_of_fanin += fanout fanout_of_fanin . remove ( node ) # Remove node from the list of important ops since we don't need to # place the node. if node in self . important_ops : self . important_ops . remove ( node ) important_op_names . remove ( node . name ) # List of important op names, in non deterministic order. self . important_op_names = frozenset ( important_op_names )