-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Changes from 183 commits
0c0cb19
375e3ed
5efc989
e536c37
f50d168
36dba08
5023517
a5eddd9
dc3c930
333a7be
bc8d6a7
65937f6
bc79fe1
0306a7c
1931640
e6045bf
7f84ab9
21d99ac
86a825b
eb8a62b
3d2385d
a4b113a
9e53bb0
e37683e
cedd94e
37cf8d6
7e45462
4a7dd49
f87f710
7202995
d8b3fc3
000952b
e34db39
b1b7fa5
468f453
e978848
14015ec
aba6304
f9cdb64
26486af
4dfdfa5
d27f181
8d1fb27
58e6d00
e3f2cb1
5392106
3d1ff28
56a688e
e8bb9b6
a977581
afbb339
9c83941
eba2efc
d4f17c8
380cabb
f81b2f8
3bda3f6
aac01cd
894ffdb
c45bcb4
368830b
a082ff3
3918147
7479342
511217a
3f738ff
12ac516
58495fd
0a35c1a
ac88412
3fd8f3c
9b987cc
378aac8
629e6de
499c35e
689e2c8
1a43460
8d6bd1c
f1ffb54
fcb2846
903614c
27d02b0
813a344
70ba38b
36dfd3b
3c79faa
4695cc3
105c5db
9131190
c726397
cfdea10
68788ca
7ab77e4
632b3aa
6aa5373
a002467
c83c7b9
98648f0
2ed3ff3
aced280
9459603
3623ad7
93213dc
5defcd5
b7c4a74
af47dea
f682616
16dc12c
994247b
688f9f1
a9d6d41
6e99b34
6abff88
0b5c185
e2dafa8
1eb2329
c05cdbc
4cbbe67
455981c
ae66409
3c17862
067cd07
3acf449
b3db998
1990045
86e7b86
bd0c97d
7cdd399
c204a7e
91fe427
7afa7eb
ac2871a
0e0a5d4
8d238bf
a2cd35a
4dab8bc
78d21c5
d9f5cb2
eaea3e6
183c20c
d01d47b
f06a74c
9cfb1b2
3ec9dba
4d7a0fd
4a16903
6a15540
4fdf4f5
355d887
b0b8f37
c144688
8fed152
682d3cb
2976ac9
998121f
8aeed79
483fbd2
7e2ee3d
31219bf
511caca
34246d3
12f6426
efc0565
b1c55ca
50eba6d
18b5b63
0e0ebac
3357ebe
c8edaa4
41f36a8
95546c4
4ae9406
231db6b
3d15a42
94b18da
6258287
17094d1
eba717c
0ad2f28
058596f
a9b38af
dfbd96f
6323f9e
4cf6d59
1761d70
9cee0fb
8089108
701edec
918050e
512ec3b
ccb24b3
2ab563b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # 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. | ||
|
|
||
| """ | ||
| ===================================================================== | ||
| Eigensolvers Package (:mod:`qiskit.algorithms.eigensolvers`) | ||
| ===================================================================== | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is very true. I have updated the both |
||
| .. currentmodule:: qiskit.algorithms.eigensolvers | ||
|
|
||
| Eigensolvers | ||
| ================ | ||
|
|
||
| .. autosummary:: | ||
| :toctree: ../stubs/ | ||
|
|
||
| Eigensolver | ||
| NumPyEigensolver | ||
| VQD | ||
|
|
||
| Results | ||
| ======= | ||
|
|
||
| .. autosummary:: | ||
| :toctree: ../stubs/ | ||
|
|
||
| EigensolverResult | ||
| NumPyEigensolverResult | ||
| VQDResult | ||
|
|
||
| """ | ||
|
|
||
| from .numpy_eigensolver import NumPyEigensolver, NumPyEigensolverResult | ||
| from .eigensolver import Eigensolver, EigensolverResult | ||
| from .vqd import VQD, VQDResult | ||
|
|
||
| __all__ = [ | ||
| "NumPyEigensolver", | ||
| "NumPyEigensolverResult", | ||
| "Eigensolver", | ||
| "EigensolverResult", | ||
| "VQD", | ||
| "VQDResult", | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # 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 | ||
| from typing import Any | ||
| 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. The ``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( | ||
|
ElePT marked this conversation as resolved.
Outdated
|
||
| self, | ||
| ) -> list[ListOrDict[tuple[complex, dict[str, Any]]]] | None: | ||
| """Return the aux operator expectation values. | ||
|
|
||
| These values are in fact tuples formatted as (mean, metadata). | ||
| """ | ||
| return self._aux_operator_eigenvalues | ||
|
|
||
| @aux_operator_eigenvalues.setter | ||
| def aux_operator_eigenvalues( | ||
| self, value: list[ListOrDict[tuple[complex, dict[str, Any]]]] | ||
| ) -> None: | ||
| """Set the aux operator eigenvalues.""" | ||
| self._aux_operator_eigenvalues = value | ||
Uh oh!
There was an error while loading. Please reload this page.