code: def to_single_stage_file(stage: "Stage", **kwargs):
      state = stage.dumpd(**kwargs)
  
      # When we load a stage we parse yaml with a fast parser, which strips
      # off all the comments and formatting. To retain those on update we do
      # a trick here:
      # - reparse the same yaml text with a slow but smart ruamel yaml parser
      # - apply changes to a returned structure
      # - serialize it
      text = stage._stage_text
      if text is None:
          return state
  
      saved_state = parse_yaml_for_update(text, stage.path)
      apply_diff(state, saved_state)
      return saved_state
  
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 9 for calling a global function with example usage: to_single_stage_file(stage) and returns: saved_state, state