code: def _serialize_pipeline(pipeline: tfx_pipeline.Pipeline) -> str:
      """Serializes a TFX pipeline.
  
      To be replaced with the the TFX Intermediate Representation:
      tensorflow/community#271. This serialization procedure extracts from
      the pipeline properties necessary for reconstructing the pipeline instance
      from within the cluster. For properties such as components and metadata
      config that can not be directly dumped with JSON, we use NodeWrapper and
      MessageToJson to serialize them beforehand.
  
      Args:
        pipeline: Logical pipeline containing pipeline args and components.
  
      Returns:
        Pipeline serialized as JSON string.
      """
      serialized_components = []
      for component in pipeline.components:
          serialized_components.append(
              json_utils.dumps(node_wrapper.NodeWrapper(component))
          )
      # Extract and pass pipeline graph information which are lost during the
      # serialization process. The orchestrator container uses downstream_ids
      # to reconstruct pipeline graph.
      downstream_ids = _extract_downstream_ids(pipeline.components)
      return json.dumps(
          {
              "pipeline_name": pipeline.pipeline_info.pipeline_name,
              "pipeline_root": pipeline.pipeline_info.pipeline_root,
              "enable_cache": pipeline.enable_cache,
              "components": serialized_components,
              "downstream_ids": downstream_ids,
              "metadata_connection_config": json_format.MessageToJson(
                  message=pipeline.metadata_connection_config,
                  preserving_proto_field_name=True,
              ),
              "beam_pipeline_args": pipeline.beam_pipeline_args,
          }
      )
  
file_path: tfx/tfx/orchestration/experimental/kubernetes/kubernetes_remote_runner.py
imports: import datetime
  import json
  import time
  from typing import Dict, List
  from absl import logging
  from kubernetes import client
  from tfx.dsl.components.base import base_node
  from tfx.dsl.context_managers import dsl_context_registry
  from tfx.orchestration import pipeline
  from tfx.orchestration.experimental.kubernetes import node_wrapper
  from tfx.utils import json_utils
  from tfx.utils import kube_utils
  from google.protobuf import json_format
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 3 for calling a global function with example usage: _serialize_pipeline(pipeline) and returns: json