Ah. Then I agree with you. Unless someone else has an idea. But your title and the code are not helping you here. ‘Problem’ is pretty vague.
Recommend changing title to ‘How to obtain gradient from non-user Variables?’