class_docstr: tf.Graph & mtf.Graph common representation which produces a CostGraphDef.
  
  Attributes:
    canonical_device: string or None, the name of the canonical device for
        is_tensor_on_canonical_device
  
  Usage Example:
    mtf_graph = mtf.Graph()
    # Add operations to mtf_graph using Mesh TensorFlow.
    graph = graph_interface.GraphInterface(mtf_graph)
    for operation_name in graph.get_all_operation_names():
      print("Operation: {}".format(operation_name))
      for input_name in graph.get_operation_input_names(operation_name):
        print("  Input: {}".format(input_name))
      for output_name in graph.get_operation_output_names(operation_name):
        print("  Output: {}".format(output_name))
        # Tensor names can also be used to retrieve data type, shape, and Mesh
        # TensorFlow dimension names.
      # Operation names can also be used to get Mesh TensorFlow dimension names.
    cost_graph = graph.compute_cost_graph()
    # Give cost_graph to a scheduler to compute schedule.
    memory_contents = graph.compute_memory_contents_under_schedule(schedule)
class_docstr_tok: ["tf.Graph","&","mtf.Graph","common","representation","which","produces","a","CostGraphDef",".","Attributes",":","canonical_device",":","string","or","None",",","the","name","of","the","canonical","device","for","is_tensor_on_canonical_device","Usage","Example",":","mtf_graph","=","mtf.Graph","(",")","#","Add","operations","to","mtf_graph","using","Mesh","TensorFlow",".","graph","=","graph_interface.GraphInterface","(","mtf_graph",")","for","operation_name","in","graph.get_all_operation_names","(",")",":","print","(","``","Operation",":","{","}","''",".format","(","operation_name",")",")","for","input_name","in","graph.get_operation_input_names","(","operation_name",")",":","print","(","``","Input",":","{","}","''",".format","(","input_name",")",")","for","output_name","in","graph.get_operation_output_names","(","operation_name",")",":","print","(","``","Output",":","{","}","''",".format","(","output_name",")",")","#","Tensor","names","can","also","be","used","to","retrieve","data","type",",","shape",",","and","Mesh","#","TensorFlow","dimension","names",".","#","Operation","names","can","also","be","used","to","get","Mesh","TensorFlow","dimension","names",".","cost_graph","=","graph.compute_cost_graph","(",")","#","Give","cost_graph","to","a","scheduler","to","compute","schedule",".","memory_contents","=","graph.compute_memory_contents_under_schedule","(","schedule",")"]
docstr: Computes a CostGraphDef protobuf based on this graph.
  
  Defined in tensorflow/core/framework/cost_graph.proto.
  
  Args:
    devices: optional [string], the names of devices to consider. If
        specified, any tensor on a device not listed is given a size of zero.
        Any device-less tensor (e.g. Mesh TensorFlow tensor) is not affected.
  
  Returns:
    a CostGraphDef protobuf with a Node for every operation in the graph, each
    of which is populated with size/dtype information for its inputs and
    outputs (which match the input/output order of the operation).
docstr_tok: ["Computes","a","CostGraphDef","protobuf","based","on","this","graph",".","Defined","in","tensorflow\/core\/framework\/cost_graph.proto",".","Args",":","devices",":","optional","[","string","]",",","the","names","of","devices","to","consider",".","If","specified",",","any","tensor","on","a","device","not","listed","is","given","a","size","of","zero",".","Any","device-less","tensor","(","e.g",".","Mesh","TensorFlow","tensor",")","is","not","affected",".","Returns",":","a","CostGraphDef","protobuf","with","a","Node","for","every","operation","in","the","graph",",","each","of","which","is","populated","with","size\/dtype","information","for","its","inputs","and","outputs","(","which","match","the","input\/output","order","of","the","operation",")","."]
code: def compute_cost_graph(self, devices=None):
      """Computes a CostGraphDef protobuf based on this graph.
  
      Defined in tensorflow/core/framework/cost_graph.proto.
  
      Args:
        devices: optional [string], the names of devices to consider. If
            specified, any tensor on a device not listed is given a size of zero.
            Any device-less tensor (e.g. Mesh TensorFlow tensor) is not affected.
  
      Returns:
        a CostGraphDef protobuf with a Node for every operation in the graph, each
        of which is populated with size/dtype information for its inputs and
        outputs (which match the input/output order of the operation).
      """
      cost_graph_def = cost_graph_pb2.CostGraphDef()
  
      for i, operation_name in enumerate(
          self.get_all_operation_names()
      ):
          node = cost_graph_def.node.add(
              name=operation_name,
              device=self.get_operation_device(operation_name),
              id=i,
          )
          for input_name in self.get_operation_input_names(
              operation_name
          ):
              id1, id2 = self._tensor_name_to_ids[input_name]
              node.input_info.add(
                  preceding_node=id1, preceding_port=id2
              )
  
          for output_name in self.get_operation_output_names(
              operation_name
          ):
              tensor_device = self.get_tensor_device(output_name)
              # devices = [] is not the same as None, and tensor_device = '' is also
              # not the same as None.
              if (
                  devices is None
                  or tensor_device is None
                  or tensor_device in devices
              ):
                  node.output_info.add(
                      size=self.get_tensor_size(output_name),
                      alias_input_port=-1,
                      dtype=self.get_tensor_dtype(
                          output_name
                      ).as_datatype_enum,
                      shape=self.get_tensor_shape(
                          output_name
                      ).as_proto(),
                  )
              else:
                  node.output_info.add(
                      size=0,
                      alias_input_port=-1,
                      dtype=self.get_tensor_dtype(
                          output_name
                      ).as_datatype_enum,
                  )
  
              # NOTE(joshuawang): Unfortunately, the CostGraphDef protobuf has final
              # operations, not tensors. As a result, we have to declare any operation
              # that outputs a final tensor as final, which may expand the final set
              # of tensors to keep in memory. This issue also arises in the scheduler
              # code we will interface with.
              if self.is_tensor_final(output_name):
                  node.is_final = True
  
      return cost_graph_def
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import math
  import mesh_tensorflow
  import tensorflow.compat.v1
  from tensorflow.core.framework import cost_graph_pb2
label_desc: Use image node_id 18 for calling the GraphInterface obj's underlying member method code with example usage: obj.compute_cost_graph(devices) and returns: cost_graph_def