sQUlearn / squlearn

scikit-learn interface for quantum algorithms
https://squlearn.github.io
Apache License 2.0
58 stars 18 forks source link

Add derivatives for PQK #277

Closed rupof closed 2 months ago

rupof commented 5 months ago

Hi!

As discussed in the meeting, here is the implementation of the single-variable RBF PQK derivatives.

It includes 3 relevant additions:

  1. evaluate_string_derivatives: given an evaluation string (i.e "dKdx", ...) returns the corresponding matrix
  2. evaluate_derivatives: calls evaluate_string_derivative, checks caching and returns a dictionary (loosely based on LowLevelPennylane.evaluate )
  3. GaussianOuterKernel.dKdx, GaussianOuterKernel.dKdy, GaussianOuterKernel.dKdxdx, GaussianOuterKernel.dKdxdy: the analytical derivatives of the RBF

About notation:

In the implementation of evaluate_string_derivatives, O correspond to the array of expectation values of the observables that go into the PQK, in the squlearn documentation of the PQK this is refered to as QNN(x). Perhaps, a better name instead of O would be good :) (pylint also did not like this name)

About the correctness:

I have numerically benchmarked with an analytical example evaluate_derivatives for dKdx, dKdy, dKdxdx, dKdxdy, so they should be correctly implemented. I have not benchmarked yet dKdp (as I have not used it for any ODE). In summary, the status of the implemented derivatives is:

1D variable:

Multidimensional variable:

I am very happy and grateful to receive your feedback to improve the implementation. 🙏 🚀

Thank you very much for your help!



In case someone wants to double check the derivation, see screenshot.

image image