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

Issue Exporting CASCI Wavefunction from PySCF to qp2 #46

Open
NastaMauger opened this issue Nov 9, 2024 · 9 comments
Open

Issue Exporting CASCI Wavefunction from PySCF to qp2 #46

NastaMauger opened this issue Nov 9, 2024 · 9 comments

Comments

@NastaMauger
Copy link

NastaMauger commented Nov 9, 2024

Hello,

I am opening this issue on the TREXIO-tools GitHub, but please be aware that I may not be certain whether the issue lies with TREXIO-tools, qp2, or myself (last one is the most probable :) )

I was able to correctly register the data needed to use them with qp2. After doing that, I ran the following qp2 commands:

qp_import_trexio.py casci.hdf5
qp set_file casci.hdf5.ezfio/
qp set mo_basis mo_label Canonical
qp_run import_trexio_integrals casci.hdf5.ezfio
qp_run print_energy casci.hdf5.ezfio

The energies returned were the same as those given by my PySCF-RHF script, so I know that my TREXIO write commands in my PySCF script are correct.

However, I would prefer to use my PySCF-CASCI wavefunction instead of the RHF one. So, I modified my PySCF script as follows:

overlap = casci.mol.intor('int1e_ovlp')                                                                  
kinetic = casci.mol.intor('int1e_kin') 
potential_n_e = casci.mol.intor('int1e_nuc')
core = casci.get_h1eff()[0]

mo_active = casci.mo_coeff[:, casci.ncore:casci.ncore + norb]

h1e_kin_active = mo_active.T @ kinetic @ mo_active
h1e_ovlp_active = mo_active.T @ overlap @ mo_active
h1e_nuc_active = mo_active.T @ potential_n_e @ mo_active

h2eff = casci.get_h2eff()
write_eri(h2eff,trexio_file)

trexio.write_mo_1e_int_overlap(trexio_file, h1e_ovlp_active)
trexio.write_mo_1e_int_kinetic(trexio_file, h1e_kin_active)
trexio.write_mo_1e_int_potential_n_e(trexio_file, potential_n_e)
trexio.write_mo_1e_int_core_hamiltonian(trexio_file, core)

However, when exporting to qp2, the energy is still the same as the RHF one, even though I am using casci.get_h1eff()[0]. On the qp2 side, I set my mo_class using qp set_mo_class to be the same as my PySCF one. The write_eri function is defined in here.

Now, using my determinant export pyscf script, I was also able to correctly import my determinant into qp2, but my energy is higher than the RHF one when using qp_run print_energy my_ezfio.

So, my question is twofold:

  1. How do I correctly export a CASCI/CASCCF wavefunction from PySCF to qp2?
  2. What might I have done wrong that could explain the increase in my E(CI)​ after using the command qp_import_trexio_determinant?

I also tried to use the FCIDUMP file after my casci.kernel() to export in trexio format but it also failed

Thank you so much for your time and insight! :)

Best

@scemama
Copy link
Member

scemama commented Nov 11, 2024

@NastaMauger : If you do

qp set determinants read_wf 1

does it fix the problem?

@q-posev
Copy link
Member

q-posev commented Nov 13, 2024

@NastaMauger I have a few notes here:

  1. Maybe your write_eri approach is wrong? The ERIs are not specific to CI, they come from HF and are already dumped as part of scf_to_trexio functionality of pyscf-forge. Maybe you should use their implementation (i don't really know what h2eff contains in your case)
  2. I see that you only use active orbitals to compute the 1e integrals. I think that 1e integrals should be also dumped as part of the HF wave function export to TREXIO. On another note, with the way you define the mo_active, it looks like you exclude the contribution of the core orbitals. Could this explain the diff in energy with qp2?

Perhaps, you can also retry your tests once Kousuke's PR for ECPs and AOs in pyscf-forge is merged.

@NastaMauger
Copy link
Author

NastaMauger commented Nov 17, 2024

Hello,

@scemama no it does not solve the issue unfortunately :(

@q-posev, I would prefer to use get_h1eff and get_h2cas which return the effective one - and two-electron integrals for the CAS space. However, since TREXIO registers each component of the one-electron integral, I’m a bit confused about how to register the get_h1eff object.
As for get_h2cas, since it returns the integral in the regular PySCF format, I don’t understand why the write_eri function from PySCF-forge wouldn’t work.

I think the issue might be he missing RDMs. Does QP2 have an import_trexio_rdm function? I couldn't find anything.
I do not understand how the Ven, Kinetic, and other energy values printed by qp_run print_energy can match the correct CASCI values given by PySCF without RDMs

Best

@NastaMauger
Copy link
Author

Also, when I add the occupation number from my CASCI object into trexio and read it with QP2, now qp_run print_energy gives energy which are wrong.

@q-posev
Copy link
Member

q-posev commented Nov 21, 2024

I am not familiar with the TREXIO import in QP2 but could it be that you need to write all integrals and not only the effective ones? And then you specify active/non-active orbitals in TREXIO file and QP2 takes care of reading the right blocks? @scemama knows for sure.

Regarding the write_eri, I would recommend to follow the way it's done by the PySCF developers unless you have a good reason not to.

@NastaMauger
Copy link
Author

NastaMauger commented Nov 22, 2024

Hello @q-posev

I am not familiar with the TREXIO import in QP2 but could it be that you need to write all integrals and not only the effective ones?

The issue doesn't seem to lie with this, as it appears to be correctly registered in TREXIO when examining the HDF5 file. However, it seems that QP2 is having difficulty interpreting it for some reason.

Regarding the write_eri, it takes the PySCF ERI as an argument and registers it directly into TREXIO. Therefore, it doesn't seem like the issue lies with write_eri when handling h2_eff.

@NastaMauger
Copy link
Author

Regarding this answer I feel a bit confused about whether TREXIO can register the element referred to by sunqm. I couldn't find any relevant information in the documentation.

@MatthewRHermes
Copy link

trexio.write_mo_1e_int_potential_n_e(trexio_file, potential_n_e)

Are you sure you don't want h1e_nuc_active here instead of potential_n_e?

@q-posev
Copy link
Member

q-posev commented Jan 2, 2025

@NastaMauger has this issue been fixed by the latest modifications?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants