block-hczhai / block2-preview

Efficient parallel quantum chemistry DMRG in MPO formalism
GNU General Public License v3.0
67 stars 23 forks source link

Relativistic DMRG failure with an odd number of electrons #125

Closed shivupa closed 1 month ago

shivupa commented 1 month ago

I was playing around with Block2, and I ran into an issue that I didn't quite understand. I managed to reproduce this by slightly modifying the example from the documentation https://block2.readthedocs.io/en/latest/tutorial/qc-hamiltonians.html#Relativistic-DMRG

from pyscf import gto, scf
import numpy as np
from pyblock2._pyscf.ao2mo import integrals as itg
from pyblock2.driver.core import DMRGDriver, SymmetryTypes

mol = gto.M(atom="N 0 0 0; N 0 0 1.1", basis="sto3g", symmetry="d2h", verbose=9, charge=1, spin=1)
mf = scf.DHF(mol).set(with_gaunt=True, with_breit=True).run(conv_tol=1E-12)
ncas, n_elec, spin, ecore, h1e, g2e, orb_sym = itg.get_dhf_integrals(mf, ncore=0, ncas=None, pg_symm=False)

driver = DMRGDriver(scratch="./tmp", symm_type=SymmetryTypes.SGFCPX, n_threads=4)
driver.initialize_system(n_sites=ncas, n_elec=n_elec, spin=spin, orb_sym=orb_sym)

mpo = driver.get_qc_mpo(h1e=h1e, g2e=g2e, ecore=ecore, iprint=1)
ket = driver.get_random_mps(tag="GS", bond_dim=250, nroots=1)
energy = driver.dmrg(mpo, ket, n_sweeps=20, bond_dims=bond_dims, noises=noises, thrds=thrds, iprint=1)
print('DMRG energy = %20.15f' % energy)

The only thing that I changed is that I removed one electron from N2.

When I run this I get

python: [PATH TO BLOCK2]block2-preview/src/core/symmetry.hpp:602: block2::SGLong<IF>::SGLong(int, int, int) [with bool IF = true]: Assertion `twos == 0' failed.

and the calculation crashes. Is this a problem with my installation of Block2 or something wrong with Block2 internally?

If needed I built Block2 master with

cmake $source_dir -DUSE_MKL=ON -DBUILD_LIB=ON -DBUILD_CLIB=ON -DLARGE_BOND=ON -DMPI=OFF -DUSE_SG=ON -DUSE_COMPLEX=ON -DCMAKE_INSTALL_PREFIX=$install_dir
hczhai commented 1 month ago

Thanks for your interest in using block2. For relativistic DMRG, the projected spin is no longer a good quantum number, so you need to delete the spin=spin in driver.initialize_system, which means:

driver.initialize_system(n_sites=ncas, n_elec=n_elec, orb_sym=orb_sym)

Then it will work. The example in the documentation will be fixed.

shivupa commented 1 month ago

Awesome! Yeah it felt weird to use projected spin for a relativistic calculation. Thanks for the quick reply. This answers my question.

Is there documentation for the FCIDUMP keywords IGENERAL and ITGENERAL?

hczhai commented 1 month ago

IGENERAL=1 indicates that there is no implied 8-fold symmetry of two-body integral. ITGENERAL=1 indicates that there is no implied 2-fold symmetry of one-body integral.

When seeing these keywords in FCIDUMP, the block2 code will not apply the identities h[ij] = h[ji] and v[ijkl] = v[jilk] = ....

shivupa commented 1 month ago

Awesome thank you! That makes sense!