Week 3 Assignment - unittests.test_tsp_small_graph(GraphTSPSmallGraph)

I have implemented the assignment as required, and when I execute it locally in my own IDE, all works correctly, and I get the correct results including the expected distance values of 799, 893, 978, 776 and 1394.

However, when I execute the “unittests.test_tsp_small_graph(GraphTSPSmallGraph)” I get the following:
Failed test case: Failed to find the optimal solution for a path starting in node 0. To replicate the graph, you may run generate_graph(graph = GraphTSPSmallGraph, nodes = 10, complete = True, seed = 42).
Expected: 799
Got: 1255

Failed test case: Failed to find the optimal solution for a path starting in node 0. To replicate the graph, you may run generate_graph(graph = GraphTSPSmallGraph, nodes = 10, complete = True, seed = 43).
Expected: 893
Got: 1255

Failed test case: Failed to find the optimal solution for a path starting in node 0. To replicate the graph, you may run generate_graph(graph = GraphTSPSmallGraph, nodes = 10, complete = True, seed = 44).
Expected: 978
Got: 1255

Failed test case: Failed to find the optimal solution for a path starting in node 0. To replicate the graph, you may run generate_graph(graph = GraphTSPSmallGraph, nodes = 10, complete = True, seed = 45).
Expected: 776
Got: 1255

Failed test case: Failed to find the optimal solution for a path starting in node 0. To replicate the graph, you may run generate_graph(graph = GraphTSPSmallGraph, nodes = 10, complete = True, seed = 46).
Expected: 1394
Got: 1255

I have restarted the kernel multiple times to no effect.
I have also noticed that when I try to just run the code, without for instance the example usage in Section 3.2, I get an error saying graph is not defined, which to me seems to be a bad smell.
Is there a problem in the notebook or am I doing something wrong?
Something else I also n

I can not advice on running locally, but perhaps maybe either your solution is wrong or even maybe you are missing some helper file from the Lab folder, make sure that you download all the files in the Lab folder when you run the Lab locally.

You can always ask the LLM what guidance can it offer about the error as well.

Good morning,
The problem is that when it is run in the course notebook environment, those errors happen.
The code is correct, and when I execute it locally, the correct results show up.
So the issue is with the course environment.
And what looks wrong about it is that it is stating that each test it runs comes back with the exact same result of 1255.
Furthermore, when I add in a print statement to print out the graph under test, it is the exact same graph that is being passed to each test, which is not what I would have expected?
In summary, this points to there being an issue with the test code “unittests.test_tsp_small_graph(GraphTSPSmallGraph)”.

So below I have the summary of the results of the tests, as run on the coursera notebook remotely, giving what it outputs in the logs for each test.
seed - the value passed in when generating the graph for the tests
Expected: the results the test expected to get
Got: the result the test said it got, which is incorrect and doesn’t make sense
Result I got: the result I got when I ran the test locally, which matches the Expected: value above.

First test:
seed = 42
Expected: 799
Got: 1255
Result I got:799

Second test:
seed = 43
Expected: 893
Got: 1255
Result I got:893

Third test:
seed = 44
Expected: 978
Got: 1255
Result I got:978

Fourth test:
seed = 45
Expected: 776
Got: 1255
Result I got:776

Fifth test:
seed = 46
Expected:1394
Got: 1255
Result I got:1394

Right, the grader uses different tests from the unit tests!
Failed test case: Failed to find the optimal solution for a path starting in node 0. To replicate the graph, you may run generate_graph(graph = GraphTSPSmallGraph, nodes = 10, complete = True, seed = 46).

It is probable that your solution is not right, refer to this post for advice on how to proceed further at this point:

But that is exactly what I’m doing to generate the graph, and it looks to me that it it the same graph being used each time for the unit tests.
So the solution is moire than likely correct, and the unites code is incorrect - why is the unittst re-using the exact same graph for each test?

I don’t understand what you mean but as a mentor I advise you to seek with the help of the LLM another solution to the exercise, you may need though to reset the Lab notebook if you have done changes in it that alter cells outside the exercises.

I think the advice given on the referenced link is valid for your issue too.