code: def write_forward_solution(fname, fwd, overwrite=False, verbose=None):
      """Write forward solution to a file.
  
      Parameters
      ----------
      %(fname_fwd)s
      fwd : Forward
          Forward solution.
      %(overwrite)s
      %(verbose)s
  
      See Also
      --------
      read_forward_solution
  
      Notes
      -----
      Forward solutions, which are derived from an original forward solution with
      free orientation, are always stored on disk as forward solution with free
      orientation in X/Y/Z RAS coordinates. Transformations (surface orientation,
      fixed orientation) will be reverted. To reapply any transformation to the
      forward operator please apply :func:`convert_forward_solution` after
      reading the forward solution with :func:`read_forward_solution`.
  
      Forward solutions, which are derived from an original forward solution with
      fixed orientation, are stored on disk as forward solution with fixed
      surface-based orientations. Please note that the transformation to
      surface-based, fixed orientation cannot be reverted after loading the
      forward solution with :func:`read_forward_solution`.
      """
      check_fname(
          fname,
          "forward",
          (
              "-fwd.fif",
              "-fwd.fif.gz",
              "_fwd.fif",
              "_fwd.fif.gz",
              "-fwd.h5",
              "_fwd.h5",
          ),
      )
  
      # check for file existence and expand `~` if present
      fname = _check_fname(fname, overwrite)
      if fname.suffix == ".h5":
          _write_forward_hdf5(fname, fwd)
      else:
          with start_and_end_file(fname) as fid:
              _write_forward_solution(fid, fwd)
  
imports: import os
  import re
  import shutil
  import tempfile
  from copy import deepcopy
  from os import PathLike
  from os import path
  from pathlib import Path
  from time import time
  import numpy
  from scipy import sparse
  from .._fiff.constants import FIFF
  from .._fiff.matrix import _read_named_matrix, _transpose_named_matrix, write_named_matrix
  from .._fiff.meas_info import Info, _make_ch_names_mapping, _read_bad_channels, _read_extended_ch_info, _write_bad_channels, _write_ch_infos, write_info
  from .._fiff.open import fiff_open
  from .._fiff.pick import pick_channels, pick_channels_forward, pick_info, pick_types
  from .._fiff.tag import find_tag, read_tag
  from .._fiff.tree import dir_tree_find
  from .._fiff.write import end_block, start_and_end_file, start_block, write_coord_trans, write_id, write_int, write_string
  from ..epochs import BaseEpochs
  from ..evoked import Evoked, EvokedArray
  from ..html_templates import _get_html_template
  from ..io import BaseRaw, RawArray
  from ..label import Label
  from ..source_estimate import _BaseSourceEstimate, _BaseVectorSourceEstimate
  from ..source_space._source_space import _get_src_nn, _read_source_spaces_from_tree, _set_source_space_vertices, _src_kind_dict, _write_source_spaces_to_fid, find_source_space_hemi
  from ..surface import _normal_orth
  from ..transforms import invert_transform, transform_surface_to, write_trans
  from ..utils import _check_compensation_grade, _check_fname, _check_option, _check_stc_units, _import_h5io_funcs, _on_missing, _stamp_to_dt, _validate_type, check_fname, fill_doc, get_subjects_dir, has_mne_c, logger, repr_html, run_subprocess, verbose, warn
label_desc: Use image node_id 9 for calling a global function with example usage: write_forward_solution(fname, fwd, overwrite, verbose) without return types