-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
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:
|
betas
calculation for betas
calculation on VQD
and add async.
This should have a reno and we probably want to release this in a bug fix release too right? |
betas
calculation on VQD
and add async.betas
calculation on VQD
and async. cost evaluation
Pull Request Test Coverage Report for Build 3632367696
💛 - 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 |
There was a problem hiding this comment.
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?
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 |
There was a problem hiding this comment.
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,...)?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Co-authored-by: Julien Gacon <gaconju@gmail.com>
There was a problem hiding this 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!
* Fix betas * Add async * Fix seed test * Fix lint * Add reno * Add enumerate Co-authored-by: Julien Gacon <gaconju@gmail.com> * Apply suggestions Julien * Fix lint Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit f339f71)
…9253) * Fix betas * Add async * Fix seed test * Fix lint * Add reno * Add enumerate Co-authored-by: Julien Gacon <gaconju@gmail.com> * Apply suggestions Julien * Fix lint Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit f339f71) Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> Co-authored-by: Julien Gacon <gaconju@gmail.com>
…iskit#9245) * Fix betas * Add async * Fix seed test * Fix lint * Add reno * Add enumerate Co-authored-by: Julien Gacon <gaconju@gmail.com> * Apply suggestions Julien * Fix lint Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
This PR fixes the
betas
auto-evaluation onVQD
forPauliSumOp
operators (pending deprecation), and adds support for beta auto-evaluation withSparsePauliOp
. The code was supposed to iterate over primitive coefficients, and was instead obtaining a series ofPauliSumOp
coefficients (which were always1.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 testSparsePauliOp
imports.