qiskit-community / qiskit-nature

Qiskit Nature is an open-source, quantum computing, framework for solving quantum mechanical natural science problems.
https://qiskit-community.github.io/qiskit-nature/
Apache License 2.0
290 stars 197 forks source link

Enable fully occupied spin registers in UCC-like ansatze #1355

Open zpy2001 opened 3 months ago

zpy2001 commented 3 months ago

Environment

What is happening?

When I use QEOM, I set the driver as

driver = PySCFDriver(
    atom="H 0 0 0; H 0 0 0.7",
    basis="sto3g",
    charge=-1,
    spin=1,
    unit=DistanceUnit.ANGSTROM,
)

It is right in pyscf: 2611712584314_ pic

but meets bug in ansatz: 截屏2024-04-08 下午10 20 36

How can we reproduce the issue?

In docs/tutorials/04_excited_states_solvers.ipynb, input the driver as data above.

What should happen?

It throw out an error ValueError: The number of spatial orbitals 2must be greater than number of particles of any spin kind (2, 1).

Any suggestions?

No response

mrossinek commented 2 months ago

UCC (and its variants) is currently hard-coding a check to ensure that no spin register is completely occupied: https://github.com/qiskit-community/qiskit-nature/blob/cbba76c516cbf372903a336b17fdeb2c31cd6d57/qiskit_nature/second_q/circuit/library/ansatzes/ucc.py#L394

I think that the code itself should be able to handle the case where the number of particles in a spin exactly fills that spin register but there are no unittests to ensure this. Lifting this limitation will enable this use case to run.


You can already use generalized=True which will ignore the actual occupation that you start from to run the code. But your ansatz will be longer.