code: def _create_artifact_and_event_pairs(
      metadata_handle: metadata.Metadata,
      artifact_dict: typing_utils.ArtifactMultiMap,
      event_type: metadata_store_pb2.Event.Type,
  ) -> List[
      Tuple[metadata_store_pb2.Artifact, metadata_store_pb2.Event]
  ]:
      """Creates a list of [Artifact, Event] tuples.
  
      The result of this function will be used in a MLMD put_execution() call.
  
      Args:
        metadata_handle: A handler to access MLMD store.
        artifact_dict: The source of artifacts to work on. For each unique artifact
          in the dict, creates a tuple for that. Note that all artifacts of the same
          key in the artifact_dict are expected to share the same artifact type. If
          the same artifact is used for multiple keys, several event paths will be
          generated for the same event.
        event_type: The event type of the event to be attached to the artifact
  
      Returns:
        A list of [Artifact, Event] tuples
      """
      if not artifact_dict:
          return []
  
      result = []
      artifact_event_map = dict()
      for key, artifact_list in artifact_dict.items():
          artifact_type = None
          for index, artifact in enumerate(artifact_list):
              artifact_id = _get_id(artifact.mlmd_artifact)
              if artifact_id and artifact_id in artifact_event_map:
                  event_lib.add_event_path(
                      artifact_event_map[artifact_id][1],
                      key=key,
                      index=index,
                  )
              else:
                  event = event_lib.generate_event(
                      event_type=event_type, key=key, index=index
                  )
                  # Reuses already registered type in the same list whenever possible as
                  # the artifacts in the same list share the same artifact type.
                  if artifact_type:
                      assert (
                          artifact_type.name
                          == artifact.artifact_type.name
                      ), "Artifacts under the same key should share the same artifact type."
                  else:
                      artifact_type = (
                          common_utils.register_type_if_not_exist(
                              metadata_handle, artifact.artifact_type
                          )
                      )
                  artifact.set_mlmd_artifact_type(artifact_type)
                  if artifact_id:
                      artifact_event_map[artifact_id] = (
                          artifact.mlmd_artifact,
                          event,
                      )
                  else:
                      result.append((artifact.mlmd_artifact, event))
      result.extend(list(artifact_event_map.values()))
      return result
  
imports: from __future__ import annotations
  import collections
  import copy
  import itertools
  import re
  from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Tuple
  from absl import logging
  from tfx import types
  from tfx.orchestration import data_types_utils
  from tfx.orchestration import metadata
  from tfx.orchestration.portable import outputs_utils
  from tfx.orchestration.portable.mlmd import artifact_lib
  from tfx.orchestration.portable.mlmd import common_utils
  from tfx.orchestration.portable.mlmd import event_lib
  from tfx.orchestration.portable.mlmd import filter_query_builder
  from tfx.utils import metrics_utils
  from tfx.proto.orchestration import execution_result_pb2
  from tfx.proto.orchestration import pipeline_pb2
  from tfx.utils import proto_utils
  from tfx.utils import typing_utils
  from tfx.utils import telemetry_utils
  from google.protobuf import json_format
  import ml_metadata
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 13 for calling a global function with example usage: _create_artifact_and_event_pairs(metadata_handle, artifact_dict, event_type) and returns: result, list