Open therooler opened 3 years ago
Hi Roeland, it's great to hear that your research is benefitting from TFQ!
As for the Hessians of circuits, it is likely that we will add a function to implement the parameter-shift-based Hessian (as in e.g. this work by the Coles group ). Really, this is just applying recursively the parameter shift gradient update rule twice. @zaqqwerty is working on such implementations for second and higher-order gradients and may have a temporary workaround leveraging some of the recent methods for exposing the innards of TFQ differentiators.
Hi, I also want to compute the Hessian of parameterized circuits using TFQ. Does anyone have a workaround solution? Thanks!
Hello all,
I'm hitting this error but only when running in graph mode.
What's strange is that I'm only asking for gradients (not a Jacobian), and calling the circuit (part of a model) with tf.py_function
(so as to run the model in eager mode), so I don't understand where the error is coming from. Is there a way to side-step this?
def eager_model_eval(inputs, params):
with tf.GradientTape(watch_accessed_variables=False) as tape:
tape.watch(params)
# `model` and `tan_loss` are defined out of scope
overlap = model([inputs,params])
loss = tan_loss(overlap, [1.])
gradients = tape.gradient(loss, [params])
return loss, gradients
# ... Later in graph mode ...
eager_model_result = tf.py_function(
func=eager_model_eval,
inp=[inputs, params],
Tout=(tf.float32, tf.float32))
(My guess is that a differentiation of the gradient is being attempted, but only in graph mode for some reason?)
Thanks in advance.
Hi @therooler @zaqqwerty @QuantumVerd
May I know if you were able to find a solution to calculate Jacobians/Hessians from Parameterized Quantum circuits? I'm facing a similar problem and it would be appreciated if you could provide some insights! Thanks.
Python: 3.8 TFQ: 0.4.0 Hi,
I am trying to get some Hessians from the one of my parameterized quantum circuits. This trainstep works as intended:
Following this example in the TensorFlow 2 docs I was hoping I could get the Hessian with the following code:
But this throws the error:
From which I conclude that calculating gradients of gradients is not supported yet ( I tried the other differentiators as well). Am I out of luck here? Or is there a hack I can use to get the Hessians from the circuit? Thanks! If you need an example where I use this train step I can throw one together.
P.S. I am in the process of rewriting all my research code to TFQ and so far everything has worked like a charm. No more super slow graph building times and worrying about how to extract stuff the graph with my own TF1 simulator. And the adjoint differentiator in TFQ is amazing as well; I ran a VQE optimization with like 500 parameters the other day without any issues. Great stuff!