Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCC and fully occupied MOs (Fix for issue #1277) #1286

Merged
merged 10 commits into from
Dec 1, 2023

Conversation

julenl
Copy link
Contributor

@julenl julenl commented Nov 27, 2023

Summary

Improved the functionality of UCC a little bit, to work if only one of the spin registers is fully occupied.

Details and comments

The configuration check looked for whether any number of alpha or beta orbitals (length of the spin register) was greater or equals than the number of particles.
Obviously, there cannot be more particles than spin orbitals, and in order to handle this case, I updated the previous any(n >= ... to any(n > ....
For handling case where both alpha and beta are the same as the number of particles (i.e. (2, 2) for the He2 molecule), I created a new raise condition, notifying that the function is still not implemented.
Implementing this option will probably involve dealing with the empty excitation list at line 339.
For the case where either alpha or beta is equals to the number of particles (i.e. H-He molecule), it should just pass through.

The configuration check looked for whether any number of alpha or beta orbitals was greater or equals than the number of particles.
Obviously, there cannot be more particles than spin orbitals, and in order to handle this case, I updated the previous `any(n >= ...` to `any(n > ...`. 
For handling case where both alpha and beta are the same as the number of particles (i.e. He2 molecule), I created a new raise condition, notifying that the function is still not implemented.
For the case where either alpha or beta is equals to the number of particles (i.e. H-He molecule), it should just pass through.
@coveralls
Copy link

coveralls commented Nov 27, 2023

Pull Request Test Coverage Report for Build 7057038901

  • 2 of 5 (40.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 86.753%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_nature/second_q/circuit/library/ansatzes/ucc.py 2 5 40.0%
Totals Coverage Status
Change from base Build 7020358022: -0.02%
Covered Lines: 8769
Relevant Lines: 10108

💛 - Coveralls

Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks like a good start. Can you please also do the following changes?

  • add a unittest which asserts that the behavior works as intended
  • verify whether the docstrings on the section of which errors are being raised needs to be updated
  • add a release note (see here for instructions)

And finally:

  • please also check all of the above for the HartreeFock initial state and add a unittest if it already works (just to be certain that it won't break in the future)

Added a test case for HeH molecule, with (alpha, beta) = (2, 1). This should work after the changes in ucc.py
The tests complained because of the spelling of a molecule in a comment. And I reformatted a little.
Formatted the indentations correctly following the suggestions of black
@julenl
Copy link
Contributor Author

julenl commented Nov 30, 2023

So, @mrossinek

  • Unit test for a system equivalent to the "single H" molecule with spin register (1, 0) added
  • Docstrings do not need update, because the raised error corresponds to an internal method
  • Release note added
  • The HartreeFock one does not have this issue, because it directly checks for "n spatial orbitals" > "particles in spin register"

Deleted unnecessary parts.
mrossinek
mrossinek previously approved these changes Dec 1, 2023
Copy link
Member

@mrossinek mrossinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me 👍


On a side note: I noticed that none of the errors which _check_configuration (and _check_ucc_configuration) might raise when raise_on_failure=True are documented.. I guess this does not show up, because these are all part of internal methods, which get called under the hood in Qiskit's BlueprintCircuit (which is a base-class of these circuits incl. HartreeFock).

We should probably at some point look into addressing this documentation-wise.

@mrossinek mrossinek merged commit c815e54 into qiskit-community:main Dec 1, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behavior of HartreeFock and UCC for fully occupied orbitals
4 participants