-
Notifications
You must be signed in to change notification settings - Fork 3k
Implement eigensolvers (VQD) with primitives #8640
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
Merged
Merged
Changes from 35 commits
Commits
Show all changes
192 commits
Select commit
Hold shift + click to select a range
0c0cb19
New eigensolver namespace
ElePT 375e3ed
Add unittests
ElePT 5efc989
Remove unit test
ElePT e536c37
Progress
ElePT f50d168
Merge branch 'Qiskit:main' into vqd-primitives
ElePT 36dba08
Merge branch 'Qiskit:main' into vqd-primitives
ElePT 5023517
Pass unit test, copy paste aux_ops_evaluator
ElePT a5eddd9
Merge branch 'vqd-primitives' of https://github.com/ElePT/qiskit-terr…
ElePT dc3c930
Revert vqd changes
ElePT 333a7be
Restore temporary changes
ElePT bc8d6a7
Change test names
ElePT 65937f6
Code cleanup
ElePT bc79fe1
More cleanup
ElePT 0306a7c
Remove run options
ElePT 1931640
Fix seed test callback
ElePT e6045bf
Add warning gradients
ElePT 7f84ab9
Fix style
ElePT 21d99ac
Move aux ops evaluation to vqd
ElePT 86a825b
Make black
ElePT eb8a62b
Fix cyclic imports
ElePT 3d2385d
Fix style unit tests
ElePT a4b113a
Remove eigenstate from result class
ElePT 9e53bb0
Add eigenstates to init
ElePT e37683e
Fix black
ElePT cedd94e
Add NumPyEigensolverResult
ElePT 37cf8d6
Fix lint
ElePT 7e45462
Add eigensolvers with primitives (VQD)
ElePT 4a7dd49
Update base class
ElePT f87f710
Update numpy eigensolver
ElePT 7202995
Apply changes VQE
ElePT d8b3fc3
Update
ElePT 000952b
Add TODO
ElePT e34db39
Remove opflow code
ElePT b1b7fa5
Update copyright
ElePT 468f453
Change run_options
ElePT e978848
Merge branch 'main' of https://github.com/ElePT/qiskit-terra into vqd…
ElePT 14015ec
Add obs.eval, fix bug, add unit test, apply comments
ElePT aba6304
Fix black
ElePT f9cdb64
Fix attributes, remove gradient
ElePT 26486af
Remove defaults
ElePT 4dfdfa5
Fix lint, add base operator support
ElePT d27f181
Add BaseOperator support and unit tests
ElePT 8d1fb27
Fix style
ElePT 58e6d00
Fix style
ElePT e3f2cb1
Fix lint
ElePT 5392106
Fix sphinx
ElePT 3d1ff28
Update qiskit/algorithms/eigensolvers/vqd.py
ElePT 56a688e
Update qiskit/algorithms/eigensolvers/vqd.py
ElePT e8bb9b6
Apply VQE changes
ElePT a977581
Add metadata to result
ElePT afbb339
Fix old reno cross reference
manoelmarques 9c83941
fix lint
manoelmarques eba2efc
modify aux ops metadata
ElePT d4f17c8
Merge branch 'vqd-primitives' of https://github.com/ElePT/qiskit-terr…
ElePT 380cabb
Add metadata to callback
ElePT f81b2f8
Return metadata in observables evaluator
ElePT 3bda3f6
fix copyright
ElePT aac01cd
Merge branch 'main' of https://github.com/ElePT/qiskit-terra into vqd…
ElePT 894ffdb
Merge branch 'main' into vqd-primitives
ElePT c45bcb4
Update test/python/algorithms/test_numpy_eigen_solver.py
ElePT 368830b
Merge branch 'vqd-primitives' of https://github.com/ElePT/qiskit-terr…
ElePT a082ff3
Remove opflow from vqd tests
ElePT 3918147
Add optimizer result
ElePT 7479342
fix tests
ElePT 511217a
Fix lint
ElePT 3f738ff
Fix black
ElePT 12ac516
Fix cyclic imports
ElePT 58495fd
Fix black againnn
ElePT 0a35c1a
Add minimally working VQE with estimator primitive implementation.
declanmillar ac88412
Revert from dataclass results to original result classes.
declanmillar 3fd8f3c
Enforce positional and keyword VQE arguments.
declanmillar 9b987cc
Move aux op eval logic to function
declanmillar 378aac8
Update docstring.
declanmillar 629e6de
Remove max_evals_grouped. Force to set directly on optimizer.
declanmillar 499c35e
Remove validate min import.
declanmillar 689e2c8
Make note that eval_observables will be used to eval aux ops.
declanmillar 1a43460
Add initial vqe tests.
declanmillar 8d6bd1c
Have VQE inherit from VariationalAlgorithm.
declanmillar f1ffb54
Move energy evaluation to unnested function.
declanmillar fcb2846
Construct h2_op using SparsePauliOp
declanmillar 903614c
Add gradient with primitives support.
declanmillar 27d02b0
Update docstrings
declanmillar 813a344
update broadcast handling
declanmillar 70ba38b
update eval_energy output for batching
declanmillar 36dfd3b
add incomplete QNSPA test
declanmillar 3c79faa
fix batch evaluation of QNSPSA test
declanmillar 4695cc3
remove vqe callback
declanmillar 105c5db
move estimator to first arg
declanmillar 9131190
remove usused imports
declanmillar c726397
add minimum eigensolvers test init file
declanmillar cfdea10
add aux ops tests and prepare for new eval_operators
declanmillar 68788ca
no longer support account for Nones in aux_ops
declanmillar 7ab77e4
correct typing for MinimumEigensolver
declanmillar 632b3aa
Compute default initial point using ansatz bounds.
declanmillar 6aa5373
Add NumPyMinimumEigensolverResult
declanmillar a002467
Fix type hints
declanmillar c83c7b9
Fix type hints
declanmillar 98648f0
Formatting
declanmillar 2ed3ff3
Do not store NumPyMES result inside the algo.
declanmillar aced280
Provide default values for ansatz and estimator
declanmillar 9459603
Formatting
declanmillar 3623ad7
fix old and new batching
declanmillar 93213dc
Add tests for NumpyMES and import in module.
declanmillar 5defcd5
Use lazy formatting in log messages
declanmillar b7c4a74
Use lazy formatting in log messages
declanmillar af47dea
Add back callback to VQE.
declanmillar f682616
minor renaming
declanmillar 16dc12c
raise algorithm error if primitive jobs fail
declanmillar 994247b
Add return documentation
declanmillar 688f9f1
Improve var names and docstrings.
declanmillar a9d6d41
Apply suggestions from code review
declanmillar 6e99b34
minor formatting
declanmillar 6abff88
minor formatting
declanmillar 0b5c185
Ensure evaluate_energy/gradient match
declanmillar e2dafa8
return bounds logic; fix some docstrings and minor refactor
declanmillar 1eb2329
Force keyword arguments in vqe.
declanmillar c05cdbc
Use estimate_observables function
declanmillar 4cbbe67
break up numpy mes tests with subTest
declanmillar 455981c
formatting
declanmillar ae66409
remove redundant eval_aux_ops
declanmillar 3c17862
add typehints to docstring attributes
declanmillar 067cd07
remove usused imports
declanmillar 3acf449
remove default ansatz
declanmillar b3db998
remove usused imports
declanmillar 1990045
update typehints
declanmillar 86e7b86
avoid changing the original ansatz
declanmillar bd0c97d
avoid changing the original ansatz
declanmillar 7cdd399
create separate function to build vqe result
declanmillar c204a7e
Correct aux operator eignvalue type hint
declanmillar 91fe427
add variance to callback
declanmillar 7afa7eb
use std_dev in callback rather than variance
declanmillar ac2871a
formatting
declanmillar 0e0a5d4
return variance and shots in callback
declanmillar 8d238bf
return full metadata in callback
declanmillar a2cd35a
Move validation functions to algorithms/utils
declanmillar 4dab8bc
correct the callback attribute documentation
declanmillar 78d21c5
correct the callback attribute typehint docstring
declanmillar d9f5cb2
update VQE docstring
declanmillar eaea3e6
release note and pending-depreciate old algs
declanmillar 183c20c
update vqe class docstring
declanmillar d01d47b
Apply suggestions from code review
declanmillar f06a74c
Do not copy ansatz
declanmillar 9cfb1b2
Note pending depreciation of old algs
declanmillar 3ec9dba
fix docstrings and imports
declanmillar 4d7a0fd
Fix issues with building docs
declanmillar 4a16903
Include OptimizerResult in VQEResult
declanmillar 6a15540
Remove trailing whitespace
declanmillar 4fdf4f5
Fix math notation in docstring
declanmillar 355d887
estimate_obervables to return metadata @ElePT +VQE
declanmillar b0b8f37
add example in release note
declanmillar c144688
Update evaluate_observables docstring
declanmillar 8fed152
Fix observables_evaluator tests.
declanmillar 682d3cb
fix trotter_qrte tests and remove depreciation
declanmillar 2976ac9
formatting
declanmillar 998121f
remove unused import
declanmillar 8aeed79
Apply suggestions to docstring from code review
declanmillar 483fbd2
Update VQE docstring
declanmillar 7e2ee3d
Remove printing
declanmillar 31219bf
Add parameters to estimate observables
ElePT 511caca
Fix estimate obs. unit test
ElePT 34246d3
Update arg description
declanmillar 12f6426
Update arg description
declanmillar efc0565
keep equation part of sentence
declanmillar b1c55ca
dict -> dict[str, Any]
declanmillar 50eba6d
Merge branch 'main' into vqe-with-estimator-primitive
woodsp-ibm 18b5b63
Update qiskit/algorithms/optimizers/spsa.py
ElePT 0e0ebac
introduce FilterType and aux_operator_eigenvalues -> aux_operators_ev…
declanmillar 3357ebe
Correct typehint
declanmillar c8edaa4
Fix conflicts
ElePT 41f36a8
Adapt to VQE
ElePT 95546c4
Update qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py
ElePT 4ae9406
Merge branch 'vqd-primitives' of https://github.com/ElePT/qiskit-terr…
ElePT 231db6b
Pull from main
ElePT 3d15a42
Merge branch 'main' into vqd-primitives
ElePT 94b18da
Remove change vqe
ElePT 6258287
Refine docs, typehints, remove opflow
ElePT 17094d1
add check for PauliSumOp
ElePT eba717c
Fix import
ElePT 0ad2f28
reformat test
ElePT 058596f
Remove metadata unit tests
ElePT a9b38af
Add operator tests
ElePT dfbd96f
Reformat tests
ElePT 6323f9e
Fix observables eval test
ElePT 4cf6d59
Apply initial feedback
ElePT 1761d70
Change numpy eig. aux ops metadata
ElePT 9cee0fb
Apply review comments
ElePT 8089108
Fix unittests
ElePT 701edec
Update reno
ElePT 918050e
Apply review comments
ElePT 512ec3b
Fix result names, typehints
ElePT ccb24b3
Fix docs
ElePT 2ab563b
Merge branch 'main' into vqd-primitives
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2020. | ||
| # | ||
| # This code is licensed under the Apache License, Version 2.0. You may | ||
| # obtain a copy of this license in the LICENSE.txt file in the root directory | ||
| # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
| # | ||
| # Any modifications or derivative works of this code must retain this | ||
| # copyright notice, and modified files need to carry a notice indicating | ||
| # that they have been altered from the originals. | ||
|
|
||
| """ Eigensolvers Package """ | ||
|
|
||
| from .numpy_eigensolver import NumPyEigensolver | ||
| from .eigensolver import Eigensolver, EigensolverResult | ||
| from .vqd import VQD, VQDResult | ||
|
|
||
| __all__ = ["NumPyEigensolver", "Eigensolver", "EigensolverResult", "VQD", "VQDResult"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2022. | ||
| # | ||
| # This code is licensed under the Apache License, Version 2.0. You may | ||
| # obtain a copy of this license in the LICENSE.txt file in the root directory | ||
| # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
| # | ||
| # Any modifications or derivative works of this code must retain this | ||
| # copyright notice, and modified files need to carry a notice indicating | ||
| # that they have been altered from the originals. | ||
|
|
||
| """The eigensolver interface and result.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| import numpy as np | ||
|
|
||
| from qiskit.opflow import PauliSumOp | ||
| from qiskit.quantum_info.operators.base_operator import BaseOperator | ||
|
|
||
| from ..algorithm_result import AlgorithmResult | ||
| from ..list_or_dict import ListOrDict | ||
|
|
||
|
|
||
| class Eigensolver(ABC): | ||
| """The eigensolver interface. | ||
|
|
||
| Algorithms that can compute eigenvalues for an operator | ||
| may implement this interface to allow different algorithms to be | ||
| used interchangeably. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def compute_eigenvalues( | ||
| self, | ||
| operator: BaseOperator | PauliSumOp, | ||
| aux_operators: ListOrDict[BaseOperator | PauliSumOp] | None = None, | ||
| ) -> "EigensolverResult": | ||
| """ | ||
| Computes eigenvalues. ``operator`` and ``aux_operators`` can be supplied here and, | ||
| if not ``None``, will override any already set into algorithm so it can be reused with | ||
|
ElePT marked this conversation as resolved.
Outdated
|
||
| different operators. While an ``operator`` is required by algorithms, ``aux_operators`` | ||
| are optional. To 'remove' a previous ``aux_operators`` array use an empty list here. | ||
|
|
||
| Args: | ||
| operator: Qubit operator of the observable | ||
| aux_operators: Optional list of auxiliary operators to be evaluated with the | ||
| eigenstate of the minimum eigenvalue main result and their expectation values | ||
| returned. For instance, in chemistry these can be dipole operators and total particle | ||
| count operators, so we can get values for these at the ground state. | ||
|
|
||
| Returns: | ||
| An eigensolver result. | ||
| """ | ||
| return EigensolverResult() | ||
|
|
||
| @classmethod | ||
| def supports_aux_operators(cls) -> bool: | ||
| """Whether computing the expectation value of auxiliary operators is supported. | ||
|
|
||
| If the eigensolver computes the eigenvalues of the main operator, then it can compute | ||
| the expectation value of the aux_operators for that state. Otherwise they will be ignored. | ||
|
|
||
| Returns: | ||
| ``True`` if ``aux_operator`` expectations can be evaluated, ``False`` otherwise | ||
| """ | ||
| return False | ||
|
|
||
|
|
||
| class EigensolverResult(AlgorithmResult): | ||
| """Eigensolver result.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| super().__init__() | ||
| self._eigenvalues = None | ||
| self._aux_operator_eigenvalues = None | ||
|
|
||
| @property | ||
| def eigenvalues(self) -> np.ndarray | None: | ||
| """Return the eigenvalues.""" | ||
| return self._eigenvalues | ||
|
|
||
| @eigenvalues.setter | ||
| def eigenvalues(self, value: np.ndarray) -> None: | ||
| """Set the eigenvalues.""" | ||
| self._eigenvalues = value | ||
|
|
||
| @property | ||
| def aux_operator_eigenvalues(self) -> list[ListOrDict[tuple[complex, complex]]] | None: | ||
| """Return the aux operator expectation values. | ||
|
|
||
| These values are in fact tuples formatted as (mean, standard deviation). | ||
| """ | ||
| return self._aux_operator_eigenvalues | ||
|
|
||
| @aux_operator_eigenvalues.setter | ||
| def aux_operator_eigenvalues(self, value: list[ListOrDict[tuple[complex, complex]]]) -> None: | ||
| """Set the aux operator eigenvalues.""" | ||
| self._aux_operator_eigenvalues = value | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think we need a
eigensolversmodule link in the algorithms.__init__.py file so as to link in the docs here since a user will have to do fromqiskit.algorithms.eigensolvers import VQDas we cannot simply import these to the algorithms at present since the names collide with the existing algos. As such the doctrsing here in this file here needs to be expanded to list the set of algorithms/results for eigensolvers similar to how its done in algorithms init.Uh oh!
There was an error while loading. Please reload this page.
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.
That is very true. I have updated the both
eigensolvers.__init__.pyandalgorithms.__init__.py, where I changed the title for the legacy module fromEigensolverstoEigen Solversin the docstring, so that I can now list theeigensolversmodule there underEigensolvers.