quantumlib / OpenFermion-FQE

The Fermionic Quantum Emulator (FQE) is a fermionic simulation research tool specializing in quantum circuits emulating fermion dynamics.
Apache License 2.0
61 stars 25 forks source link

Consider adding additional helper functions for integration with Cirq #71

Closed Wuggins closed 3 years ago

Wuggins commented 3 years ago

I spent some time experimenting with FQE for pre-determining parameters for a variational ansatz that I want to express as a quantum circuit. I ended up writing code to take the parameters from FQE and build a cirq Circuit that produced the same wavefunction (with one qubit per spin-orbital and a Jordan-Wigner transformation).

I was a little surprised that I had to cobble together some of slow and messy code to convert my FQE wavefunction into a qubit one. It was important for testing that I compare the two wavefunctions properly and it would be great if FQE provided a helper for this that wasn't too slow on top of the exponential scaling we'd already be dealing with.

I'm not sure what the best path here is. It seems silly to reproduce the OpenFermion functionality for doing the conversions unless we're going to replace it entirely (which might be a good long term plan). Minimally, it would be nice to have a function that can at least take an FQE wavefunction and a qubit ordering for Jordan-Wigner and return a vector in the qubit Hilbert space.

P.S. I'm not sure if this is the best place for a feature request, so feel free to close this issue if there is a better channel.

ncrubin commented 3 years ago

we have that functionality in FQE. These functions are fqe.to(from)_cirq. They output a 2**n vector that can be used to seed a cirq simulation. They are relatively fast now but there are some performance improvements that can be made if necessary. We always map to the alpha == even and beta==odd index ordering for jordan-wigner.

Wuggins commented 3 years ago

I honestly have no idea how I missed this. I swear I searched "cirq" and skimmed through the code. Nevermind then.

One thing that might be worth considering is having an option to specify the ordering of the fermionic modes in the qubit wavefunction.

There is a good argument that that is too niche of a feature though. If I had found this function I would have just copied the method and added a call to OpenFermion's reorder in the middle.

ncrubin commented 3 years ago

I discussed with @Wuggins offline but I wanted to say it here before closing the issue. An inefficient way to do this would be to use FQE to map a vector to a sum of ladder ops and then use OpenFermion to impose the desired normal_ordering. I guess a better way would to cleverly use the sorting routines in FQE to give you the phase for the normal_ordered string based on whatever the user defines as normal ordering.