C2W3_Assignment - Output Error

Hello everybody,

I am getting errors:

def get_parent_artifacts(store, artifact):

    ### START CODE HERE ###
    
    # Get the artifact id of the input artifact
    artifact_id = artifact.id

    # Get events associated with the artifact id
    artifact_id_events = store.get_events_by_artifact_ids([artifact_id])

    # From the `artifact_id_events`, get the execution ids of OUTPUT events.
    # Cast to a set to remove duplicates if any.
    executions_id = set (
      event.artifact_id
      for event in artifact_id_events
      if event.type == metadata_store_pb2.Event.OUTPUT
    )


    # Get the events associated with the execution_id
    execution_id_events = store.get_events_by_execution_ids([executions_id])

    # From execution_id_events, get the artifact ids of INPUT events.
    # Cast to a set to remove duplicates if any.
    parent_artifact_ids = set ( 
        event.artifact_id
        for event in execution_id_events
        if event.type == metadata_store_pb2.Event.INPUT
    )

    # Get the list of artifacts associated with the parent_artifact_ids
    parent_artifact_list = store.get_artifacts_by_id(list[parent_artifact_ids])

    ### END CODE HERE ###
    
    return parent_artifact_list

Please help me, I don’t understand why getting errors.

Hello @LinhVO ,

Thanks for your question.
It looks to me that there is a mistake in the executions_id = … section of your code. Remember you have to get the execution ids of OUTPUT events.
Hopefully this helps you to find the solution and if you need more help , pls let me know.

After solving the problem, could you please remove the code snippet from your question above? This is because we should avoid posting code solutions in the forums to respect the Honour Code.

Thanks and best of luck!

Maarten

1 Like

Hi @mjsmid,

I am also struggling with this, this is my code for getting the execution ids:


    # Get the artifact id of the input artifact
    artifact_id = artifact.id

    # Get events associated with the artifact id
    artifact_id_events = store.get_events_by_artifact_ids([artifact_id])
    
    # From the `artifact_id_events`, get the execution ids of OUTPUT events.
    # Cast to a set to remove duplicates if any.
 
    execution_id = set( 
        event.execution_id
        for event in artifact_id_events
        if event.type == metadata_store_pb2.Event.OUTPUT
    )

which gives me a resulting execution_id set of:

print(execution_id)
{14}

I receive the same error as OP. I believe I am getting the correct events as I checked this:

artifact_id_events = store.get_events_by_artifact_ids([artifact_id])
print(artifact_id_events)
[artifact_id: 12 
execution_id: 14 <-----
path {
  steps {
    key: "transform_graph"
  }
  steps {
    index: 0
  }
}
type: OUTPUT <----
milliseconds_since_epoch: 1645063929167
]

Here is my error output:

**---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-125-3e08721051e9> in <module>
      3 
      4 # Retrieve the parent artifacts of the instance
----> 5 parent_artifacts = get_parent_artifacts(store, artifact_instance)
      6 
      7 # Display the results

<ipython-input-124-ad7639b6870b> in get_parent_artifacts(store, artifact)
     24 
     25     # Get the events associated with the execution_id
---> 26     execution_id_events = store.get_events_by_execution_ids([execution_id])
     27 
     28     # From execution_id_events, get the artifact ids of INPUT events.

/opt/conda/lib/python3.8/site-packages/ml_metadata/metadata_store/metadata_store.py in get_events_by_execution_ids(self, execution_ids)
   1412     request = metadata_store_service_pb2.GetEventsByExecutionIDsRequest()
   1413     for x in execution_ids:
-> 1414       request.execution_ids.append(x)
   1415     response = metadata_store_service_pb2.GetEventsByExecutionIDsResponse()
   1416 

TypeError: {14} has type set, but expected one of: int, long**

Hi @CooperWhite ,

The error message displays a TypeError of the execution_id’s; TypeError: {14} has type set, but expected one of: int, long**
In your definition of the execution_id_events you are providing a list of the set you defined previously but the individual elements handled by the method get_events_by_execution_ids need to be numbers instead of sets, so please have a look at how you define the arguments in the execution_id_events definition.

Hopefully this helps you to find the answer. If you need more info, pls let me know.

BR
maarten