qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

Sampler-based VQE for diagonal operators, plus QAOA

Open Cryoris opened this issue 2 years ago • 5 comments

Summary

Add a VQE variant based on the sampler primitive, which only allows for optimization of diagonal ("classical") Hamiltonians.

Adds QAOA based on the above. closes #8472

Details and comments

This differs from the estimator-based, standard VQE in that this version

  • takes a BaseSampler and not a BaseEstimator
  • allows for a custom aggregation function (such as CVaR)
  • keeps track of the best overall measurement (not possible/useful in estimator-based case)
  • returns samples of the final state (not possible in estimator-based case we generally have to measure in more than one basis)

Gradient support

In this PR, the gradient support has not yet been added. That's because it's not quite clear what's the best way to integrate the gradients. Here are the options we came up with, and we decided that we will first not support them and then directly implement option 4 if possible:

Option 1 The SamplingVQE takes a sampler and sampler gradient as input pro: it is consistent as it takes a sampler and a sampler gradient problem: I cannot support aggregation functions like CVaR, since I cannot easily compute the gradient if I have only access to the samples

Option 2 The SamplingVQE takes a sampler and an empty estimator gradient (i.e. without an estimator set) pro: I build the diagonal estimator inside the SamplingVQE, and plug it into the estimator gradient problem: consistency suffers, since I have to make the estimator in the gradients optional

Option 3 Make the SamplingVQE take a DiagonalEstimator and a EstimatorGradient equipped with said diagonal estimator pro: consistent problem: users have to build out the diagonal estimator, and the Sampling VQE will take an estimator

Option 4 Change how gradients work and introduce a general ParameterShift() (& co) which is not sampler or estimator specific pro: makes my life easy pro: makes users life easy as they don’t have to write out these nasty gradient names problem: doesn’t exist yet

Todo

  • [x] Support batching
  • [x] See TODOs in tests

Cryoris avatar Sep 02 '22 20:09 Cryoris

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:

  • @Qiskit/terra-core
  • @manoelmarques
  • @woodsp-ibm

qiskit-bot avatar Sep 02 '22 20:09 qiskit-bot

@Cryoris See also my DM to you for some comments

woodsp-ibm avatar Sep 06 '22 21:09 woodsp-ibm

Pull Request Test Coverage Report for Build 3154881397

  • 268 of 296 (90.54%) changed or added relevant lines in 5 files are covered.
  • 13 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.2%) to 84.593%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/algorithms/minimum_eigensolvers/qaoa.py 24 28 85.71%
qiskit/algorithms/minimum_eigensolvers/sampling_mes.py 47 53 88.68%
qiskit/algorithms/minimum_eigensolvers/sampling_vqe.py 116 122 95.08%
qiskit/algorithms/minimum_eigensolvers/diagonal_estimator.py 78 90 86.67%
<!-- Total: 268 296
Files with Coverage Reduction New Missed Lines %
qiskit/extensions/quantum_initializer/squ.py 2 79.78%
qiskit/compiler/transpiler.py 11 89.71%
<!-- Total: 13
Totals Coverage Status
Change from base Build 3154878985: 0.2%
Covered Lines: 61115
Relevant Lines: 72246

💛 - Coveralls

coveralls avatar Sep 07 '22 10:09 coveralls

This PR will also include a QAOA implementation that subclasses SamplingVQE.

declanmillar avatar Sep 14 '22 13:09 declanmillar

Needs a release note added.

woodsp-ibm avatar Sep 14 '22 16:09 woodsp-ibm