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

Code duplication in hamiltonians #45

Open rmlarose opened 3 years ago

rmlarose commented 3 years ago

There's a few things that can be cleaned up with these classes, notably the methods diagonal_coulomb, diagonal, etc. Some of these can just be inferred from the type, i.e. using isinstance(ham, DiagonalCoulomb) instead of

def diagonal_coulomb(self) -> bool:
    """Returns whether or not the Hamiltonian is diagonal_coulomb."""
    return True

Alternatively, one define Hamiltonian with arguments for is_diagonal, is_diagonal_coulomb, etc., which would clean things up.

I think the inheritance structure could be fixed in some places. E.g., DiagonalCoulomb should inherit from Diagonal instead of from Hamiltonian as far as I understand.

ncrubin commented 3 years ago

Hey Ryan, I also think it would be nice if we had a way to use FQE wavefunctions to calculate expectation values of FermionOperators that obey the symmetries of the wavefunction. The simplest thing one could do is partition the FermionOperator into individual terms and then convert to a SparseOperator and calculate the expectation value. It would be better if this happened behind an API. Any interest in implementing this?

rmlarose commented 3 years ago

Hey Ryan, I also think it would be nice if we had a way to use FQE wavefunctions to calculate expectation values of FermionOperators that obey the symmetries of the wavefunction. The simplest thing one could do is partition the FermionOperator into individual terms and then convert to a SparseOperator and calculate the expectation value. It would be better if this happened behind an API. Any interest in implementing this?

Sure thing! I think I have a clear idea how to do this but may need to ask some domain-specific questions, though.