Skip to content

Commit

Permalink
dict -> dict[str, Any]
Browse files Browse the repository at this point in the history
  • Loading branch information
declanmillar committed Sep 26, 2022
1 parent 9f1ad39 commit 55e6ca6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
21 changes: 11 additions & 10 deletions qiskit/algorithms/minimum_eigensolvers/vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import logging
from time import time
from collections.abc import Callable, Sequence
from typing import Any

import numpy as np

Expand Down Expand Up @@ -95,10 +96,10 @@ def my_minimizer(fun, x0, jac=None, bounds=None) -> OptimizerResult:
:class:`.Minimizer` protocol.
gradient (BaseEstimatorGradient | None): An optional estimator gradient to be used with the
optimizer.
callback (Callable[[int, np.ndarray, float, dict], None] | None): A callback that can access
the intermediate data at each optimization step. These data are: the evaluation count,
the optimizer parameters for the ansatz, the evaluated mean, and the metadata
dictionary.
callback (Callable[[int, np.ndarray, float, dict[str, Any]], None] | None): A callback that
can access the intermediate data at each optimization step. These data are: the
evaluation count, the optimizer parameters for the ansatz, the evaluated mean, and the
metadata dictionary.
References:
[1] Peruzzo et al, "A variational eigenvalue solver on a quantum processor"
Expand All @@ -113,7 +114,7 @@ def __init__(
*,
gradient: BaseEstimatorGradient | None = None,
initial_point: Sequence[float] | None = None,
callback: Callable[[int, np.ndarray, float, dict], None] | None = None,
callback: Callable[[int, np.ndarray, float, dict[str, Any]], None] | None = None,
) -> None:
r"""
Args:
Expand All @@ -124,11 +125,11 @@ def __init__(
can either be a Qiskit :class:`.Optimizer` or a callable implementing the
:class:`.Minimizer` protocol.
gradient: An optional estimator gradient to be used with the optimizer.
initial_point: An optional initial point (i.e. initial parameter values) for the optimizer.
The length of the initial point must match the number of :attr:`ansatz` parameters.
If ``None``, a random point will be generated within certain parameter bounds.
``VQE`` will look to the ansatz for these bounds. If the ansatz does not specify
bounds, bounds of :math:`-2\pi`, :math:`2\pi` will be used.
initial_point: An optional initial point (i.e. initial parameter values) for the
optimizer. The length of the initial point must match the number of :attr:`ansatz`
parameters. If ``None``, a random point will be generated within certain parameter
bounds. ``VQE`` will look to the ansatz for these bounds. If the ansatz does not
specify bounds, bounds of :math:`-2\pi`, :math:`2\pi` will be used.
callback: A callback that can access the intermediate data at each optimization step.
These data are: the evaluation count, the optimizer parameters for the ansatz, the
estimated value, and the metadata dictionary.
Expand Down
5 changes: 3 additions & 2 deletions qiskit/algorithms/observables_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import annotations
from collections.abc import Sequence
from typing import Any

import numpy as np

Expand All @@ -31,7 +32,7 @@ def estimate_observables(
observables: ListOrDict[BaseOperator | PauliSumOp],
parameter_values: Sequence[float] | None = None,
threshold: float = 1e-12,
) -> ListOrDict[tuple[complex, dict]]:
) -> ListOrDict[tuple[complex, dict[str, Any]]]:
"""
Accepts a sequence of operators and calculates their expectation values - means
and metadata. They are calculated with respect to a quantum state provided. A user
Expand Down Expand Up @@ -94,7 +95,7 @@ def _handle_zero_ops(
def _prepare_result(
observables_results: list[tuple[complex, dict]],
observables: ListOrDict[BaseOperator | PauliSumOp],
) -> ListOrDict[tuple[complex, dict]]:
) -> ListOrDict[tuple[complex, dict[str, Any]]]:
"""
Prepares a list of tuples of eigenvalues and metadata tuples from
``observables_results`` and ``observables``.
Expand Down

0 comments on commit 55e6ca6

Please sign in to comment.