C1W3: Weird behavior of Grader: Failed test case: Exception during compute_cost test: name 'math' is not defined

I have clearly imported math in the first cell of my Jupyter notebook (refer screenshot). Later in the notebook I call math.log. This works fine when running the notebook. However, once I save and submit the notebook to the grader, it errors out on the cells which use math.log with the error:

Failed test case: Exception during compute_cost test: name 'math' is not defined.

I fixed it by importing math in that specific cell, and that makes the grader stop complaining, but it’s odd that the initial import of math didn’t work.

Interestingly, the same failure occurs on two cells, but importing math in just one cell (i.e. the one for exercise 2) fixed the problem in the next exercise too.

I made sure to run my entire notebook and save it before submitting.

Anyway since my problem is solved, I’m good, but the DL.ai staff might want to take a look at this error.

Has anyone else seen this?

The grader doesn’t use your whole notebook.
It only extracts the graded cells, and then runs your code in a separate environment.

The grader does not expect you to use the math library. So it does not import it.

Try changing your solution so it doesn’t use math.log.

Hint: The assignment expects you to use numpy.

I fixed it by importing math in that specific cell,

Please do not do this.

For the future I’ll remember to not import libraries other than what’s specified in the notebook, but it might be good to specify that - in giant letters - in the notebook too.