class_docstr: Helper class to handle metadata I/O.
  
  Not thread-safe without external synchronisation.
docstr: Creates a list of [Artifact, [Optional]Event] tuples.
  
  The result of this function will be used in a MLMD put_execution() call. The
  artifacts will be linked to certain contexts. If an artifact is attached
  with an event, it will be linked with the execution through the event
  created.
  
  When the id of an artifact is in the registered_artifacts_ids, no event is
  attached to it. Otherwise, an event with given type will be attached to the
  artifact.
  
  Args:
    artifact_dict: the source of artifacts to work on. For each artifact in
      the dict, creates a tuple for that
    event_type: the event type of the event to be attached to the artifact
    new_state: new state of the artifacts
    registered_artifacts_ids: artifact ids to bypass event creation since they
      are regarded already registered
  
  Returns:
    A list of [Artifact, [Optional]Event] tuples
docstr_tok: ["Creates","a","list","of","[","Artifact",",","[","Optional","]","Event","]","tuples",".","The","result","of","this","function","will","be","used","in","a","MLMD","put_execution","(",")","call",".","The","artifacts","will","be","linked","to","certain","contexts",".","If","an","artifact","is","attached","with","an","event",",","it","will","be","linked","with","the","execution","through","the","event","created",".","When","the","id","of","an","artifact","is","in","the","registered_artifacts_ids",",","no","event","is","attached","to","it",".","Otherwise",",","an","event","with","given","type","will","be","attached","to","the","artifact",".","Args",":","artifact_dict",":","the","source","of","artifacts","to","work","on",".","For","each","artifact","in","the","dict",",","creates","a","tuple","for","that","event_type",":","the","event","type","of","the","event","to","be","attached","to","the","artifact","new_state",":","new","state","of","the","artifacts","registered_artifacts_ids",":","artifact","ids","to","bypass","event","creation","since","they","are","regarded","already","registered","Returns",":","A","list","of","[","Artifact",",","[","Optional","]","Event","]","tuples"]
code: def _artifact_and_event_pairs(
      self,
      artifact_dict: Dict[str, List[_Artifact]],
      event_type: metadata_store_pb2.Event.Type,
      new_state: Optional[str] = None,
      registered_artifacts_ids: Optional[Set[int]] = None,
  ) -> List[
      Tuple[
          metadata_store_pb2.Artifact,
          Optional[metadata_store_pb2.Event],
      ]
  ]:
      """Creates a list of [Artifact, [Optional]Event] tuples.
  
      The result of this function will be used in a MLMD put_execution() call. The
      artifacts will be linked to certain contexts. If an artifact is attached
      with an event, it will be linked with the execution through the event
      created.
  
      When the id of an artifact is in the registered_artifacts_ids, no event is
      attached to it. Otherwise, an event with given type will be attached to the
      artifact.
  
      Args:
        artifact_dict: the source of artifacts to work on. For each artifact in
          the dict, creates a tuple for that
        event_type: the event type of the event to be attached to the artifact
        new_state: new state of the artifacts
        registered_artifacts_ids: artifact ids to bypass event creation since they
          are regarded already registered
  
      Returns:
        A list of [Artifact, [Optional]Event] tuples
      """
      registered_artifacts_ids = registered_artifacts_ids or {}
      result = []
      for key, a_list in artifact_dict.items():
          for index, a in enumerate(a_list):
              if new_state:
                  a.state = new_state
              if a.id and a.id in registered_artifacts_ids:
                  result.append(tuple([a.mlmd_artifact]))
              else:
                  a.set_mlmd_artifact_type(
                      self._prepare_artifact_type(a.artifact_type)
                  )
                  result.append(
                      (
                          a.mlmd_artifact,
                          self._prepare_event(
                              event_type=event_type,
                              key=key,
                              index=index,
                          ),
                      )
                  )
      return result
  
imports: import collections
  import copy
  import hashlib
  import itertools
  import os
  import random
  import time
  import types
  from typing import Any, Dict, List, Optional, Set, Tuple, Type, Union
  import absl
  from tfx.dsl.io import fileio
  from tfx.orchestration import data_types
  from tfx.orchestration.portable.mlmd import event_lib
  from tfx.types import artifact
  from tfx.types import artifact_utils
  import ml_metadata
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 18 for calling the Metadata obj's underlying member method code with example usage: obj._artifact_and_event_pairs(artifact_dict, event_type, new_state, registered_artifacts_ids) and returns: result