code: def _artifacts_not_in_use(
      mlmd_handle: metadata.Metadata,
      artifacts: Sequence[metadata_store_pb2.Artifact],
      events: Sequence[metadata_store_pb2.Event],
  ) -> Sequence[metadata_store_pb2.Artifact]:
      """Returns artifacts that are not currently in use."""
      artifact_ids = set(a.id for a in artifacts)
      input_events = [
          e
          for e in events
          if e.artifact_id in artifact_ids
          and event_lib.is_valid_input_event(e)
      ]
      execution_ids = [e.execution_id for e in input_events]
      if not execution_ids:
          return artifacts
      executions = mlmd_handle.store.get_executions_by_id(execution_ids)
      execution_id_to_execution = {e.id: e for e in executions}
      in_use_artifact_ids = set()
      for event in input_events:
          if event.execution_id not in execution_id_to_execution:
              raise RuntimeError(
                  "Could not find execution with id: %d"
                  % event.execution_id
              )
          execution = execution_id_to_execution[event.execution_id]
          if execution_lib.is_execution_active(execution):
              in_use_artifact_ids.add(event.artifact_id)
      return [a for a in artifacts if a.id not in in_use_artifact_ids]
  
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 3 for calling a global function with example usage: _artifacts_not_in_use(mlmd_handle, artifacts, events) and returns: unknown, artifacts