code: def _topsorted_layers(
      pipeline: pipeline_pb2.Pipeline,
  ) -> List[List[node_proto_view.NodeProtoView]]:
      """Returns pipeline nodes in topologically sorted layers."""
      node_by_id = _node_by_id(pipeline)
      return topsort.topsorted_layers(
          [node_proto_view.get_view(node) for node in pipeline.nodes],
          get_node_id_fn=lambda node: node.node_info.id,
          get_parent_nodes=(
              lambda node: [node_by_id[n] for n in node.upstream_nodes]
          ),
          get_child_nodes=(
              lambda node: [
                  node_by_id[n] for n in node.downstream_nodes
              ]
          ),
      )
  
imports: import collections
  import textwrap
  from typing import Callable, Dict, List, Mapping, Optional, Set
  from absl import logging
  from tfx.orchestration import node_proto_view
  from tfx.orchestration.experimental.core import mlmd_state
  from tfx.orchestration.experimental.core import pipeline_state
  from tfx.orchestration.experimental.core import service_jobs
  from tfx.orchestration.experimental.core import task
  from tfx.orchestration.experimental.core import task_gen
  from tfx.orchestration.experimental.core import task_gen_utils
  from tfx.orchestration import mlmd_connection_manager
  from tfx.orchestration.portable.input_resolution import exceptions
  from tfx.orchestration.portable.mlmd import execution_lib
  from tfx.proto.orchestration import pipeline_pb2
  from tfx.utils import status
  from tfx.utils import topsort
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: _topsorted_layers(pipeline) and returns: topsort