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 betas calculation on VQD and async. cost evaluation #9245

Merged
merged 9 commits into from
Dec 6, 2022

Conversation

ElePT
Copy link
Contributor

@ElePT ElePT commented Dec 5, 2022

Summary

This PR fixes the betas auto-evaluation on VQD for PauliSumOp operators (pending deprecation), and adds support for beta auto-evaluation with SparsePauliOp. The code was supposed to iterate over primitive coefficients, and was instead obtaining a series of PauliSumOp coefficients (which were always 1.0).

In addition to the betas fix, this PR includes a change in the energy eval. method to leverage the async capabilities of the primitives (the job results are retrieved after both jobs are submitted, instead of sequentially submitting and retrieving results), as this was the initial intention.

Details and comments

The unit tests have also been updated not to use PauliSumOp internally, and to test SparsePauliOp imports.

@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

@ElePT ElePT changed the title Fix betas calculation for Fix betas calculation on VQD and add async. Dec 5, 2022
@woodsp-ibm woodsp-ibm added Changelog: Bugfix Include in the "Fixed" section of the changelog mod: algorithms Related to the Algorithms module labels Dec 5, 2022
@woodsp-ibm
Copy link
Member

This should have a reno and we probably want to release this in a bug fix release too right?

@ElePT ElePT changed the title Fix betas calculation on VQD and add async. Fix betas calculation on VQD and async. cost evaluation Dec 5, 2022
@coveralls
Copy link

coveralls commented Dec 5, 2022

Pull Request Test Coverage Report for Build 3632367696

  • 17 of 20 (85.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.001%) to 84.599%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/algorithms/eigensolvers/vqd.py 17 20 85.0%
Files with Coverage Reduction New Missed Lines %
qiskit/algorithms/eigensolvers/vqd.py 1 96.23%
Totals Coverage Status
Change from base Build 3632367272: 0.001%
Covered Lines: 63154
Relevant Lines: 74651

💛 - Coveralls

@@ -227,15 +228,19 @@ def compute_eigenvalues(
if self.betas is None:
if isinstance(operator, PauliSumOp):
upper_bound = abs(operator.coeff) * sum(
abs(operation.coeff) for operation in operator
abs(operation.primitive.coeffs) for operation in operator
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this simplified to the following?

Suggested change
abs(operation.primitive.coeffs) for operation in operator
np.abs(operator.primitive.coeffs)

Or maybe even just cast to a SparsePauliOp for the whole function?

if isinstance(operator, PauliSumOp):
    operator = operator.coeff * operator.primitive


try:
estimator_result = estimator_job.result()
values = estimator_result.values + total_cost
Copy link
Contributor

Choose a reason for hiding this comment

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

Not blocking but would it be better to take the summation out of the try block to distinguish between the estimator failing and the addition failing (due to e.g. wrong types, or the result being None,...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@@ -116,7 +115,16 @@ def test_full_spectrum(self):
result.eigenvalues.real, self.h2_energy_excited, decimal=2
)

@data(H2_PAULI, H2_OP)
def test_betas_autoeval(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way we could test the autoevaluation itself? This here would also fail if something else in the algorithm is going wrong 🙂 What about e.g. checking the log?

Copy link
Contributor Author

@ElePT ElePT Dec 6, 2022

Choose a reason for hiding this comment

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

Yeah... fair enough, I did check the log but didn't include it in the test.

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

LGTM thanks for the fix!

@Cryoris Cryoris added stable backport potential The bug might be minimal and/or import enough to be port to stable automerge labels Dec 6, 2022
@mergify mergify bot merged commit f339f71 into Qiskit:main Dec 6, 2022
mergify bot pushed a commit that referenced this pull request Dec 6, 2022
* Fix betas

* Add async

* Fix seed test

* Fix lint

* Add reno

* Add enumerate

Co-authored-by: Julien Gacon <[email protected]>

* Apply suggestions Julien

* Fix lint

Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit f339f71)
@ElePT ElePT deleted the fix-vqd-betas branch December 7, 2022 09:16
mergify bot added a commit that referenced this pull request Dec 7, 2022
…9253)

* Fix betas

* Add async

* Fix seed test

* Fix lint

* Add reno

* Add enumerate

Co-authored-by: Julien Gacon <[email protected]>

* Apply suggestions Julien

* Fix lint

Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit f339f71)

Co-authored-by: ElePT <[email protected]>
Co-authored-by: Julien Gacon <[email protected]>
Cryoris added a commit to Cryoris/qiskit-terra that referenced this pull request Jan 12, 2023
)

* Fix betas

* Add async

* Fix seed test

* Fix lint

* Add reno

* Add enumerate

Co-authored-by: Julien Gacon <[email protected]>

* Apply suggestions Julien

* Fix lint

Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
ElePT added a commit to ElePT/qiskit that referenced this pull request Jun 27, 2023
)

* Fix betas

* Add async

* Fix seed test

* Fix lint

* Add reno

* Add enumerate

Co-authored-by: Julien Gacon <[email protected]>

* Apply suggestions Julien

* Fix lint

Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
ElePT added a commit to ElePT/qiskit-algorithms-test that referenced this pull request Jul 17, 2023
…iskit#9245)

* Fix betas

* Add async

* Fix seed test

* Fix lint

* Add reno

* Add enumerate

Co-authored-by: Julien Gacon <[email protected]>

* Apply suggestions Julien

* Fix lint

Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: algorithms Related to the Algorithms module stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants