def _is_eligible_previous_execution( self, current_execution: metadata_store_pb2.Execution, target_execution: metadata_store_pb2.Execution) -> bool: """Compare if the previous execution is same as current execution. This method will ignore ID and time related fields. Args: current_execution: the current execution. target_execution: the previous execution to be compared with. Returns: whether the previous and current executions are the same. """ current_execution.properties['run_id'].string_value = '' target_execution.properties['run_id'].string_value = '' current_execution.id = target_execution.id # Skip comparing time sensitive fields. # The execution might not have the create_time_since_epoch or # create_time_since_epoch field if the execution is created by an old # version before this field is introduced. if hasattr(current_execution, 'create_time_since_epoch'): current_execution.ClearField('create_time_since_epoch') if hasattr(target_execution, 'create_time_since_epoch'): target_execution.ClearField('create_time_since_epoch') if hasattr(current_execution, 'last_update_time_since_epoch'): current_execution.ClearField('last_update_time_since_epoch') if hasattr(target_execution, 'last_update_time_since_epoch'): target_execution.ClearField('last_update_time_since_epoch') return current_execution == target_execution
def _is_eligible_previous_execution( self, currrent_execution: metadata_store_pb2.Execution, target_execution: metadata_store_pb2.Execution) -> bool: currrent_execution.properties['run_id'].string_value = '' target_execution.properties['run_id'].string_value = '' currrent_execution.id = target_execution.id return currrent_execution == target_execution
def put_execution( metadata_handler: metadata.Metadata, execution: metadata_store_pb2.Execution, contexts: Sequence[metadata_store_pb2.Context], input_artifacts: Optional[typing_utils.ArtifactMultiMap] = None, output_artifacts: Optional[typing_utils.ArtifactMultiMap] = None, input_event_type: metadata_store_pb2.Event.Type = metadata_store_pb2.Event. INPUT, output_event_type: metadata_store_pb2.Event.Type = metadata_store_pb2. Event.OUTPUT ) -> metadata_store_pb2.Execution: """Writes an execution-centric subgraph to MLMD. This function mainly leverages metadata.put_execution() method to write the execution centric subgraph to MLMD. Args: metadata_handler: A handler to access MLMD. execution: The execution to be written to MLMD. 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 with type input_event_type. Each artifact will also be linked with every context in the `contexts` argument. output_artifacts: Output artifacts of the execution. Each artifact will be linked with the execution through an event with type output_event_type. Each artifact will also be linked with every context in the `contexts` argument. input_event_type: The type of the input event, default to be INPUT. output_event_type: The type of the output event, default to be OUTPUT. Returns: An MLMD execution that is written to MLMD, with id pupulated. """ artifact_and_events = [] if input_artifacts: artifact_and_events.extend( _create_artifact_and_event_pairs(metadata_handler=metadata_handler, artifact_dict=input_artifacts, event_type=input_event_type)) if output_artifacts: artifact_and_events.extend( _create_artifact_and_event_pairs(metadata_handler=metadata_handler, artifact_dict=output_artifacts, event_type=output_event_type)) execution_id, artifact_ids, contexts_ids = ( metadata_handler.store.put_execution( execution=execution, artifact_and_events=artifact_and_events, contexts=contexts, reuse_context_if_already_exist=True)) execution.id = execution_id for artifact_and_event, a_id in zip(artifact_and_events, artifact_ids): artifact, _ = artifact_and_event artifact.id = a_id for context, c_id in zip(contexts, contexts_ids): context.id = c_id return execution