-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistency between expectation values via SparseHamiltonian and get_restricted_hamiltonian? #99
Comments
I believe that fqe.get_restricted_hamiltonian assumes that the input tensors are spin-free form (i.e., spatial -- in this case (2,2) and (2,2,2,2) size). It appears that you are passing (4,4) and (4,4,4,4) sized arrays to this function. If you zero out the two body and pass one_body_integrals to get_restricted_hamiltonian, they'd agree. Second, your two-body operator is not consistent. This is the print out - the coefficient in front of 3^3^11 should be identical to two_body_integrals[1, 1, 0, 0]. It appears that for this particular term, there is a factor of 2 missing. Also your hamiltonian does not have some elements, for example, 3^ 0^ 3 0 element, which I find odd. Further, due to symmetry, I'd imagine that 3^ 1^ 1 3 and 3^ 1^ 3 1 should be the same magnitude but different sign. Something is odd.
|
Well, the docstring of I can confirm that if I set the two body integrals to zero and pass the integrals instead of the coefficients to If Regardless of whether I pass integrals or coefficient tensors to You seem to say that my Hamiltonians are not well formed. But (at least in the second example) they are generated with standard OpenFermion tools from integrals that, while random, should have all the symmetries also shared by real RHF integrals. To exclude that the discrepancy I observe is caused by my integrals, I have now added tests with integrals generated by openfermion-pyscf and such from the FQE unittest_data and still see the same discrepancy:
I get
but still think that the energy from InteractionOperator->FermionOperator->SparseHamiltonian should agree with either the value returned by get_restricted_hamiltonian() when called with integrals or when called with coefficients. |
Regarding the first point, I will include the docstring update in the next commit to clarify that what's expected is a Hamiltonian tensor in a spin-free form. Regarding the second, get_restricted_hamiltonian is correctly working (see below); therefore, I can only speculate that there is some inconsistency in your code, perhaps with regards to interacting with OpenFermion and/or FQE. Nick @ncrubin -- could you take a look?
which returns
|
I can also reproduce the problem with a more minimal example starting from your code:
Here, I think, the correctness of the integrals is beyond doubt and I am only using standard OpenFermion functions to convert the given integrals into an InteractionOperator. I really don't see where my code can explain the result that I am getting:
|
Thank you, this example is helpful! To summarize the situation for others: there seems some inconsistency in the conversion process of numpy.ndarray->InteractionOperator->FermionOperator->SparseHamiltonian, and I have observed in the initial reply that the SparseHamiltonian object does not seem to be properly formed. The first two steps are implemented in OpenFermion (that I am not familiar with) and the third step is implemented in FQE. I can double-check the third step, should we narrow down the problem to this step. I will first let Nick @ncrubin review this example to get his insights. |
Great! There are all sorts of subtleties here concerning tensor index ordering and subsystem ordering (both qubits and fermions) but from reading the examples (and the great overlap in developers of the two packages), my impression was that OpenFermion and FQE should use all the same conventions, which is why I am puzzled by the discrepancy described above. |
@cvjjm Unfortunately, the default convention used in OpenFermion is not consistent with FQE (which was designed for efficiency). I'll take a look at the examples and report back. |
Just to add a little more to this: The following code computes the energy from the cirq wave function and the Hamiltonian obtained from OF:
The result is also -13.129513263353799+0j, i.e., in line with result from My suspicion thus was that the problem is caused by some difference in how qubits or orbitals are ordered during the jordan wigner transformation. I have some code that does JW in 'sequential' ordering and the qubit ordering of the resulting operator can be changed with with
|
…re included Note that General Hamiltonian is considered now as spin-unrestricted. Related to #99
I think I found the solution to the mystery here. FQE seems to use "chemists' ordering" of the two electron integrals and conversion from OpenFermion convention (which uses "physicist's ordering" can be done by means of One can thus go back from FQE convention to OF convention by means of I wish this were documented somewhere, or even better that at least the packages from the same developers stick to the same conventions.... |
Hi @cvjjm , circling back to this in more detail today. Indeed we provide the openfermion functions for interfacing the two Hamiltonian types. You are right that ideally documentation on OpenFermion and FQE highlights (the very first page) integral formatting. I will raise this as an issue and get someone to address it (myself or @jjgoings) Indeed it would be nice if the ordering was the same for OpenFermion and FQE. Just as a note, OpenFermion isn't even physics notation as I've traditionally seen it. The OpenFermion convention is to use the pqrs ladder op indices as the tensor indices. This is not the case in most quantum chemistry codes. Another common way to build hamiltonians for FQE is to use the For example, augmenting your original code slightly
|
Great! And thanks for making me aware of |
I will leave it open until changes are made. This is a good first issue for @jjgoings |
Suppose I have an OpenFermion
InteractionOperator
and I want to measure its energy on a FQE wave function.It appears there are two routs to do this:
Convert the
InteractionOperator
to aFermionOperator
and then to a FQESparseHamiltonian
(btw, it would be nice if there was a more direct way to do this)Get the tensors from the
InteractionOperator
and feed them into FQE'sget_restricted_hamiltonian()
Naively I would have thought that this should yield the same result, but this does not seem to be the case, not even in the HartreeFock state as the following "minimal" example shows (just to be sure I am also constructing the
InteractionOperator
in two different ways):The output I get is:
Am I doing something wrong?
The text was updated successfully, but these errors were encountered: