Skip to content
Merged
Show file tree
Hide file tree
Changes from 183 commits
Commits
Show all changes
192 commits
Select commit Hold shift + click to select a range
0c0cb19
New eigensolver namespace
ElePT Aug 30, 2022
375e3ed
Add unittests
ElePT Aug 30, 2022
5efc989
Remove unit test
ElePT Aug 30, 2022
e536c37
Progress
ElePT Sep 5, 2022
f50d168
Merge branch 'Qiskit:main' into vqd-primitives
ElePT Sep 5, 2022
36dba08
Merge branch 'Qiskit:main' into vqd-primitives
ElePT Sep 7, 2022
5023517
Pass unit test, copy paste aux_ops_evaluator
ElePT Sep 7, 2022
a5eddd9
Merge branch 'vqd-primitives' of https://github.com/ElePT/qiskit-terr…
ElePT Sep 7, 2022
dc3c930
Revert vqd changes
ElePT Sep 7, 2022
333a7be
Restore temporary changes
ElePT Sep 7, 2022
bc8d6a7
Change test names
ElePT Sep 7, 2022
65937f6
Code cleanup
ElePT Sep 7, 2022
bc79fe1
More cleanup
ElePT Sep 7, 2022
0306a7c
Remove run options
ElePT Sep 7, 2022
1931640
Fix seed test callback
ElePT Sep 7, 2022
e6045bf
Add warning gradients
ElePT Sep 7, 2022
7f84ab9
Fix style
ElePT Sep 7, 2022
21d99ac
Move aux ops evaluation to vqd
ElePT Sep 7, 2022
86a825b
Make black
ElePT Sep 7, 2022
eb8a62b
Fix cyclic imports
ElePT Sep 8, 2022
3d2385d
Fix style unit tests
ElePT Sep 8, 2022
a4b113a
Remove eigenstate from result class
ElePT Sep 8, 2022
9e53bb0
Add eigenstates to init
ElePT Sep 8, 2022
e37683e
Fix black
ElePT Sep 8, 2022
cedd94e
Add NumPyEigensolverResult
ElePT Sep 9, 2022
37cf8d6
Fix lint
ElePT Sep 12, 2022
7e45462
Add eigensolvers with primitives (VQD)
ElePT Sep 13, 2022
4a7dd49
Update base class
ElePT Sep 14, 2022
f87f710
Update numpy eigensolver
ElePT Sep 14, 2022
7202995
Apply changes VQE
ElePT Sep 14, 2022
d8b3fc3
Update
ElePT Sep 14, 2022
000952b
Add TODO
ElePT Sep 14, 2022
e34db39
Remove opflow code
ElePT Sep 14, 2022
b1b7fa5
Update copyright
ElePT Sep 14, 2022
468f453
Change run_options
ElePT Sep 14, 2022
e978848
Merge branch 'main' of https://github.com/ElePT/qiskit-terra into vqd…
ElePT Sep 16, 2022
14015ec
Add obs.eval, fix bug, add unit test, apply comments
ElePT Sep 16, 2022
aba6304
Fix black
ElePT Sep 19, 2022
f9cdb64
Fix attributes, remove gradient
ElePT Sep 19, 2022
26486af
Remove defaults
ElePT Sep 19, 2022
4dfdfa5
Fix lint, add base operator support
ElePT Sep 19, 2022
d27f181
Add BaseOperator support and unit tests
ElePT Sep 20, 2022
8d1fb27
Fix style
ElePT Sep 20, 2022
58e6d00
Fix style
ElePT Sep 20, 2022
e3f2cb1
Fix lint
ElePT Sep 20, 2022
5392106
Fix sphinx
ElePT Sep 20, 2022
3d1ff28
Update qiskit/algorithms/eigensolvers/vqd.py
ElePT Sep 21, 2022
56a688e
Update qiskit/algorithms/eigensolvers/vqd.py
ElePT Sep 21, 2022
e8bb9b6
Apply VQE changes
ElePT Sep 21, 2022
a977581
Add metadata to result
ElePT Sep 22, 2022
afbb339
Fix old reno cross reference
manoelmarques Sep 22, 2022
9c83941
fix lint
manoelmarques Sep 22, 2022
eba2efc
modify aux ops metadata
ElePT Sep 23, 2022
d4f17c8
Merge branch 'vqd-primitives' of https://github.com/ElePT/qiskit-terr…
ElePT Sep 23, 2022
380cabb
Add metadata to callback
ElePT Sep 23, 2022
f81b2f8
Return metadata in observables evaluator
ElePT Sep 23, 2022
3bda3f6
fix copyright
ElePT Sep 26, 2022
aac01cd
Merge branch 'main' of https://github.com/ElePT/qiskit-terra into vqd…
ElePT Sep 26, 2022
894ffdb
Merge branch 'main' into vqd-primitives
ElePT Sep 26, 2022
c45bcb4
Update test/python/algorithms/test_numpy_eigen_solver.py
ElePT Sep 26, 2022
368830b
Merge branch 'vqd-primitives' of https://github.com/ElePT/qiskit-terr…
ElePT Sep 26, 2022
a082ff3
Remove opflow from vqd tests
ElePT Sep 26, 2022
3918147
Add optimizer result
ElePT Sep 26, 2022
7479342
fix tests
ElePT Sep 26, 2022
511217a
Fix lint
ElePT Sep 26, 2022
3f738ff
Fix black
ElePT Sep 26, 2022
12ac516
Fix cyclic imports
ElePT Sep 26, 2022
58495fd
Fix black againnn
ElePT Sep 26, 2022
0a35c1a
Add minimally working VQE with estimator primitive implementation.
declanmillar Aug 31, 2022
ac88412
Revert from dataclass results to original result classes.
declanmillar Sep 1, 2022
3fd8f3c
Enforce positional and keyword VQE arguments.
declanmillar Sep 2, 2022
9b987cc
Move aux op eval logic to function
declanmillar Sep 2, 2022
378aac8
Update docstring.
declanmillar Sep 2, 2022
629e6de
Remove max_evals_grouped. Force to set directly on optimizer.
declanmillar Sep 5, 2022
499c35e
Remove validate min import.
declanmillar Sep 5, 2022
689e2c8
Make note that eval_observables will be used to eval aux ops.
declanmillar Sep 5, 2022
1a43460
Add initial vqe tests.
declanmillar Sep 5, 2022
8d6bd1c
Have VQE inherit from VariationalAlgorithm.
declanmillar Sep 5, 2022
f1ffb54
Move energy evaluation to unnested function.
declanmillar Sep 5, 2022
fcb2846
Construct h2_op using SparsePauliOp
declanmillar Sep 5, 2022
903614c
Add gradient with primitives support.
declanmillar Sep 6, 2022
27d02b0
Update docstrings
declanmillar Sep 6, 2022
813a344
update broadcast handling
declanmillar Sep 7, 2022
70ba38b
update eval_energy output for batching
declanmillar Sep 7, 2022
36dfd3b
add incomplete QNSPA test
declanmillar Sep 7, 2022
3c79faa
fix batch evaluation of QNSPSA test
declanmillar Sep 7, 2022
4695cc3
remove vqe callback
declanmillar Sep 7, 2022
105c5db
move estimator to first arg
declanmillar Sep 7, 2022
9131190
remove usused imports
declanmillar Sep 7, 2022
c726397
add minimum eigensolvers test init file
declanmillar Sep 7, 2022
cfdea10
add aux ops tests and prepare for new eval_operators
declanmillar Sep 8, 2022
68788ca
no longer support account for Nones in aux_ops
declanmillar Sep 9, 2022
7ab77e4
correct typing for MinimumEigensolver
declanmillar Sep 9, 2022
632b3aa
Compute default initial point using ansatz bounds.
declanmillar Sep 12, 2022
6aa5373
Add NumPyMinimumEigensolverResult
declanmillar Sep 12, 2022
a002467
Fix type hints
declanmillar Sep 12, 2022
c83c7b9
Fix type hints
declanmillar Sep 12, 2022
98648f0
Formatting
declanmillar Sep 12, 2022
2ed3ff3
Do not store NumPyMES result inside the algo.
declanmillar Sep 12, 2022
aced280
Provide default values for ansatz and estimator
declanmillar Sep 12, 2022
9459603
Formatting
declanmillar Sep 12, 2022
3623ad7
fix old and new batching
declanmillar Sep 12, 2022
93213dc
Add tests for NumpyMES and import in module.
declanmillar Sep 12, 2022
5defcd5
Use lazy formatting in log messages
declanmillar Sep 12, 2022
b7c4a74
Use lazy formatting in log messages
declanmillar Sep 12, 2022
af47dea
Add back callback to VQE.
declanmillar Sep 13, 2022
f682616
minor renaming
declanmillar Sep 13, 2022
16dc12c
raise algorithm error if primitive jobs fail
declanmillar Sep 13, 2022
994247b
Add return documentation
declanmillar Sep 13, 2022
688f9f1
Improve var names and docstrings.
declanmillar Sep 14, 2022
a9d6d41
Apply suggestions from code review
declanmillar Sep 15, 2022
6e99b34
minor formatting
declanmillar Sep 15, 2022
6abff88
minor formatting
declanmillar Sep 15, 2022
0b5c185
Ensure evaluate_energy/gradient match
declanmillar Sep 15, 2022
e2dafa8
return bounds logic; fix some docstrings and minor refactor
declanmillar Sep 16, 2022
1eb2329
Force keyword arguments in vqe.
declanmillar Sep 16, 2022
c05cdbc
Use estimate_observables function
declanmillar Sep 16, 2022
4cbbe67
break up numpy mes tests with subTest
declanmillar Sep 20, 2022
455981c
formatting
declanmillar Sep 20, 2022
ae66409
remove redundant eval_aux_ops
declanmillar Sep 20, 2022
3c17862
add typehints to docstring attributes
declanmillar Sep 20, 2022
067cd07
remove usused imports
declanmillar Sep 20, 2022
3acf449
remove default ansatz
declanmillar Sep 20, 2022
b3db998
remove usused imports
declanmillar Sep 20, 2022
1990045
update typehints
declanmillar Sep 20, 2022
86e7b86
avoid changing the original ansatz
declanmillar Sep 21, 2022
bd0c97d
avoid changing the original ansatz
declanmillar Sep 21, 2022
7cdd399
create separate function to build vqe result
declanmillar Sep 21, 2022
c204a7e
Correct aux operator eignvalue type hint
declanmillar Sep 21, 2022
91fe427
add variance to callback
declanmillar Sep 22, 2022
7afa7eb
use std_dev in callback rather than variance
declanmillar Sep 23, 2022
ac2871a
formatting
declanmillar Sep 23, 2022
0e0a5d4
return variance and shots in callback
declanmillar Sep 23, 2022
8d238bf
return full metadata in callback
declanmillar Sep 23, 2022
a2cd35a
Move validation functions to algorithms/utils
declanmillar Sep 23, 2022
4dab8bc
correct the callback attribute documentation
declanmillar Sep 23, 2022
78d21c5
correct the callback attribute typehint docstring
declanmillar Sep 23, 2022
d9f5cb2
update VQE docstring
declanmillar Sep 23, 2022
eaea3e6
release note and pending-depreciate old algs
declanmillar Sep 23, 2022
183c20c
update vqe class docstring
declanmillar Sep 23, 2022
d01d47b
Apply suggestions from code review
declanmillar Sep 26, 2022
f06a74c
Do not copy ansatz
declanmillar Sep 26, 2022
9cfb1b2
Note pending depreciation of old algs
declanmillar Sep 26, 2022
3ec9dba
fix docstrings and imports
declanmillar Sep 26, 2022
4d7a0fd
Fix issues with building docs
declanmillar Sep 26, 2022
4a16903
Include OptimizerResult in VQEResult
declanmillar Sep 26, 2022
6a15540
Remove trailing whitespace
declanmillar Sep 26, 2022
4fdf4f5
Fix math notation in docstring
declanmillar Sep 26, 2022
355d887
estimate_obervables to return metadata @ElePT +VQE
declanmillar Sep 26, 2022
b0b8f37
add example in release note
declanmillar Sep 26, 2022
c144688
Update evaluate_observables docstring
declanmillar Sep 26, 2022
8fed152
Fix observables_evaluator tests.
declanmillar Sep 26, 2022
682d3cb
fix trotter_qrte tests and remove depreciation
declanmillar Sep 26, 2022
2976ac9
formatting
declanmillar Sep 26, 2022
998121f
remove unused import
declanmillar Sep 26, 2022
8aeed79
Apply suggestions to docstring from code review
declanmillar Sep 26, 2022
483fbd2
Update VQE docstring
declanmillar Sep 26, 2022
7e2ee3d
Remove printing
declanmillar Sep 26, 2022
31219bf
Add parameters to estimate observables
ElePT Sep 26, 2022
511caca
Fix estimate obs. unit test
ElePT Sep 26, 2022
34246d3
Update arg description
declanmillar Sep 26, 2022
12f6426
Update arg description
declanmillar Sep 26, 2022
efc0565
keep equation part of sentence
declanmillar Sep 26, 2022
b1c55ca
dict -> dict[str, Any]
declanmillar Sep 26, 2022
50eba6d
Merge branch 'main' into vqe-with-estimator-primitive
woodsp-ibm Sep 27, 2022
18b5b63
Update qiskit/algorithms/optimizers/spsa.py
ElePT Sep 27, 2022
0e0ebac
introduce FilterType and aux_operator_eigenvalues -> aux_operators_ev…
declanmillar Sep 27, 2022
3357ebe
Correct typehint
declanmillar Sep 27, 2022
c8edaa4
Fix conflicts
ElePT Sep 27, 2022
41f36a8
Adapt to VQE
ElePT Sep 27, 2022
95546c4
Update qiskit/algorithms/eigen_solvers/numpy_eigen_solver.py
ElePT Sep 27, 2022
4ae9406
Merge branch 'vqd-primitives' of https://github.com/ElePT/qiskit-terr…
ElePT Sep 27, 2022
231db6b
Pull from main
ElePT Sep 27, 2022
3d15a42
Merge branch 'main' into vqd-primitives
ElePT Sep 27, 2022
94b18da
Remove change vqe
ElePT Sep 27, 2022
6258287
Refine docs, typehints, remove opflow
ElePT Sep 27, 2022
17094d1
add check for PauliSumOp
ElePT Sep 27, 2022
eba717c
Fix import
ElePT Sep 27, 2022
0ad2f28
reformat test
ElePT Sep 27, 2022
058596f
Remove metadata unit tests
ElePT Sep 27, 2022
a9b38af
Add operator tests
ElePT Sep 27, 2022
dfbd96f
Reformat tests
ElePT Sep 27, 2022
6323f9e
Fix observables eval test
ElePT Sep 27, 2022
4cf6d59
Apply initial feedback
ElePT Sep 28, 2022
1761d70
Change numpy eig. aux ops metadata
ElePT Sep 28, 2022
9cee0fb
Apply review comments
ElePT Sep 28, 2022
8089108
Fix unittests
ElePT Sep 28, 2022
701edec
Update reno
ElePT Sep 28, 2022
918050e
Apply review comments
ElePT Sep 28, 2022
512ec3b
Fix result names, typehints
ElePT Sep 28, 2022
ccb24b3
Fix docs
ElePT Sep 28, 2022
2ab563b
Merge branch 'main' into vqd-primitives
mergify[bot] Sep 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions qiskit/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
MaximumLikelihoodAmplitudeEstimationResult


Eigensolvers
------------
Eigen Solvers
-------------
Comment thread
ElePT marked this conversation as resolved.

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
Expand All @@ -93,6 +93,17 @@
NumPyEigensolver
VQD

Eigensolvers
------------

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.

.. autosummary::
:toctree: ../stubs/

eigensolvers

Evolvers
--------
Expand Down Expand Up @@ -384,6 +395,7 @@
"HamiltonianPhaseEstimation",
"HamiltonianPhaseEstimationResult",
"VQD",
"VQDResult",
Comment thread
ElePT marked this conversation as resolved.
"PhaseEstimationScale",
"PhaseEstimation",
"PhaseEstimationResult",
Expand Down
53 changes: 53 additions & 0 deletions qiskit/algorithms/eigensolvers/__init__.py
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`)
=====================================================================

Copy link
Copy Markdown
Member

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 eigensolvers module link in the algorithms.__init__.py file so as to link in the docs here since a user will have to do from qiskit.algorithms.eigensolvers import VQD as 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.

@ElePT ElePT Sep 16, 2022

Copy link
Copy Markdown
Contributor Author

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__.py and algorithms.__init__.py, where I changed the title for the legacy module from Eigensolvers to Eigen Solvers in the docstring, so that I can now list the eigensolvers module there under Eigensolvers.

.. 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",
]
106 changes: 106 additions & 0 deletions qiskit/algorithms/eigensolvers/eigensolver.py
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
Comment thread
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(
Comment thread
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
Loading