Exercise 12: Get parent artifacts

I need some hints regarding this exercise.
I get zero rows in the output.

In the function get_parent_artifacts, the execution_id={7}
and parent_artifact_ids is empty set.

Hi! We have updated the boilerplate code for this exercise. Please reopen the notebook from the Coursera classroom to see the update. Take note though that you will need to copy the solutions from the old notebook to the new one so it can be properly graded.

As for hints, the code there will look similar to the one used to get the parent_artifact_ids. You will just need to be mindful of the properties and event types. Hope this helps!

I get the same result.
This is my code:

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.
execution_id = set( 
    event.execution_id
    for event in artifact_id_events # @REPLACE
    if event.type == metadata_store_pb2.Event.OUTPUT # @REPLACE
)

# Get the events associated with the execution_id
execution_id_events = store.get_executions_by_id(execution_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
)

print(parent_artifact_ids)

# Get the list of artifacts associated with the parent_artifact_ids
parent_artifact_list = parent_artifact_ids

### END CODE HERE ###

return parent_artifact_list

Output:
set()

artifact id type uri

Hi! You’re almost there! Take note that parent_artifact_ids are just IDs. What you want to collect in the last line are the artifact objects. With that, you will need to get the artifacts that are associated with those IDs from the metadata store. You can use a list comprehension to put all artifacts (with the parent artifact ids) you got from the store into a list. The ungraded lab before this assignment will tell you what method to use to get artifacts from the store based on IDs.

If you’ve figured it out, kindly remove your code from this post to give other learners a chance to figure out the solution by themselves. Learning works best that way! Thank you!

1 Like

@chris.favila

Thanks for your above reply. I am having issues submitting exercise 12 for grading. Specifically, the issue originates from the display_artifacts(store, parent_artifacts, base_dir) function imported from the util module. The above function looks for the id key, but the parent_artifacts list only has elements with the artifact_id key instead of id.

Hi Teja! Please check your code carefully. You are collecting Events instead of Artifacts. Artifacts will have an id property while events have artifact_id.

2 Likes

Thank you @chris.favila. That solved my issue!

1 Like

It’s a little confusing because the tip mentions we will need get_events_by_artifact_ids() and get_events_by_execution_ids(), but doesn’t mention the method we have to use to get the artifacts.