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

fidelity should cast the density matrix argument #195

Closed zaqqwerty closed 2 years ago

zaqqwerty commented 2 years ago

Currently, the fidelity function in qhbmlib/inference/qhbm_utils.py requires the input density matrix sigma to be of dtype tf.complex64. Instead, that argument should be generalized to cast to this dtype.

ecsbeats commented 2 years ago

Working on it.

zaqqwerty commented 2 years ago

Thanks, assigned you to the issue. Also wanted to note, we just cut a new release, which included some file structure updates to be aware of. In particular the fidelity function now lives in qhbmlib/inference/qhbm_utils.py

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.

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.