-
Notifications
You must be signed in to change notification settings - Fork 3
Autodiff through chain of chain #10
Comments
On the other side, |
I see, thanks for your answer! Do you have any example of how to use Yao.AD? |
For observable loss, a single prime would work. For general backward, you need to call apply_back explicitly like in: https://github.com/QuantumBFS/YaoBlocks.jl/blob/3bb64e810e38ff8f02ac8975b7d04206eed8232f/src/autodiff/apply_back.jl#L167 Also, matrix representation can be back propagated with mat_back. Note: need master branch. |
So if I want to take the gradient of L = f(expect(H, state => circuit)) with respect to the parameters of the the circuit ( |
BTW, I'll hook backwards to ChainRules in the weekend. (I have 2 assignment due in the week) which should solve this issue once and for all. But @GiggleLiu 's solution is what you can do before we release this.
|
For your case y = f(expect(H, state => circuit))
L = f(y) You need to compute I will write a working example ASAP. |
This repo contains an example of interfacing Yao's AD ( |
Sorry for the late reply, also see this gate learning example https://github.com/QuantumBFS/QuAlgorithmZoo.jl/blob/master/examples/PortZygote/gate_learning.jl |
Sorry to ask a question, Now I can get the gradient of a loss function (like observable), But is there any way if I want to get the Jacobian matrix of state vector (\frac{\partial |x>}{\partial \theta}) ? |
When the output is larger than input, forwarddiff is much faster. I can give you a demo tomorrow (in bed now). You can also try to implement one if you need it urgently. It should be very easy. |
Honestly, I faced some problem when I tired to do like this way (using Zygote). Maybe your demo will help me a lot. I'm not in a hurry, I wish you a good night's sleep. Thank you very much! |
Once the above PR get merged and tagged, you should be able to update your package and use non-inplace API to compute jacobians. pkg> add YaoBlocks#non-inplace-API |
Regarding to this issue itself, I'm hoping to get rid of Zygote at some point entirely from YaoCompiler side... and replace with Enzyme or Diffractor, in near term it would be Enzyme, since ChainRules doesn't have an API definition of in-place operations yet. But not sure if this would happen this year, it will depend on the progress of ChainRules too. |
When running the code below,
I get the following output:
meaning that it didn't find chains defined with
U()
to be differentiable. Is there something wrong with my syntax or is it a bug?The text was updated successfully, but these errors were encountered: