Programming assignment: reinforcement learning

Hello All,
I am Sesa,
I am stuck on the programming assignment the code is correct, however when I submit I fail.
Exercise 2 code:

(staff edit: removed code)

Hi Sesa, and welcome to the Forum! To follow the guidelines here, please post the error messages you’re getting instead of sharing your solution. A mentor will reach out in chase they need more info. Thank you!

2 Likes

Code Cell UNQ_C2 failed: compute_loss test 1 failed
If you see many functions being marked as incorrect, try to trace back your steps & identify if there is an incorrect function that is being used in other steps.
This dependency may be the cause of the errors.

Hi Sesa,
The most common reason for a grader test failing is because there is something wrong in your code. The grader uses different tests, so it’s possible to fail a grader test even if all the tests in the assignment notebook passed.

Sometimes, though, something can cause the grader to hiccup. So, if you feel like you’ve checked everything and see nothing wrong with your code, you can try:

1). Choose Kernel/Restart and Clear Output, and then submit again. This will clear out any extra garbage lying around from when you were running and testing your notebook. Sometimes, if the size gets too large it can cause a problem for the grader.

If that doesn’t work, you can try:

2). Get a fresh copy of the assignment and start over. This will help if there was some kind of inadvertent change in the notebook that is confusing the grader. To get a fresh copy, you will need to first delete or rename your current assignment file. Then, click on the help icon (question mark in a circle in the upper right corner) and choose “Get latest version”

2 Likes

Hi Wendy, I have tried all you said, however now it’s giving my first code an error I know for sure I did it right. Please see error below:
Cell #UNQ_C1. Can’t compile the student’s code. Error: VariableNotFoundError(‘Variable optimizer not found in Code Cell UNQ_C1. Please make sure you have not altered the cell positions from the original exercise question.’)
Traceback (most recent call last):
File “/home/www/app/grading/exceptions.py”, line 112, in handle_solution_errors
yield {}
File “/home/www/app/grading/abstract.py”, line 410, in _grade
output=output,
File “/home/www/app/grading/graders.py”, line 365, in call
variable_value, is_passed = self._validate(context)
File “/home/www/app/grading/graders.py”, line 344, in _validate
f’Variable {self.variable} not found in Code Cell ’
grading.exceptions.VariableNotFoundError: Variable optimizer not found in Code Cell UNQ_C1. Please make sure you have not altered the cell positions from the original exercise question.

Hi @Sesa2, thanks for trying those things. It now sounds like you have a new issue. The grader is looking in the cell that starts with the line: # UNQ_C1
and is trying to locate the variable ‘optimizer’, which it can’t find.

Please look carefully at your #UNQ_C1 cell, and look for a line that starts with
optimizer =

Make sure optimizer is spelled properly and make sure you don’t see anything else unusual in that cell.

If it all looks fine, try running everything up to and including that cell and the tests in the next cell to make sure it works fine for you. If you still can’t see anything, and it is still getting the same error in the grader, please DM me a copy of your .ipynb file and I’ll take a look.

1 Like

If you are still having issues after Wendy’s advice, it may be better to reset the notebook at the top right hand corner on the question mark, then “Get Latest Version”, but rename or delete the current one. And then try again.

First Exercise is all good now.

I am getting this error again when I submit: Code Cell UNQ_C2 failed: compute_loss test 1 failed
If you see many functions being marked as incorrect, try to trace back your steps & identify if there is an incorrect function that is being used in other steps.
This dependency may be the cause of the errors.

Can I please send my code to you or Wendy because I got the latest version but it still didn’t work. And in the notebook it says I’ve passed

Note that the grader uses different tests. Passing the tests in notebook is not enough.

1 Like

Yes, Sesa, DM me a copy of your .ipynb and I’ll take a look

Hi, All,

  I'm encountering the same error "Code Cell UNQ_C2 failed: compute_loss test 1 failed "  when I submit the assignment, please help me have a look and how can I pass the assignment, thanks ! 

```python

< Code removed by mentor >

Please do not share your code on the forum. That’s not allowed by the Code of Conduct.

Just posting your error messages or asserts is usually sufficient to identify the issue.

@songsong0906,

I will remove your code above since it is against the Code of Conduct to share on the forum, but as far as I can see, the code in the ### START CODE HERE ### and ### END CODE HERE ### sections for the function compute_loss() look fine.

The grader could be failing on that function due to something earlier in the assignment. It’s very important that you make no changes outside of the ### START CODE HERE ### and ### END CODE HERE ### sections.

Please try the suggestions I gave Sesa above for restarting the kernel and starting from a fresh copy. If you are still stuck after trying those steps, you can DM me a copy of your .ipynb file and I’ll take a look.

Follow-up for anyone who runs into this issue in the future:

Please remember, you should never have to add anything outside of the ### START CODE HERE ###, ### END CODE HERE ### sections. If you add your code to those sections, and then get an error in the unit tests, look at the error message and see what you can change in that section to fix the issue. You should be able to fix it without making changes outside of that section. If you have trouble figuring out how to do that, always feel free to ask for help.

1 Like