code: def get_subgraph(
      graph: "DiGraph",
      nodes: Optional[List] = None,
      pipeline: bool = False,
      downstream: bool = False,
  ) -> "DiGraph":
      import networkx as nx
  
      from .graph import (
          get_pipeline,
          get_pipelines,
          get_subgraph_of_nodes,
      )
  
      if not pipeline or not nodes:
          return get_subgraph_of_nodes(
              graph, nodes, downstream=downstream
          )
  
      pipelines = get_pipelines(graph)
      used_pipelines = [get_pipeline(pipelines, node) for node in nodes]
      return nx.compose_all(used_pipelines)
  
file_path: dvc/dvc/repo/reproduce.py
imports: from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, NoReturn, Optional, Set, Tuple, TypeVar, Union, cast
  from funcy import ldistinct
  from dvc.exceptions import ReproductionError
  from dvc.log import logger
  from dvc.repo.scm_context import scm_context
  from dvc.stage.cache import RunCacheNotSupported
  from dvc.utils import humanize
  from dvc.utils.collections import ensure_list
  from .None import locked
label_desc: Use image node_id 2 for calling a global function with example usage: get_subgraph(graph, nodes, pipeline, downstream) and returns: nx, get_subgraph_of_nodes