# Openfermion : get_sparse_operator issue

I am trying to use operfermion to calculated the eigen values for different molecules. Tried for Hydrogen, LithiumHydride, Water. It works fine. When Itried to calculated the same thing for Ozone, Oxygen, HCN etc., the program finally got killed after consuming all the memory.

Any help is deeply appreciated.

## Here is the sample code to reproduce the issue

from numpy import pi

from openfermion.chem import MolecularData
geometry=[['O',[0,0,0]],['O',[0,1.0885,0.6697]],['O',[0,-1.0885,0.6697]]]
basis='sto-3g'
multiplicity=1 #singlet
charge=0 #neutral
ozone_molecule=MolecularData(geometry,basis,multiplicity,charge)
from openfermionpsi4 import run_psi4
ozone_molecule = run_psi4(ozone_molecule,
run_mp2=True,
run_cisd=True,
run_ccsd=True,
run_fci=True)
two_electron_integrals = ozone_molecule.two_body_integrals
orbitals = ozone_molecule.canonical_orbitals
ozone_filename = ozone_molecule.filename
ozone_molecule.save()

one_body_integrals = ozone_molecule.one_body_integrals

from openfermion.transforms import get_fermion_operator, jordan_wigner

ozone_qubit_hamiltonian = jordan_wigner(get_fermion_operator(ozone_molecule.get_molecular_hamiltonian()))

from openfermion.linalg import get_sparse_operator
from scipy.linalg import eigh

ozone_matrix= get_sparse_operator(ozone_qubit_hamiltonian).todense()
eigenvalues, eigenvectors = eigh(ozone_matrix)
print(eigenvalues)



This consumes roughly 128 GB of RAM and finally gets killed.

• Welcome to QC StackExchange! Could you provide some more details on your attempts so far, maybe snippets of your code? Apr 15 '21 at 13:50
• Code Snipped attached above Apr 18 '21 at 5:01

## 1 Answer

This is normal! If you look at the molecular Hamiltonian ozone_molecule.get_molecular_hamiltonian(), you will notice that it is a Hamiltonian that acts on 30 spin orbitals, and so ozone_qubit_hamiltonian is a 30 qubit Hamiltonian. This means it has $$2^{30} \times 2^{30} = 2^{60} \approx 1.15 \times 10^{18}$$ matrix elements, which will surely consume all your computers memory.

If you want to study these larger molecules, perhaps you should consider an active space approximation (see the Openfermion tutorials some details on how to implement this). This will reduce the number of spin orbitals in your molecular Hamiltonian, giving you an exponential reduction in the dimension of the sparse/dense matrix.

• Thank you very much. I will go through it and see how we can use the active space approximation. If possible can you provide some example code, coz that will expedite the work. Regards, Apr 19 '21 at 9:12