Add FQK derivatives using a new lowlevel class FidelityKernelExpectationValue #320
Conversation
…nd modified fidelity_kernel to call fidelity_kernel_expectation value
There was a problem hiding this comment.
The overall code looks good - thank you very much!
However, the docstrings in fidelity_kernel_expectation_value.py are currently a bit chaotic.
Additionally, many comments and strings exceed 100 characters. Could you fix this?
I also have the impression that the Args and Parameters sections were modified using search and replace, which introduced some inconsistencies.
Please ensure that the following format is used consistently throughout the code:
"""
Single-line summary.
Detailed description.
Args:
variable_name (variable_type): Variable description.
Returns:
return_type: Return value description.
"""
src/squlearn/kernel/lowlevel_kernel/fidelity_kernel_expectation_value.py
Outdated
Show resolved
Hide resolved
src/squlearn/kernel/lowlevel_kernel/fidelity_kernel_expectation_value.py
Outdated
Show resolved
Hide resolved
…h:`U(x)^\dagger U(y) |0\rangle` and measuring the expectation value of the operator
:math:`P_0 = |0\rangle\langle 0|^{\otimes n}`, where :math:`U(x)` is the encoding circuit unitary
evaluated for data `x`.
|
Hi @David-Kreplin! I think you can already review it again. I think I implemented all your comments and try to make the docstrings less chaotic. If you think they still need improvement, please let me know. Also, two more points:
Thank you very much! Again, if there is anything else, please let me know 😄 Roberto |
Hi!
Here is the implementation for the derivatives of the FQKs for both 1-D and N-D variables:
dKdx,dKdxdx,dKdxdy,dKdydx,dKdp, etcBasically, it implements a FQK as a QNN ( U(y)^\dagger U(x) |0>) and measures against the operator P_0 = |0><0|^\otimes n.
For this, I had to:
Modify
EncodingCircuitBase.inverse()such that squlearn encoding circuits can be inverted.composemethod instead of ("+") such that the sum of two circuits includes new features and uses the same parameters. I modified ("+") such that it is an especial case of.compose.Created the FidelityKernelExpectationValue class that creates the QNN in the QK format, and implemented
.evaluate_derivativesthat calculates the derivatives from the QNN._evaluate_duplicates = "none", for this class. The routine only calculates the lower triangle values of the kernel matrix "K" and then reshapes it appropriately. I only implemented it for "K", for the derivatives I have not implemented anything yet.I benchmarked the derivatives with an analytical example and created three tests: single variable derivatives, multi variable derivatives and duplicate tests.
Also perhaps FidelityKernelExpectationValue is not a good name, as always calculating a QK requires obtaining expectation values.
Feel free to give me feedback and let me know what should be improved.
Thank you very much for your help! 🚀
Roberto
PD: I used black but I dont know why it is failing the tests :/