code: def _artifacts_to_garbage_collect(
      mlmd_handle: metadata.Metadata,
      artifacts: Sequence[metadata_store_pb2.Artifact],
      events: Sequence[metadata_store_pb2.Event],
      policy: garbage_collection_policy_pb2.GarbageCollectionPolicy,
  ) -> Sequence[metadata_store_pb2.Artifact]:
      """Returns artifacts that should be garbage collected."""
      result = artifacts
      result = _artifacts_to_garbage_collect_for_policy(result, policy)
      result = garbage_collection_extensions.artifacts_not_in_use_in_pipeline_groups(
          mlmd_handle, policy.keep_if_used_in_pipeline_groups, result
      )
      result = _artifacts_not_in_use(mlmd_handle, result, events)
      return result
  
imports: import collections
  import itertools
  from typing import Mapping, Optional, Sequence
  from absl import logging
  from tfx import types
  from tfx.dsl.io import fileio
  from tfx.orchestration import data_types_utils
  from tfx.orchestration import metadata
  from tfx.orchestration import node_proto_view
  from tfx.orchestration.experimental.core import task
  from tfx.orchestration.portable.mlmd import event_lib
  from tfx.orchestration.portable.mlmd import execution_lib
  from tfx.orchestration.portable.mlmd import store_ext
  from tfx.proto.orchestration import garbage_collection_policy_pb2
  from tfx.orchestration.experimental.core import garbage_collection_extensions
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 8 for calling a global function with example usage: _artifacts_to_garbage_collect(mlmd_handle, artifacts, events, policy) and returns: result