-
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
Implement eigensolvers (VQD) with primitives #8640
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:
|
Pull Request Test Coverage Report for Build 3150026480
💛 - Coveralls |
…into vqd-primitives Merge latest changes in main
|
||
prev_circs = [] | ||
for state in range(step - 1): | ||
prev_circs.append(self.ansatz.bind_parameters(prev_states[state])) |
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.
I imagine we could build up these circuits just once as we go step by step. Here it will be rebuilding (binding) them each time which will be seen as different circuits on down through the primitives. Maybe this can be some future improvement in the interests of time if its not easily changed.
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.
Will leave as a future improvement. Not resolving the conversation for that purpose.
def _build_vqd_result() -> VQDResult: | ||
|
||
result = VQDResult() | ||
result.optimal_point = [] |
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.
It seems with lists we are going beyond the typehints for VariationalAlgo. And even on the initial point getter/setter though its Sequence float I guess ideally it would be a list of initial points not a single one, though I think here we only support an single value that is used on every step.
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.
Removed extension of VariationalResult
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.
Maybe we need to think about improving initial_point as input gong forwards since I think it ought to be a list of points one for each step, maybe we support a single value, like now for all. But ideally I should be able to feed in the optimal points outcome which is a list of points so each step has its optimizer set accordingly.
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.
I also agree, I will note it as a future improvement (again, not resolving the comment to be able to find it later).
qiskit/algorithms/__init__.py
Outdated
|
||
Algorithms to find eigenvalues of an operator. For chemistry these can be used to find excited | ||
states of a molecule, and qiskit-nature has some algorithms that leverage chemistry specific | ||
knowledge to do this in that application domain. | ||
knowledge to do this in that application domain.These algorithms are pending depreciation. |
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.
knowledge to do this in that application domain.These algorithms are pending depreciation. | |
knowledge to do this in that application domain. These algorithms are pending depreciation. |
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.
I also realized it says depreciation instead of deprecation 🤣. Changing both egeinsolvers and minimum eigensolvers
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.
depreciation
Well they are losing their value as such! 🤣
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.
@ElePT Thanks for the great work!
* New eigensolver namespace * Add unittests * Remove unit test * Progress * Revert vqd changes * Restore temporary changes * Change test names * Code cleanup * More cleanup * Remove run options * Fix seed test callback * Add warning gradients * Fix style * Move aux ops evaluation to vqd * Make black * Fix cyclic imports * Fix style unit tests * Remove eigenstate from result class * Add eigenstates to init * Fix black * Add NumPyEigensolverResult * Fix lint * Add eigensolvers with primitives (VQD) * Update base class * Update numpy eigensolver * Apply changes VQE * Update * Add TODO * Remove opflow code * Update copyright * Change run_options * Add obs.eval, fix bug, add unit test, apply comments * Fix black * Fix attributes, remove gradient * Remove defaults * Fix lint, add base operator support * Add BaseOperator support and unit tests * Fix style * Fix style * Fix lint * Fix sphinx * Update qiskit/algorithms/eigensolvers/vqd.py * Update qiskit/algorithms/eigensolvers/vqd.py * Apply VQE changes * Add metadata to result * Fix old reno cross reference * fix lint * modify aux ops metadata * Add metadata to callback * Return metadata in observables evaluator * fix copyright * Update test/python/algorithms/test_numpy_eigen_solver.py * Remove opflow from vqd tests * Add optimizer result * fix tests * Fix lint * Fix black * Fix cyclic imports * Fix black againnn * Add minimally working VQE with estimator primitive implementation. No gradients, no tests etc. * Revert from dataclass results to original result classes. * Enforce positional and keyword VQE arguments. * Move aux op eval logic to function * Update docstring. * Remove max_evals_grouped. Force to set directly on optimizer. * Remove validate min import. * Make note that eval_observables will be used to eval aux ops. * Add initial vqe tests. * Have VQE inherit from VariationalAlgorithm. * Move energy evaluation to unnested function. * Construct h2_op using SparsePauliOp * Add gradient with primitives support. * Update docstrings * update broadcast handling * update eval_energy output for batching * add incomplete QNSPA test * fix batch evaluation of QNSPSA test * remove vqe callback * move estimator to first arg * remove usused imports * add minimum eigensolvers test init file * add aux ops tests and prepare for new eval_operators * no longer support account for Nones in aux_ops * correct typing for MinimumEigensolver * Compute default initial point using ansatz bounds. * Add NumPyMinimumEigensolverResult * Fix type hints * Fix type hints * Formatting * Do not store NumPyMES result inside the algo. * Provide default values for ansatz and estimator * Formatting * fix old and new batching * Add tests for NumpyMES and import in module. * Use lazy formatting in log messages * Use lazy formatting in log messages * Add back callback to VQE. * minor renaming * raise algorithm error if primitive jobs fail * Add return documentation * Improve var names and docstrings. * Apply suggestions from code review Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> Co-authored-by: dlasecki <dal@zurich.ibm.com> * minor formatting * minor formatting * Ensure evaluate_energy/gradient match Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch> * return bounds logic; fix some docstrings and minor refactor * Force keyword arguments in vqe. * Use estimate_observables function * break up numpy mes tests with subTest * formatting * remove redundant eval_aux_ops * add typehints to docstring attributes * remove usused imports * remove default ansatz * remove usused imports * update typehints * avoid changing the original ansatz * avoid changing the original ansatz * create separate function to build vqe result * Correct aux operator eignvalue type hint Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> * add variance to callback * use std_dev in callback rather than variance * formatting * return variance and shots in callback * return full metadata in callback * Move validation functions to algorithms/utils * correct the callback attribute documentation * correct the callback attribute typehint docstring * update VQE docstring * release note and pending-depreciate old algs * update vqe class docstring * Apply suggestions from code review Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> * Do not copy ansatz * Note pending depreciation of old algs * fix docstrings and imports * Fix issues with building docs * Include OptimizerResult in VQEResult * Remove trailing whitespace * Fix math notation in docstring * estimate_obervables to return metadata @ElePT +VQE * add example in release note * Update evaluate_observables docstring * Fix observables_evaluator tests. Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> * fix trotter_qrte tests and remove depreciation * formatting * remove unused import * Apply suggestions to docstring from code review Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * Update VQE docstring * Remove printing Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> * Add parameters to estimate observables * Fix estimate obs. unit test * Update arg description * Update arg description * keep equation part of sentence * dict -> dict[str, Any] * Update qiskit/algorithms/optimizers/spsa.py Apply suggestion Imamichi-san * introduce FilterType and aux_operator_eigenvalues -> aux_operators_evaluated * Correct typehint Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com> * Adapt to VQE * Update qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py * Pull from main * Remove change vqe * Refine docs, typehints, remove opflow * add check for PauliSumOp * Fix import * reformat test * Remove metadata unit tests * Add operator tests * Reformat tests * Fix observables eval test * Apply initial feedback * Change numpy eig. aux ops metadata * Apply review comments * Fix unittests * Update reno * Apply review comments * Fix result names, typehints * Fix docs Co-authored-by: Manoel Marques <manoel.marques@ibm.com> Co-authored-by: Declan Millar <declan.millar@ibm.com> Co-authored-by: dlasecki <dal@zurich.ibm.com> Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* New eigensolver namespace * Add unittests * Remove unit test * Progress * Revert vqd changes * Restore temporary changes * Change test names * Code cleanup * More cleanup * Remove run options * Fix seed test callback * Add warning gradients * Fix style * Move aux ops evaluation to vqd * Make black * Fix cyclic imports * Fix style unit tests * Remove eigenstate from result class * Add eigenstates to init * Fix black * Add NumPyEigensolverResult * Fix lint * Add eigensolvers with primitives (VQD) * Update base class * Update numpy eigensolver * Apply changes VQE * Update * Add TODO * Remove opflow code * Update copyright * Change run_options * Add obs.eval, fix bug, add unit test, apply comments * Fix black * Fix attributes, remove gradient * Remove defaults * Fix lint, add base operator support * Add BaseOperator support and unit tests * Fix style * Fix style * Fix lint * Fix sphinx * Update qiskit/algorithms/eigensolvers/vqd.py * Update qiskit/algorithms/eigensolvers/vqd.py * Apply VQE changes * Add metadata to result * Fix old reno cross reference * fix lint * modify aux ops metadata * Add metadata to callback * Return metadata in observables evaluator * fix copyright * Update test/python/algorithms/test_numpy_eigen_solver.py * Remove opflow from vqd tests * Add optimizer result * fix tests * Fix lint * Fix black * Fix cyclic imports * Fix black againnn * Add minimally working VQE with estimator primitive implementation. No gradients, no tests etc. * Revert from dataclass results to original result classes. * Enforce positional and keyword VQE arguments. * Move aux op eval logic to function * Update docstring. * Remove max_evals_grouped. Force to set directly on optimizer. * Remove validate min import. * Make note that eval_observables will be used to eval aux ops. * Add initial vqe tests. * Have VQE inherit from VariationalAlgorithm. * Move energy evaluation to unnested function. * Construct h2_op using SparsePauliOp * Add gradient with primitives support. * Update docstrings * update broadcast handling * update eval_energy output for batching * add incomplete QNSPA test * fix batch evaluation of QNSPSA test * remove vqe callback * move estimator to first arg * remove usused imports * add minimum eigensolvers test init file * add aux ops tests and prepare for new eval_operators * no longer support account for Nones in aux_ops * correct typing for MinimumEigensolver * Compute default initial point using ansatz bounds. * Add NumPyMinimumEigensolverResult * Fix type hints * Fix type hints * Formatting * Do not store NumPyMES result inside the algo. * Provide default values for ansatz and estimator * Formatting * fix old and new batching * Add tests for NumpyMES and import in module. * Use lazy formatting in log messages * Use lazy formatting in log messages * Add back callback to VQE. * minor renaming * raise algorithm error if primitive jobs fail * Add return documentation * Improve var names and docstrings. * Apply suggestions from code review Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> Co-authored-by: dlasecki <dal@zurich.ibm.com> * minor formatting * minor formatting * Ensure evaluate_energy/gradient match Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch> * return bounds logic; fix some docstrings and minor refactor * Force keyword arguments in vqe. * Use estimate_observables function * break up numpy mes tests with subTest * formatting * remove redundant eval_aux_ops * add typehints to docstring attributes * remove usused imports * remove default ansatz * remove usused imports * update typehints * avoid changing the original ansatz * avoid changing the original ansatz * create separate function to build vqe result * Correct aux operator eignvalue type hint Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> * add variance to callback * use std_dev in callback rather than variance * formatting * return variance and shots in callback * return full metadata in callback * Move validation functions to algorithms/utils * correct the callback attribute documentation * correct the callback attribute typehint docstring * update VQE docstring * release note and pending-depreciate old algs * update vqe class docstring * Apply suggestions from code review Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> * Do not copy ansatz * Note pending depreciation of old algs * fix docstrings and imports * Fix issues with building docs * Include OptimizerResult in VQEResult * Remove trailing whitespace * Fix math notation in docstring * estimate_obervables to return metadata @ElePT +VQE * add example in release note * Update evaluate_observables docstring * Fix observables_evaluator tests. Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> * fix trotter_qrte tests and remove depreciation * formatting * remove unused import * Apply suggestions to docstring from code review Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * Update VQE docstring * Remove printing Co-authored-by: ElePT <57907331+ElePT@users.noreply.github.com> * Add parameters to estimate observables * Fix estimate obs. unit test * Update arg description * Update arg description * keep equation part of sentence * dict -> dict[str, Any] * Update qiskit/algorithms/optimizers/spsa.py Apply suggestion Imamichi-san * introduce FilterType and aux_operator_eigenvalues -> aux_operators_evaluated * Correct typehint Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com> * Adapt to VQE * Update qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py * Pull from main * Remove change vqe * Refine docs, typehints, remove opflow * add check for PauliSumOp * Fix import * reformat test * Remove metadata unit tests * Add operator tests * Reformat tests * Fix observables eval test * Apply initial feedback * Change numpy eig. aux ops metadata * Apply review comments * Fix unittests * Update reno * Apply review comments * Fix result names, typehints * Fix docs Co-authored-by: Manoel Marques <manoel.marques@ibm.com> Co-authored-by: Declan Millar <declan.millar@ibm.com> Co-authored-by: dlasecki <dal@zurich.ibm.com> Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Summary
This PR addresses #8491 and #8492 and provides an implementation of VQD using the new primitive interfaces. The new implementation comes with a change of namespace for the whole eigensolvers module (from
eigen_solvers
toeigensolvers
), which is more consistent with the naming conventions used throughout the stack.Closes #8491
Closes #8492
Details and comments
Blocked by:
Closely related to (but not blocked by):
To ensure consistency with the changes made in VQE (#8702), the following elements have been removed:
eigenstate
that used to be part of theEigensolverResult
. To reproduce this one may use a Sampler and the optimal point from VQD outside the algorithm.property
andprint_settings
method.initial_point
, which requires it for theVariationalAlgorithm
interface).expectation
andinclude_custom
. These are not required anymore when using anEstimator
.Additionally, the following changes have been applied:
Gradient
through the VQD intialization. This option will be on hold untilFidelityGradients
using primitives are enabled.NumPyEigensolverResult
class that allows theNumPyEigensolver
to still return theeigenstate
.This PR also fixes a bug found in
qiskit/algorithms/observables_evaluator.py
where thevariance
/shots
are not correctly extracted from theestimator
metadata
, and adds a corresponding unit test to verify the fix.TO-DO:
TO-AGREE-ON:
EigensolverResult
, adding variance/shots from aux. ops, changing aux ops return type (only eigenvalue). Blocked by VQE implementation with estimator primitive #8702.