C2_W3_Assignment Exercise 12: Get parent artifacts Error

@Chris

Exercise 1-11 have good results with no errors, exercise 12 with errors, but all 12 exercises scored 0/10.

Exercise 12: Get parent artifacts

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 (
  artifact_id_events.event.execution_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(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
)

# 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

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

in get_parent_artifacts(store, artifact)
7
8 # Get events associated with the artifact id
----> 9 artifact_id_events = store.get_events_by_artifact_ids(artifact_id)
10
11 # From the artifact_id_events, get the execution ids of OUTPUT events.

/opt/conda/lib/python3.8/site-packages/ml_metadata/metadata_store/metadata_store.py in get_events_by_artifact_ids(self, artifact_ids)
1129
1130 request = metadata_store_service_pb2.GetEventsByArtifactIDsRequest()
→ 1131 for x in artifact_ids:
1132 request.artifact_ids.append(x)
1133 response = metadata_store_service_pb2.GetEventsByArtifactIDsResponse()

TypeError: ‘int’ object is not iterable

Hi! The traceback is pointing to here:

artifact_id_events = store.get_events_by_artifact_ids(artifact_id)

And it’s saying that int is not iterable. You may want to cast the artifact id as a list so the function can iterate over it.

The grader will halt if your notebook is throwing an error. If you want it to grade your other 11 exercises, you can comment exercise 12 and the test code. The important part is if you run the entire notebook, there is no cell that will throw an error.

Hope this helps!

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
    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(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
)

# Get the list of artifacts associated with the parent_artifact_ids
parent_artifact_list = store.get_events_by_artifact_ids(parent_artifact_ids)

### END CODE HERE ###

return parent_artifact_list

AttributeError Traceback (most recent call last)
in
6
7 # Display the results
----> 8 display_artifacts(store, parent_artifacts, base_dir)

~/work/util.py in display_artifacts(store, artifacts, base_dir)
45 table = {‘artifact id’: , ‘type’: , ‘uri’: }
46 for a in artifacts:
—> 47 table[‘artifact id’].append(a.id)
48 artifact_type = store.get_artifact_types_by_id([a.type_id])[0]
49 table[‘type’].append(artifact_type.name)

AttributeError: id

I solved this - thanks.

@amitpphatak - How did you solve it? I have the same problem

Without giving out the answer - need to use a different method. We get this error because the method used is incorrect.

2 Likes