code: def collect_rev(
      repo: "Repo",
      rev: str,
      param_deps: bool = False,
      force: bool = False,
      cache: Optional["ExpCache"] = None,
      **kwargs,
  ) -> ExpState:
      """Collect experiment state for the given revision.
  
      Exp will be loaded from cache when available unless rev is 'workspace' or
      force is set.
      """
      from dvc.fs import LocalFileSystem
  
      cache = cache or repo.experiments.cache
      assert cache
      # TODO: support filtering serialized exp when param_deps is set
      if rev != "workspace" and not (force or param_deps):
          cached_exp = cache.get(rev)
          if cached_exp:
              if isinstance(cached_exp, SerializableError):
                  return ExpState(rev=rev, error=cached_exp)
              return ExpState(rev=rev, data=cached_exp)
      if rev == "workspace" and isinstance(repo.fs, LocalFileSystem):
          orig_cwd: Optional[str] = os.getcwd()
          os.chdir(repo.root_dir)
      else:
          orig_cwd = None
      try:
          data = _collect_rev(
              repo,
              rev,
              param_deps=param_deps,
              force=force,
              **kwargs,
          )
          if not (
              rev == "workspace" or param_deps or data.contains_error
          ):
              cache.put(data, force=True)
          return ExpState(rev=rev, data=data)
      except Exception as exc:  # noqa: BLE001
          logger.debug("", exc_info=True)
          error = SerializableError(str(exc), type(exc).__name__)
          return ExpState(rev=rev, error=error)
      finally:
          if orig_cwd:
              os.chdir(orig_cwd)
  
imports: import itertools
  import os
  from dataclasses import fields
  from datetime import datetime
  from typing import TYPE_CHECKING, Collection, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  from funcy import first
  from scmrepo.exceptions import SCMError
  from dvc.log import logger
  from dvc.scm import Git, SCMError, iter_revs
  from .exceptions import InvalidExpRefError
  from .refs import EXEC_BRANCH, ExpRefInfo
  from .serialize import ExpRange, ExpState, SerializableError, SerializableExp
  from .utils import describe
label_desc: Use image node_id 1 for calling a global function with example usage: collect_rev(repo, rev, param_deps, force, cache) and returns: ExpState, ExpState, ExpState, ExpState