Closed mrossinek closed 7 months ago
It turns out, that there are more things at play here...
The Qiskit calculation is mostly correct. In fact, all that is needed is to use a symmetric formula for $S^2$ which also allows the number of beta-spin particles to be larger than the alpha ones (rather than vice versa).
The problem here is rather of conceptual nature. The problem is, that using unrestricted-spin orbitals for the active space, can result in the active alpha- and beta-spin orbitals to span different spaces. This then result in a non-unitary alpha-beta overlap matrix, which in turn actually breaks an assumption on which PySCF's implementation is based (which is where I obtained those numpy.einsum
equations from). Fixing it is possible by simply changing the following two lines:
+ np.einsum("ji,ij->", dm1a, ovlpaa)
+ np.einsum("ji,ij->", dm1b, ovlpbb)
to become:
+ np.einsum("ji,ij->", dm1a, ovlpab @ ovlpba)
+ np.einsum("ji,ij->", dm1b, ovlpba @ ovlpab)
This properly accounts for the non-unitary nature of ovlpab
. I tested this in a more extensive example in the snippet below.
One final problem remains, which is for the case where both, the inactive and active sector include unpaired electrons. Here, the numpy.einsum
code does NOT produce the correct expectation value of $S_z$. It is possible to get the correct inactive value from the difference of the total and active terms, but computing the inactive value directly I have still not figured out yet. However, this is not really a problem because such a choice of active space is not really relevant.
Finally, this means that the implementation of #1275 was largely correct. This is also good news, because integrating the overlap-matrix into the FermionicOp
would not really work as I had originally suggested. A PR to make some final improvements to fix this issue will follow shortly.
Environment
0.7.1
)What is happening?
1273 unfortunately has not been fixed properly.
This issue resurfaced while I was looking into some more extended tests. Specifically, using the overlap matrix which I obtained for a
(6,4)
active space of O2:Basically, comparing the computed
S^2
values for different occupations obtained from PySCF's FCI module and Qiskit Nature still produce vastly different results.How can we reproduce the issue?
This results in:
What should happen?
Qiskit should produce the same result as the PySCF implementation.
Any suggestions?
Basically, there are multiple problems:
the formula $S^2 = S^- S^+ + S^z (S^z + 1)$ assumes that there are more alpha than beta spin particles. One needs to take the symmetric version to allow either case: $S^2 = 0.5 * (S^- S^+ + S^+ S^-) + S^z S^z$
on top of that, the logic that was added in #1275 is actually flawed. Through mostly trial and error, I found a patch last night which I admittedly did not understand completely but it made all my test cases pass :eyes: Essentially, I ended up overwriting the coefficients of the one-body terms which result from normal-ordering the $S^+ S^-$ (and v.v.) product to all be 1 (instead of the coefficient that resulted from the overlap squared).
Today, I found out why (thanks also to @AlbertoBaiardi for the extensive discussions). The problem is, that $S^+$ and $S^-$ do NOT need to the include the overlap as coefficients! Rather, we need to adapt our anti-commutation relation and weight this with the overlap. This is explained quite nicely in sections 4.1 and 4.2 of this paper of which I will include the relevant screenshots below:
Long story short, to fix this issue we need to:
FermionicOp
~ also wrong