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

Fix bug in result creation and add instantiation of EFGSS to how-to #268

Merged
merged 13 commits into from
Jun 20, 2023

Conversation

caleb-johnson
Copy link
Collaborator

@caleb-johnson caleb-johnson commented Jun 17, 2023

Resolves #132
Resolves #247

This PR fixes a bug which was preventing the EFResults from being properly populated in certain cases, such as when we include orbitals_to_reduce argument to EFGSSolver

It also introduces an instantiation of the EFGroundStateSolver in the bitstring reduction how-to. Users need to pass in the orbitals to reduce here, as well as the ansatz, so that the observable can be properly reduced as well. This has been a point of confusion, so adding this step should clear this confusion up.

@github-actions
Copy link

github-actions bot commented Jun 17, 2023

Pull Request Test Coverage Report for Build 5326993381

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 89.908%

Totals Coverage Status
Change from base Build 5326803671: 0.3%
Covered Lines: 2334
Relevant Lines: 2596

💛 - Coveralls

@@ -9,15 +9,6 @@
"In this guide, we apply Entanglement Forging to compute the energy of a $\\mathrm{H}_2\\mathrm{O}$ molecule. We reduce the number of orbitals in the problem, in turn reducing the number of qubits needed in each circuit, following the logic given in the [explanatory material](../explanation/index.rst)."
]
},
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Trimming down unnecessary explaining in how-to's here.

@@ -43,6 +44,7 @@
from .entanglement_forging_operator import EntanglementForgingOperator
from .entanglement_forging_ground_state_solver import (
EntanglementForgingGroundStateSolver,
EntanglementForgingResult,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shouldnt have to go all the way into the EFGSSolver to get the main result type of this tool. Adding it here

@@ -317,14 +316,11 @@ def solve(

# Create the EntanglementForgingResult from the results from the
# results of eigenvalue minimization and other meta information
min_eigsolver_result = MinimumEigensolverResult()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unnecessary and also buggy. Just removing this unnecessary conversion fixes the bug

"driver = PySCFDriver(\n",
" f\"O 0.0 0.0 0.0; H {H1_x} 0.0 0.0; H {H2_x} {H2_y} 0.0\", basis=\"sto6g\"\n",
")\n",
"driver.run()\n",
"problem = driver.to_problem(basis=ElectronicBasis.AO)"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This actually needs to be instantiated in the MO basis, which is the default

"source": [
"solver = EntanglementForgingGroundStateSolver(\n",
" ansatz=ansatz,\n",
" orbitals_to_reduce=orbitals_to_reduce,\n",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to tell the EFGSS how to split the observable to match the reduced ansatz via the orbitals_to_reduce arg. This is a crucial step and should be included here in this how-to

Comment on lines +320 to +321
result.eigenvalues = np.asarray([optimal_evaluation.eigenvalue])
result.eigenstates = [(optimal_evaluation.eigenstate, None)]
Copy link
Member

Choose a reason for hiding this comment

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

Why are eigenvalues and eigenstates plural? There is an eigenvalue (singular) property on MinimumEigensolverResult but I don't see eigenstates there or in EntanglementForgingResult. And why is eigenstates a 2-tuple? (Interesting to note that this didn't break any tests.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why are eigenvalues and eigenstates plural? There is an eigenvalue (singular) property on MinimumEigensolverResult but I don't see eigenstates there or in EntanglementForgingResult. And why is eigenstates a 2-tuple? (Interesting to note that this didn't break any tests.)

https://github.com/qiskit-community/qiskit-nature/blob/14ff6490c09af7091b90d1c38a99815a92b93a83/qiskit_nature/second_q/problems/eigenstate_result.py#L62-L63

The groundstate and groundenergy properties (the ones we really care about) are derived from these fields. groundenergy is the first element in the eigenvalues list, and groundstate is the first index of the first index of eigenstates. It didn't break any tests bc we've been using EigenstateResult as a base class the whole time.

Your comment brings up a larger question of whether we can break the dependency on this class. This would be in-line with all of the dependencies we've broken with Nature in the EFGSSolver, so I think the answer is yes. I've opened #275 to track this.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. You clarified the source of my confusion, namely, that EntanglementForgingResult derives from EigenstateResult (which is in Qiskit Nature), not MinimumEigensolverResult (which is in Qiskit Terra).

Co-authored-by: Jim Garrison <garrison@ibm.com>
Copy link
Member

@garrison garrison left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this. It's always nice to close issues that we know have tripped up multiple people. 🎉

@caleb-johnson caleb-johnson merged commit 665196f into main Jun 20, 2023
@caleb-johnson caleb-johnson deleted the ef-how-to branch June 20, 2023 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
2 participants