google / qhbm-library

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

Patch QNN expectation #70

Closed zaqqwerty closed 3 years ago

zaqqwerty commented 3 years ago

Patch QNN _expectation_function and add associated test.

Since the expectation and pulled_back_expectation functions expect operators to be 1D, needed to add tiling of operators to the underlying _expectation_function body. Also took the opportunity to add a test: to make sure it works with both reduce == True and reduce == False, as well as testing the gradients.

Note I had to remove the @tf.function decorators, something goes wrong with TFQ when gradients are called on the decorated function. Opened issue #71 to track resolution of this.