qiskit-documentation/docs/api/qiskit/0.27/qiskit.algorithms.Hamiltoni...

92 lines
6.3 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: HamiltonianPhaseEstimation
description: API reference for qiskit.algorithms.HamiltonianPhaseEstimation
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.algorithms.HamiltonianPhaseEstimation
---
# qiskit.algorithms.HamiltonianPhaseEstimation
<Class id="qiskit.algorithms.HamiltonianPhaseEstimation" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.17/qiskit/algorithms/phase_estimators/hamiltonian_phase_estimation.py" signature="HamiltonianPhaseEstimation(num_evaluation_qubits, quantum_instance=None)" modifiers="class">
Run the Quantum Phase Estimation algorithm to find the eigenvalues of a Hermitian operator.
This class is nearly the same as [`PhaseEstimation`](qiskit.algorithms.PhaseEstimation "qiskit.algorithms.PhaseEstimation"), differing only in that the input in that class is a unitary operator, whereas here the input is a Hermitian operator from which a unitary will be obtained by scaling and exponentiating. The scaling is performed in order to prevent the phases from wrapping around $2\pi$. The problem of estimating eigenvalues $\lambda_j$ of the Hermitian operator $H$ is solved by running a circuit representing
$$
\exp(i b H) |\psi\rangle = \sum_j \exp(i b \lambda_j) c_j |\lambda_j\rangle,
$$
where the input state is
$$
|\psi\rangle = \sum_j c_j |\lambda_j\rangle,
$$
and $\lambda_j$ are the eigenvalues of $H$.
Here, $b$ is a scaling factor sufficiently large to map positive $\lambda$ to $[0,\pi)$ and negative $\lambda$ to $[\pi,2\pi)$. Each time the circuit is run, one measures a phase corresponding to $lambda_j$ with probability $|c_j|^2$.
If $H$ is a Pauli sum, the bound $b$ is computed from the sum of the absolute values of the coefficients of the terms. There is no way to reliably recover eigenvalues from phases very near the endpoints of these intervals. Because of this you should be aware that for degenerate cases, such as $H=Z$, the eigenvalues $\pm 1$ will be mapped to the same phase, $\pi$, and so cannot be distinguished. In this case, you need to specify a larger bound as an argument to the method `estimate`.
This class uses and works together with [`PhaseEstimationScale`](qiskit.algorithms.PhaseEstimationScale "qiskit.algorithms.PhaseEstimationScale") to manage scaling the Hamiltonian and the phases that are obtained by the QPE algorithm. This includes setting, or computing, a bound on the eigenvalues of the operator, using this bound to obtain a scale factor, scaling the operator, and shifting and scaling the measured phases to recover the eigenvalues.
Note that, although we speak of “evolving” the state according the the Hamiltonian, in the present algorithm, we are not actually considering time evolution. Rather, the role of time is played by the scaling factor, which is chosen to best extract the eigenvalues of the Hamiltonian.
A few of the ideas in the algorithm may be found in Ref. \[1].
**Reference:**
**\[1]: Quantum phase estimation of multiple eigenvalues for small-scale (noisy) experiments**
T.E. OBrien, B. Tarasinski, B.M. Terhal [arXiv:1809.09697](https://arxiv.org/abs/1809.09697)
**Parameters**
* **num\_evaluation\_qubits** (`int`) The number of qubits used in estimating the phase. The phase will be estimated as a binary string with this many bits.
* **quantum\_instance** (`Union`\[`QuantumInstance`, `BaseBackend`, `None`]) The quantum instance on which the circuit will be run.
### \_\_init\_\_
<Function id="qiskit.algorithms.HamiltonianPhaseEstimation.__init__" signature="__init__(num_evaluation_qubits, quantum_instance=None)">
**Parameters**
* **num\_evaluation\_qubits** (`int`) The number of qubits used in estimating the phase. The phase will be estimated as a binary string with this many bits.
* **quantum\_instance** (`Union`\[`QuantumInstance`, `BaseBackend`, `None`]) The quantum instance on which the circuit will be run.
</Function>
## Methods
| | |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| [`__init__`](#qiskit.algorithms.HamiltonianPhaseEstimation.__init__ "qiskit.algorithms.HamiltonianPhaseEstimation.__init__")(num\_evaluation\_qubits\[, …]) | **type num\_evaluation\_qubits**`int` |
| [`estimate`](#qiskit.algorithms.HamiltonianPhaseEstimation.estimate "qiskit.algorithms.HamiltonianPhaseEstimation.estimate")(hamiltonian\[, state\_preparation, …]) | Run the Hamiltonian phase estimation algorithm. |
### estimate
<Function id="qiskit.algorithms.HamiltonianPhaseEstimation.estimate" signature="estimate(hamiltonian, state_preparation=None, evolution=None, bound=None)">
Run the Hamiltonian phase estimation algorithm.
**Parameters**
* **hamiltonian** (`OperatorBase`) A Hermitian operator.
* **state\_preparation** (`Optional`\[`StateFn`]) The `StateFn` to be prepared, whose eigenphase will be measured. If this parameter is omitted, no preparation circuit will be run and input state will be the all-zero state in the computational basis.
* **evolution** (`Optional`\[`EvolutionBase`]) An evolution converter that generates a unitary from `hamiltonian`. If `None`, then the default `PauliTrotterEvolution` is used.
* **bound** (`Optional`\[`float`]) An upper bound on the absolute value of the eigenvalues of `hamiltonian`. If omitted, then `hamiltonian` must be a Pauli sum, or a `PauliOp`, in which case a bound will be computed. If `hamiltonian` is a `MatrixOp`, then `bound` may not be `None`. The tighter the bound, the higher the resolution of computed phases.
**Return type**
`HamiltonianPhaseEstimationResult`
**Returns**
HamiltonianPhaseEstimationResult instance containing the result of the estimation and diagnostic information.
**Raises**
* **ValueError** If `bound` is `None` and `hamiltonian` is not a Pauli sum, i.e. a `PauliSumOp` or a `SummedOp` whose terms are of type `PauliOp`.
* **TypeError** If `evolution` is not of type `EvolutionBase`.
</Function>
</Class>