# Gradient Calculation Issues with TensorFlow Interface

OKK， Thank you very much, we have solved this issue!

Hey @zj-lucky,

If you could please write out or copy-paste a minimal example of your code that would be great! No worries that you can’t include your dataset, but please create a dummy dataset in your code here just so that I can copy-paste, run, and try to replicate your error as quickly as possible

@zj-lucky when you say “gradients of the parameters in the quantum circuit are not being correctly computed”, do you mean that the result is that your model isn’t training as expected? I have a hard time seeing the gradients not being computed correctly, although I’m not ruling it out. One way to check the gradients of your model yourself would be to create a simple finite-difference gradient function and compare that to the gradient calculated with TF (probably using backprop under the hood). Recall that the finite-difference function is

\frac{\partial}{\partial x_i} f(x_1, x_2, ..., x_i, ..., x_n) \approx \frac{f(x_1, x_2, ..., x_i + \epsilon, ..., x_n) - f(x_1, x_2, ..., x_i, ..., x_n)}{\epsilon},

where you can take \epsilon to be something super small (e.g., 0.001).

It’s tough to say what’s going on in your code because it’s a large code base . If you could reduce it down to something much smaller that replicates the behaviour you’re observing, that would greatly help.

Let me know if looking at the finite-differences pans out!

The output is:

Epoch 1/10
WARNING:tensorflow:Gradients do not exist for variables [‘Variable:0’] when minimizing the loss. If you’re using model.compile(), did you forget to provide a loss argument?
[True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]

The first element is ‘True’, while the others are False, which means the parameters of the quantum circuit have not been correctly gradient computed, whereas the parameters in other classical models have been correctly gradient computed. Therefore, I am unsure where the issue lies in the parameter passing and training of the quantum circuit.

Interesting! Well, if you could please reduce your code down to something more manageable for me to look at, I can try to help figure out what’s going on. Reducing your code down to a minimal example that still produces the behaviour you’re seeing is a valuable part of debugging to learn . Hopefully we can find the answer!