code: def persist_artifacts(work: "LightningWork") -> None:
      """Copies all :class:`~lightning.app.storage.path.Path` referenced by the given LightningWork to the shared
      storage.
  
      Files that don't exist or do not originate from the given Work will be skipped.
  
      """
      artifact_paths = [getattr(work, name) for name in work._paths]
      # only copy files that belong to this Work, i.e., when the path's origin refers to the current Work
      artifact_paths = [
          path
          for path in artifact_paths
          if isinstance(path, Path) and path.origin_name == work.name
      ]
  
      for name in work._state:
          if isinstance(getattr(work, name), Payload):
              artifact_path = pathlib.Path(name).resolve()
              payload = getattr(work, name)
              payload.save(payload.value, artifact_path)
              artifact_paths.append(artifact_path)
  
      missing_artifacts: Set[str] = set()
      destination_paths = []
      for artifact_path in artifact_paths:
          artifact_path = pathlib.Path(artifact_path).absolute()
          if not artifact_path.exists():
              missing_artifacts.add(str(artifact_path))
              continue
          destination_path = _path_to_work_artifact(artifact_path, work)
          _copy_files(artifact_path, destination_path)
          destination_paths.append(destination_path)
  
      if missing_artifacts:
          warnings.warn(
              f"{len(missing_artifacts)} artifacts could not be saved because they don't exist:"
              f" {','.join(missing_artifacts)}.",
              UserWarning,
          )
      else:
          logger.debug(
              f"All {destination_paths} artifacts from Work {work.name} successfully "
              "stored at {artifacts_path(work.name)}."
          )
  
imports: import os
  import pathlib
  import queue
  import signal
  import sys
  import threading
  import time
  import traceback
  import warnings
  from contextlib import contextmanager
  from copy import deepcopy
  from dataclasses import dataclass, field
  from functools import partial
  from threading import Event, Thread
  from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, Optional, Set, Tuple, Type, Union
  from deepdiff import DeepDiff, Delta
  from lightning_utilities.core.apply_func import apply_to_collection
  from lightning.app.core import constants
  from lightning.app.core.queues import MultiProcessQueue
  from lightning.app.storage.copier import _Copier, _copy_files
  from lightning.app.storage.drive import Drive, _maybe_create_drive
  from lightning.app.storage.path import Path, _path_to_work_artifact
  from lightning.app.storage.payload import Payload
  from lightning.app.utilities.app_helpers import affiliation
  from lightning.app.utilities.component import _set_work_context
  from lightning.app.utilities.enum import CacheCallsKeys, WorkFailureReasons, WorkStageStatus, WorkStopReasons, make_status
  from lightning.app.utilities.exceptions import CacheMissException, LightningSigtermStateException
  from lightning.app.utilities.app_helpers import Logger
label_desc: Use image node_id 3 for calling a global function with example usage: persist_artifacts(work) without return types