Conversation
|
@rupof , is this branch ready for review or you are still working on it? |
|
@David-Kreplin it is ready for review, I just changed it now. Thanks! |
David-Kreplin
left a comment
There was a problem hiding this comment.
Here are some comments on the code
src/squlearn/encoding_circuit/circuit_library/hardware_efficient_rzrxrz.py
Outdated
Show resolved
Hide resolved
…implementing chebyshev without calling external class
RobertoFlorez
left a comment
There was a problem hiding this comment.
Hi! I made the changes requested:
- Order of the ODE is now checked through len(symbols_involved_in_ODE) and included a check at the initialization. Also checks if order is higher than 2.
- Changed the name of initial_vec to initial_values for IVP information
- Moved helper functions inside the class
- Instead of HEE_rxrzrx, I created kyriienko_nonlinear_encoding which implements the feature maps used in the original paper (this implementation is slighly based on the chebyshev_tower.py).
Thanks for the feedback! Anything else that you think should be improved, I am happy to help :)
David-Kreplin
left a comment
There was a problem hiding this comment.
Great work! I think we are almost there.
However, due to the recent updates in Squlearn, the example is currently broken. Simply adding the reshape command does not resolve the issue.
There are a few minor changes that I’ve also noted in the code:
- The LaTeX rendering of the gradient in the ODE is broken.
- An example of how to initialize the ODE loss would greatly improve the documentation.
- I had difficulty understanding how to order the symbols_involved_in_ODE; perhaps you could provide a bit more detail on this.
|
Thank you very much David! I did the following things:
If you think that the documentation for the sympy symbols needs to be improved further let me know. Thanks! Edit: because the example is taking so much time one check is throwing an error, I am searching for an alternative |
David-Kreplin
left a comment
There was a problem hiding this comment.
I think that's it, thank you very much!
Hi!
This is the implementation for the loss function for an ODE
ODELoss(as done in https://arxiv.org/pdf/2011.10395). It should accept linear and non-linear 1st order and 2nd**[See footnote] order differential equations that depend on one variable.I also created an example (
ode_example) of how to use the interface and included a parameterized feature map (HEE_rzrxrz) that was used in the original paper to manipulate the function space.The implementation interface accepts two type of inputs:
About the Implementation:
This pull is a new class from
LossBasethat implements:With corresponding gradient:

where$F$ , is the homogenous differential equation that can be given by the user. Also, it includes two ways to incorporate the initial value problem information based on the paper:
floatingandpinnedAbout the correctness:
I have benchmarked the gradient of the loss by comparing the finite-difference gradient with the one implemented using squlearnˈs parameter-shift rule (i.e previous equation):
Numerical Gradient:

Squlearn Gradient:

Also, I have solved some ODEs sucessfully,
Also, to use sympy I created three functions that are outside of the ODELoss class:
numpyfy_sympy_loss,numerical_gradient_of_symbolic_equationandnumpyfy_sympy_loss. I do not know if the current location of this function is the best one or if they should be methods, I am happy to hear your thoughts.Feel free to give me feedback 😃 and thank you very much for your help! 🚀
*** 2nd order differential equations are implemented by differentiating twice the QNN trial function f(x), this implies that third order derivatives with regards to the parameters have to be calculated (i.e dfdxdxdp). As you may imagine this requires a lot of circuit evaluations (I believe for N points, around N^3 circuits must be evaluated). I do not think this is the proper way to solve second order ODE, one should translate a 2nd order to two coupled first orders.
I have not implemented coupled 1rst ODE solvers and this would be a possible next step, which I may do next. I could create an issue or something similar.