google / qhbm-library

Quantum Hamiltonian-Based Models built on TensorFlow Quantum
https://qhbm-library.readthedocs.io/en/latest/
Apache License 2.0
40 stars 15 forks source link

Unify approximate derivative code #206

Closed zaqqwerty closed 2 years ago

zaqqwerty commented 2 years ago

Currently we have two different derivative utilities, approximate_derivative and approximate_derivative_unsummed. We use the first when testing EBM derivatives, the second when testing QNN derivatives. The difference is between comparing expected results to the return from tape.gradient versus the return from tape.jacobian.

This function is also generally wrapped in a function expectations_derivative which iterates through a list of variables, computing their derivatives. The return of this function requires reshaping by the caller to compare to the return of tape.jacobian.

This issue is to combine test_util.approximate_derivative, test_util.approximate_derivative_unsummed, and expectations_derivative into one function that has an interface like tape.jacobian.