-
Notifications
You must be signed in to change notification settings - Fork 44
Description
I am trying to get frozen cores working with an OpenFermion-PySCF workflow, and am having issues. As an example, here I am freezing two electrons (i.e., one core orbital, i.e. 2 qubits.) When I set N_e = 6 and N_qubits = 12, i.e. the full active space, I get matching results between CASCI in PySCF and diagonalization of the Hamiltonian that OF-PSCF gives me. In this example, I use N_e = 4 and N_qubits = 10, and get the wrong reference and CASCI energies from the OF-PSCF Hamiltonian.
def test_adapt_vqe():
"""Test ADAPT on H6."""
if os.path.exists('test') == False:
os.makedirs('test')
geom = 'H 0 0 0; H 0 0 1; H 0 0 2; H 0 0 3; H 0 0 4; H 0 0 5'
basis = "sto-3g"
reference = "rhf"
N_e = 4
N_qubits = 10
multiplicity = 1
#E_nuc, H_core, g, D, C, hf_energy = get_integrals(geom, basis, reference, chkfile = "scr.chk", read = False, active = (int(N_qubits/2), N_e))
#PySCF SCF and CASCI Calculations
mol = gto.M(atom = geom, basis = basis, verbose = False)
mol.build()
mf = scf.RHF(mol)
mf.conv_tol_grad = 1e-8
mf.max_cycle = 10000
mf.init_guess = 'atom'
print("PySCF HF Energy:")
print(mf.kernel())
mycas = mcscf.CASCI(mf, int(N_qubits/2), N_e)
casci = mycas.kernel(verbose=False)
print("PYSCF CASCI:")
print(casci[0])
H = generate_molecular_hamiltonian(geom, basis, multiplicity, n_active_electrons = N_e, n_active_orbitals = int(N_qubits/2))
H = of.linalg.get_sparse_operator(H).real
refstr = ''
for i in range(N_e, N_qubits):
refstr += '0'
for i in range(0, N_e):
refstr += '1'
ref = np.zeros(2**N_qubits)
ref[int(refstr,2)] = 1
ref = scipy.sparse.csc_matrix(ref).T
print("OpenFermion-PySCF HF Energy:")
print((ref.T@H@ref)[0,0])
print("OpenFermion-PySCF CASCI Energy:")
w, v = scipy.sparse.linalg.eigsh(H, which = "SA")
print(w[0])
exit()
Output:
PySCF HF Energy:
-3.1355322139663198
PYSCF CASCI:
-3.1981030445646623
OpenFermion-PySCF HF Energy:
-1.3744190019034384
OpenFermion-PySCF CASCI Energy:
-3.1614199163979224