code: def retrieve_sources(sinks, ignore_control_dependencies=False):
      """Captures subgraph between sources and sinks.
  
      Walk a Graph backwards from `sinks` and return any sources encountered in the
      subgraph. This util is refactored from `_map_subgraph` in
      tensorflow/.../ops/op_selector.py.
  
      Arguments:
        sinks:  An iterable of Operations where the subgraph terminates.
        ignore_control_dependencies: (Optional) If `True`, ignore any
          `control_inputs` for all ops while walking the graph.
  
      Returns:
        The set of placeholders upon which `sinks` depend. This could also contain
        placeholders representing `captures` in the graph.
      """
      stop_at_tensors = object_identity.ObjectIdentitySet()
      ops_to_visit = object_identity.ObjectIdentitySet(sinks)
      visited_ops = object_identity.ObjectIdentitySet()
      potential_extra_sources = object_identity.ObjectIdentitySet()
      while ops_to_visit:
          op = ops_to_visit.pop()
          visited_ops.add(op)
  
          if op.type == "Placeholder":
              potential_extra_sources.update(op.outputs)
  
          input_ops = [
              t.op for t in op.inputs if t not in stop_at_tensors
          ]
          if not ignore_control_dependencies:
              input_ops = itertools.chain(input_ops, op.control_inputs)
          for input_op in input_ops:
              if input_op not in visited_ops:
                  ops_to_visit.add(input_op)
  
      return potential_extra_sources
  
imports: import collections
  import copy
  import hashlib
  import itertools
  from typing import Iterable, List, Mapping, Optional, Set, Union
  import uuid
  from absl import logging
  import tensorflow
  from tensorflow_transform import analyzer_nodes
  from tensorflow_transform import common_types
  from tensorflow_transform import nodes
  from tensorflow_transform import tf_utils
  from tfx_bsl.types import tfx_namedtuple
  from tensorflow.python.framework import composite_tensor
  from tensorflow.python.framework import func_graph
  from tensorflow.python.framework import function_def_to_graph
  from tensorflow.python.util import object_identity
label_desc: Use image node_id 2 for calling a global function with example usage: retrieve_sources(sinks, ignore_control_dependencies) and returns: potential_extra_sources