code: def to_pipeline_file(stage: "PipelineStage"):
      wdir = resolve_wdir(stage.wdir, stage.path)
      param_objs, deps_objs = split_params_deps(stage)
      deps = sorted(d.def_path for d in deps_objs)
      params = _serialize_params_keys(param_objs)
  
      outs, metrics, plots = _serialize_outs(stage.outs)
  
      cmd = stage.cmd
      assert cmd, (
          f"'{stage.PARAM_CMD}' cannot be empty for stage '{stage.name}', "
          f"got: '{cmd}'(type: '{type(cmd).__name__}')"
      )
      res = [
          (stage.PARAM_DESC, stage.desc),
          (stage.PARAM_CMD, stage.cmd),
          (stage.PARAM_WDIR, wdir),
          (stage.PARAM_DEPS, deps),
          (stage.PARAM_PARAMS, params),
          (stage.PARAM_OUTS, outs),
          (stage.PARAM_METRICS, metrics),
          (stage.PARAM_PLOTS, plots),
          (stage.PARAM_FROZEN, stage.frozen),
          (stage.PARAM_ALWAYS_CHANGED, stage.always_changed),
          (stage.PARAM_META, stage.meta),
      ]
      return {
          stage.name: OrderedDict(
              [(key, value) for key, value in res if value]
          )
      }
  
file_path: dvc/dvc/stage/serialize.py
imports: from collections import OrderedDict
  from operator import attrgetter
  from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Union, no_type_check
  from funcy import post_processing
  from dvc.dependency import ParamsDependency
  from dvc.output import Annotation, Output
  from dvc.utils.collections import apply_diff
  from dvc.utils.serialize import parse_yaml_for_update
  from .params import StageParams
  from .utils import resolve_wdir, split_params_deps
label_desc: Use image node_id 6 for calling a global function with example usage: to_pipeline_file(stage) and returns: dict