Qchem.import_state doesn't always work

If I run

from pyscf import gto, scf, ci
from pennylane.qchem import import_state

mol = gto.M(atom=[['Fe', (1.0, 0.0, 0.5)],
                  ['Fe', (0.69, 0.14, 0.36)],
                  ['H', (0.0, 0.0, -1.5)],
                  ['H', (0.0, 0.0, 1.5)]])
# perfrom restricted Hartree-Fock and then CISD
myhf = mol.HF.run()
myci = mol.CISD().run()
wf_cisd = import_state(myci, tol=1e-1)

I would have

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[36], line 11
      9 myhf = mol.HF.run()
     10 myci = mol.CISD().run()
---> 11 wf_cisd = import_state(myci, tol=1e-1)
     12 print(f"CISD-based state vector: \n{np.round(wf_cisd.real, 4)}")

File /workspaces/qtm/.venv/lib/python3.10/site-packages/pennylane/qchem/convert.py:542, in import_state(solver, tol)
    540     wf = _wfdict_to_statevector(wf_dict, len(solver[0][0]))
    541 else:
--> 542     wf = _wfdict_to_statevector(wf_dict, solver.mol.nao)
    544 return wf

File /workspaces/qtm/.venv/lib/python3.10/site-packages/pennylane/qchem/convert.py:569, in _wfdict_to_statevector(fcimatr_dict, norbs)
    567     bin_b += "0" * (norbs - len(bin_b))
    568     bin_ab = "".join(i + j for i, j in zip(bin_a, bin_b))
--> 569     statevector[int(bin_ab, 2)] += coeff
    571 statevector = statevector / np.sqrt(np.sum(statevector**2))
    573 return statevector

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Am I misunderstanding something in the chemistry or it is more of a coding issue? I understand that 2 Fe and 2 H doesn’t interact. Here I am trying to optimize their coordinates, such that the Hamiltonian is minimized if that makes sense.

Hi @mchau , I’m not sure why it’s failing here.

If you just want to optimize molecular geometries then it may be best to follow this demo on that topic instead. However if this isn’t a real molecule it may fail too. Also, it’s important to note that this is a huge molecule that you’re trying to simulate so maybe your error is purely numerical if the computer is running out of space in the middle of the computation.

1 Like

Are you saying that if it is just a bunch of atom that doesn’t react with each other, then Post HF will fail even though HF doesn’t?

Hi @mchau,

I’m not sure whether the error you’re getting is because
a. You need to code the problem differently,
b. The molecule is too large so the program fails,
c. The program fails because the molecule isn’t a real molecule,
d. There’s a bug in PennyLane or PySCF or both.

If the problem is ‘a’ then there might be a solution. I’m asking a colleague to see if maybe there’s something else going on here.

If the problem is ‘b’ or ‘c’ then you may be able to bypass it by adding in some approximations or going back to ‘a’ and doing something differently. It’s hard to say though.

If the problem is ‘d’ then my colleague should be able to help us diagnosing it but a fix may take some time.

You can help advancing the diagnosis by testing this with other real and fake molecules both large and small. Sharing your results with us can help us diagnose it faster!

1 Like

Hi @mchau.

My colleague Stepan looked into the the issue and it turns out to be problem ‘b’, the molecule is too large so your computer fails to create the statevector and the program fails.

You should be able to run active space calculations on this molecule though, with a few tweaks, by selecting only a subset of the orbitals.

We’re working on creating new devices that should be able to handle larger molecules but this isn’t ready yet.

So just to be super clear here, the problem is not that the molecule isn’t real, the problem is that the molecule is too big.

1 Like