code: def register_execution(
      metadata_handle: metadata.Metadata,
      execution_type: metadata_store_pb2.ExecutionType,
      contexts: Sequence[metadata_store_pb2.Context],
      input_artifacts: Optional[typing_utils.ArtifactMultiMap] = None,
      exec_properties: Optional[
          Mapping[str, types.ExecPropertyTypes]
      ] = None,
      last_known_state: metadata_store_pb2.Execution.State = metadata_store_pb2.Execution.RUNNING,
  ) -> metadata_store_pb2.Execution:
      """Registers a new execution in MLMD.
  
      Along with the execution:
      -  the input artifacts will be linked to the execution.
      -  the contexts will be linked to both the execution and its input artifacts.
  
      Args:
        metadata_handle: A handler to access MLMD.
        execution_type: The type of the execution.
        contexts: MLMD contexts to associated with the execution.
        input_artifacts: Input artifacts of the execution. Each artifact will be
          linked with the execution through an event.
        exec_properties: Execution properties. Will be attached to the execution.
        last_known_state: The last known state of the execution.
  
      Returns:
        An MLMD execution that is registered in MLMD, with id populated.
      """
      # Setting exec_name is required to make sure that only one execution is
      # registered in MLMD. If there is a RPC retry, AlreadyExistError will raise.
      # After this fix (b/221103319), AlreadyExistError may not raise. Instead,
      # execution may be updated again upon RPC retries.
      exec_name = str(uuid.uuid4())
      execution = execution_lib.prepare_execution(
          metadata_handle,
          execution_type,
          last_known_state,
          exec_properties,
          execution_name=exec_name,
      )
  
      return execution_lib.put_execution(
          metadata_handle,
          execution,
          contexts,
          input_artifacts=input_artifacts,
      )
  
file_path: tfx/tfx/orchestration/portable/execution_publish_utils.py
imports: from typing import Mapping, Optional, Sequence
  import uuid
  from tfx import types
  from tfx.orchestration import data_types_utils
  from tfx.orchestration import metadata
  from tfx.orchestration.portable import merge_utils
  from tfx.orchestration.portable import outputs_utils
  from tfx.orchestration.portable.mlmd import execution_lib
  from tfx.proto.orchestration import execution_result_pb2
  from tfx.utils import typing_utils
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 6 for calling a global function with example usage: register_execution(metadata_handle, execution_type, contexts, input_artifacts, exec_properties, last_known_state) and returns: execution_lib