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

Cast sigma to tf.complex64 in fidelity function (#195) #198

Closed ecsbeats closed 2 years ago

ecsbeats commented 2 years ago

Casts sigma argument of the fideltity function to the tf.complex64 dtype. Resolves #195

google-cla[bot] commented 2 years ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

ecsbeats commented 2 years ago

I casted the sigma argument for the fidelity function to the dtype complex128 in the test_fidelity_random function inside /tests/inference/qhbm_utils_tests.py::FidelityTest This way if there is any errors or difference between the output of the faster fidelity function and the direct matrix to matrix fidelity function it will be detected.

I also updated the docstring of the fidelity function to reflect the generalization of the dtype of the sigma argument.

zaqqwerty commented 2 years ago

Thanks for the update, I like the direction here. One last thing in the test: it should check that fidelity accepts both tf.complex64 and tf.complex128 - currently, it only checks that fidelity accepts tf.complex128.

So I would recommend making a copy of your code from lines 106 through 111: in one block, fidelity_wrapper gets sent a tf.complex64; in the other, fidelity_wrapper gets sent a tf.complex128.

ecsbeats commented 2 years ago

I duplicated lines 106-111 and in the second portion used the sigma of dtype complex64 in the actual fidelity function, though avoided recalcuating the direct fidelity function in the second portion to keep the test fast.