C1M3 Assignment - Cannot get 5.4 Exercise unit test to work

Hello,

I have problems with the assignment " Programming Assignment: Implementing algorithms in Graphs" for the course " Introduction to Generative AI for Software Development"

When I run this sentence unittests.test_shortest_path(Graph_Advanced) I got this error

Process shortest_path:
Traceback (most recent call last):
File “/opt/conda/lib/python3.11/multiprocessing/process.py”, line 314, in _bootstrap
self.run()
File “/opt/conda/lib/python3.11/multiprocessing/process.py”, line 108, in run
self._target(*self._args, **self._kwargs)
File “/home/jovyan/work/unittests.py”, line 33, in helper
out = func(*arg)
^^^^^^^^^^
File “/tmp/ipykernel_16506/336599966.py”, line 36, in shortest_path
distances = {vertex: float(‘infinity’) for vertex in self.vertices}
^^^^^^^^^^^^^
AttributeError: ‘Graph_Advanced’ object has no attribute ‘vertices’


When I try to run it local I get this error,
AttributeError: Can’t pickle local object ‘test_shortest_path..g..helper’.
How to fix that?

Thank you in advance!

Are you trying to run the lab on your local machine? You need to rpelicate the environment n Coursera and the same version of the used libraries.

For this error in the init method, do you have a vertices parameter?

Thank you for the answer.
I added def init(self, vertices=None), and the problems were fixed.

  1. But now, when I run this test, I get this error:
    unittests.test_shortest_path(Graph_Advanced)

I got this error:
Process shortest_path:
Traceback (most recent call last):
File “/opt/conda/lib/python3.11/multiprocessing/process.py”, line 314, in _bootstrap
self.run()
File “/opt/conda/lib/python3.11/multiprocessing/process.py”, line 108, in run
self._target(*self._args, **self._kwargs)
File “/home/jovyan/work/unittests.py”, line 33, in helper
out = func(*arg)
^^^^^^^^^^
File “/tmp/ipykernel_3127/4008524446.py”, line 43, in shortest_path
raise ValueError(f"Start vertex {start_vertex} is not present in the graph")
ValueError: Start vertex 654 is not present in the graph

  1. Where can I find the four methods of the Graph_Advanced class used in the exercise? I want to validate that I haven’t changed the signature of any methods.

3.Are you trying to run the lab on your local machine? You need to replicate the environment from Coursera and ensure the same version of the libraries is used.
Where can I find the version of the libraries you are using to replicate the environment?

Thank you in advance.

It’s better to delete what you have as files and perform a “Get Latest Version” to get clean copies of the notebooks (on the right-hand corner of the lab).

Check all the related files on File->Open or on the right hand side and the libraries used there!

1 Like

Thank you for your help

1 Like