Skip to content

solve_fermion function fails for excited state calculation with nroots = 2 #247

@ritajitmajumdar1

Description

@ritajitmajumdar1

Environment

  • qiskit-addon-sqd version: 0.11.0
  • Python version: 3.13.3
  • Operating system: Mac

What is happening and why is it wrong?

Passing nroots = 2 in the function solve_fermion for calculating excited state fails. This is because the output then becomes a list instead of SCIvector. The output type SCIvector is required for further computation.

How can we reproduce the issue?

energy_sci, coeffs_sci, avg_occs, spin = solve_fermion(
            batches[j],
            hcore,
            eri,
            nroots=2
        )

Traceback

AttributeError                            Traceback (most recent call last)
Cell In[17], [line 60](vscode-notebook-cell:?execution_count=17&line=60)
     58 coeffs = []
     59 for j in range(n_batches):
---> [60](vscode-notebook-cell:?execution_count=17&line=60)     energy_sci, coeffs_sci, avg_occs, spin = solve_fermion(
     61         batches[j],
     62         hcore,
     63         eri,
     64         nroots=2,
     65     )
     66     energy_sci += nuclear_repulsion_energy
     67     e_tmp[j] = energy_sci

File ~/miniforge3/envs/qae/lib/python3.13/site-packages/qiskit_addon_sqd/fermion.py:505, in solve_fermion(bitstring_matrix, hcore, eri, open_shell, spin_sq, shift, **kwargs)
    494 _, sci_vec = fci.selected_ci.kernel_fixed_space(
    495     myci,
    496     hcore,
   (...)
    501     **kwargs,
    502 )
    504 # Calculate the avg occupancy of each orbital
--> [505](https://file+.vscode-resource.vscode-cdn.net/Users/ritajit/Desktop/Research/NTU/~/miniforge3/envs/qae/lib/python3.13/site-packages/qiskit_addon_sqd/fermion.py:505) dm1s = myci.make_rdm1s(sci_vec, norb, (num_up, num_dn))
    506 avg_occupancy = (np.diagonal(dm1s[0]), np.diagonal(dm1s[1]))
    508 # Calculate energy from RDMs
...
--> [922](https://file+.vscode-resource.vscode-cdn.net/Users/ritajit/Desktop/Research/NTU/~/miniforge3/envs/qae/lib/python3.13/site-packages/pyscf/fci/selected_ci.py:922)     civec = civec.view(SCIvector)
    923     civec._strs = ci_strs
    924     return civec

AttributeError: 'list' object has no attribute 'view'

Any suggestions?

Line number 494 in fermion.py file calls the kernel_fixed_space and returns sci_vec which is used for further computation. When nroots = 2 is passed, the type of sci_vec becomes list instead of SCIvector. The list contains two SCIvector elements for the ground state and first excited state. Passing only sci_vec[1] for further computation solves this issue. It calculates the first excited state. However, this approach will solve for only first excited state or ground state, whereas passing some value of nroots > 1 has the potential to solve for all the energy states.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions