Skip to content
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

solve_fermion returns incorrect energy when spin is contaminated #140

Open
kevinsung opened this issue Feb 4, 2025 · 1 comment · May be fixed by #142
Open

solve_fermion returns incorrect energy when spin is contaminated #140

kevinsung opened this issue Feb 4, 2025 · 1 comment · May be fixed by #142
Assignees
Labels
bug Something isn't working test Regarding testing and test automation

Comments

@kevinsung
Copy link
Collaborator

kevinsung commented Feb 4, 2025

What should we add?

PySCF is not guaranteed to return a wavefunction with the requested spin squared. When the spin squared deviates from the value requested, then e_sci in this line is not the energy of the wavefunction.

e_sci, sci_vec = fci.selected_ci.kernel_fixed_space(

Mario investigated and found this to be apparently the correct formula:

e_sci = e_sci-myci.ss_penalty*(spin_sq-spin_squared)**2

But there may be situations where it is not correct. In PySCF's normal FCI class, there is an e_tot attribute which is supposed to always return the energy, but SelectedCI doesn't have that. The surest thing to do is just to compute the energy directly from the RDMs:

dm1 = myci.make_rdm1(sci_vec, norb, (num_up, num_dn))
dm2 = myci.make_rdm2(sci_vec, norb, (num_up, num_dn))
e_sci = np.einsum('pr,pr->',dm1,hcore)+0.5*np.einsum('prqs,prqs->',dm2,eri)

(courtesy of Mario)

TODO construct a reproduction of this issue so it can be tested for

@caleb-johnson
Copy link
Collaborator

Thanks Kevin, the fermion module testing is light/nonexistent. I'll take a look at this and work up a unit test for it

@caleb-johnson caleb-johnson self-assigned this Feb 5, 2025
@caleb-johnson caleb-johnson linked a pull request Feb 5, 2025 that will close this issue
2 tasks
@caleb-johnson caleb-johnson added bug Something isn't working test Regarding testing and test automation labels Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working test Regarding testing and test automation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants