code: def serialize(to_serialize: Serializable) -> SerializedTraceType:
      """Converts Serializable to a proto SerializedTraceType."""
  
      if not isinstance(to_serialize, Serializable):
          raise ValueError(
              "Can not serialize "
              + type(to_serialize).__name__
              + " since it is not Serializable. For object "
              + str(to_serialize)
          )
      actual_proto = to_serialize.experimental_as_proto()
  
      if not isinstance(
          actual_proto, to_serialize.experimental_type_proto()
      ):
          raise ValueError(
              type(to_serialize).__name__
              + " returned different type of proto than specified by "
              + "experimental_type_proto()"
          )
  
      serialized = SerializedTraceType()
      serialized.representation.Pack(actual_proto)
      return serialized
  
file_path: tensorflow-upstream/tensorflow/core/function/trace_type/serialization.py
imports: import abc
  from typing import Type
  from google.protobuf import message
  from tensorflow.core.function.trace_type import serialization_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: serialize(to_serialize) and returns: serialized