qiskit-documentation/docs/api/qiskit/0.43/qiskit.algorithms.Amplitude...

209 lines
9.6 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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: AmplitudeEstimation
description: API reference for qiskit.algorithms.AmplitudeEstimation
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.algorithms.AmplitudeEstimation
---
# AmplitudeEstimation
<Class id="qiskit.algorithms.AmplitudeEstimation" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.24/qiskit/algorithms/amplitude_estimators/ae.py" signature="AmplitudeEstimation(num_eval_qubits, phase_estimation_circuit=None, iqft=None, quantum_instance=None, sampler=None)" modifiers="class">
Bases: [`AmplitudeEstimator`](qiskit.algorithms.AmplitudeEstimator "qiskit.algorithms.amplitude_estimators.amplitude_estimator.AmplitudeEstimator")
The Quantum Phase Estimation-based Amplitude Estimation algorithm.
This class implements the original Quantum Amplitude Estimation (QAE) algorithm, introduced by \[1]. This canonical version uses quantum phase estimation along with a set of $m$ additional evaluation qubits to find an estimate $\tilde{a}$, that is restricted to the grid
$$
\tilde{a} \in \{\sin^2(\pi y / 2^m) : y = 0, ..., 2^{m-1}\}
$$
More evaluation qubits produce a finer sampling grid, therefore the accuracy of the algorithm increases with $m$.
Using a maximum likelihood post processing, this grid constraint can be circumvented. This improved estimator is implemented as well, see \[2] Appendix A for more detail.
<Admonition title="Note" type="note">
This class does not support the [`EstimationProblem.is_good_state`](qiskit.algorithms.EstimationProblem#is_good_state "qiskit.algorithms.EstimationProblem.is_good_state") property, as for phase estimation-based QAE, the oracle that identifes the good states must be encoded in the Grover operator. To set custom oracles, the [`EstimationProblem.grover_operator`](qiskit.algorithms.EstimationProblem#grover_operator "qiskit.algorithms.EstimationProblem.grover_operator") attribute can be set directly.
</Admonition>
**References**
**\[1]: Brassard, G., Hoyer, P., Mosca, M., & Tapp, A. (2000).**
Quantum Amplitude Amplification and Estimation. [arXiv:quant-ph/0005055](http://arxiv.org/abs/quant-ph/0005055).
**\[2]: Grinko, D., Gacon, J., Zoufal, C., & Woerner, S. (2019).**
Iterative Quantum Amplitude Estimation. [arXiv:1912.05559](https://arxiv.org/abs/1912.05559).
<Admonition title="Deprecated since version 0.24.0" type="danger">
`qiskit.algorithms.amplitude_estimators.ae.AmplitudeEstimation.__init__()`s argument `quantum_instance` is deprecated as of qiskit-terra 0.24.0. It will be removed no earlier than 3 months after the release date. Instead, use the `sampler` argument. See [https://qisk.it/algo\_migration](https://qisk.it/algo_migration) for a migration guide.
</Admonition>
**Parameters**
* **num\_eval\_qubits** (*int*) The number of evaluation qubits.
* **phase\_estimation\_circuit** ([*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") *| None*) The phase estimation circuit used to run the algorithm. Defaults to the standard phase estimation circuit from the circuit library, qiskit.circuit.library.PhaseEstimation when None.
* **iqft** ([*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") *| None*) The inverse quantum Fourier transform component, defaults to using a standard implementation from qiskit.circuit.library.QFT when None.
* **quantum\_instance** ([*QuantumInstance*](qiskit.utils.QuantumInstance "qiskit.utils.QuantumInstance") *|*[*Backend*](qiskit.providers.Backend "qiskit.providers.Backend") *| None*) Deprecated: The backend (or QuantumInstance) to execute the circuits on.
* **sampler** ([*BaseSampler*](qiskit.primitives.BaseSampler "qiskit.primitives.BaseSampler") *| None*) A sampler primitive to evaluate the circuits.
**Raises**
**ValueError** If the number of evaluation qubits is smaller than 1.
## Methods
<span id="qiskit-algorithms-amplitudeestimation-compute-confidence-interval" />
### compute\_confidence\_interval
<Function id="qiskit.algorithms.AmplitudeEstimation.compute_confidence_interval" signature="AmplitudeEstimation.compute_confidence_interval(result, alpha=0.05, kind='likelihood_ratio')" modifiers="static">
Compute the (1 - alpha) confidence interval.
**Parameters**
* **result** ([*AmplitudeEstimationResult*](qiskit.algorithms.AmplitudeEstimationResult "qiskit.algorithms.AmplitudeEstimationResult")) An amplitude estimation result for which to compute the confidence interval.
* **alpha** (*float*) Confidence level: compute the (1 - alpha) confidence interval.
* **kind** (*str*) The method to compute the confidence interval, can be fisher, observed\_fisher or likelihood\_ratio (default)
**Returns**
The (1 - alpha) confidence interval of the specified kind.
**Raises**
* **AquaError** If mle is not in self.\_ret.keys() (i.e. run was not called yet).
* **NotImplementedError** If the confidence interval method kind is not implemented.
**Return type**
tuple\[float, float]
</Function>
<span id="qiskit-algorithms-amplitudeestimation-compute-mle" />
### compute\_mle
<Function id="qiskit.algorithms.AmplitudeEstimation.compute_mle" signature="AmplitudeEstimation.compute_mle(result, apply_post_processing=False)" modifiers="static">
Compute the Maximum Likelihood Estimator (MLE).
**Parameters**
* **result** ([*AmplitudeEstimationResult*](qiskit.algorithms.AmplitudeEstimationResult "qiskit.algorithms.AmplitudeEstimationResult")) An amplitude estimation result object.
* **apply\_post\_processing** (*bool*) If True, apply the post processing to the MLE before returning it.
**Returns**
The MLE for the provided result object.
**Return type**
float
</Function>
<span id="qiskit-algorithms-amplitudeestimation-construct-circuit" />
### construct\_circuit
<Function id="qiskit.algorithms.AmplitudeEstimation.construct_circuit" signature="AmplitudeEstimation.construct_circuit(estimation_problem, measurement=False)">
Construct the Amplitude Estimation quantum circuit.
**Parameters**
* **estimation\_problem** ([*EstimationProblem*](qiskit.algorithms.EstimationProblem "qiskit.algorithms.amplitude_estimators.estimation_problem.EstimationProblem")) The estimation problem for which to construct the QAE circuit.
* **measurement** (*bool*) Boolean flag to indicate if measurements should be included in the circuit.
**Returns**
The QuantumCircuit object for the constructed circuit.
**Return type**
[*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.quantumcircuit.QuantumCircuit")
</Function>
<span id="qiskit-algorithms-amplitudeestimation-estimate" />
### estimate
<Function id="qiskit.algorithms.AmplitudeEstimation.estimate" signature="AmplitudeEstimation.estimate(estimation_problem)">
Run the amplitude estimation algorithm on provided estimation problem.
**Parameters**
**estimation\_problem** ([*EstimationProblem*](qiskit.algorithms.EstimationProblem "qiskit.algorithms.amplitude_estimators.estimation_problem.EstimationProblem")) The estimation problem.
**Returns**
An amplitude estimation results object.
**Raises**
* **ValueError** If state\_preparation or objective\_qubits are not set in the estimation\_problem.
* **ValueError** A quantum instance or sampler must be provided.
* [**AlgorithmError**](qiskit.algorithms.AlgorithmError "qiskit.algorithms.AlgorithmError") Sampler job run error.
**Return type**
[AmplitudeEstimationResult](qiskit.algorithms.AmplitudeEstimationResult "qiskit.algorithms.AmplitudeEstimationResult")
</Function>
<span id="qiskit-algorithms-amplitudeestimation-evaluate-measurements" />
### evaluate\_measurements
<Function id="qiskit.algorithms.AmplitudeEstimation.evaluate_measurements" signature="AmplitudeEstimation.evaluate_measurements(circuit_results, threshold=1e-06)">
Evaluate the results from the circuit simulation.
Given the probabilities from statevector simulation of the QAE circuit, compute the probabilities that the measurements y/gridpoints a are the best estimate.
**Parameters**
* **circuit\_results** (*dict\[str, int] | np.ndarray*) The circuit result from the QAE circuit. Can be either a counts dict or a statevector or a quasi-probabilities dict.
* **threshold** (*float*) Measurements with probabilities below the threshold are discarded.
**Returns**
**Dictionaries containing the a gridpoints with respective probabilities and**
y measurements with respective probabilities, in this order.
**Return type**
tuple\[dict\[float, float], dict\[int, float]]
</Function>
## Attributes
### quantum\_instance
<Attribute id="qiskit.algorithms.AmplitudeEstimation.quantum_instance">
Get the quantum instance.
<Admonition title="Deprecated since version 0.24.0" type="danger">
The property `qiskit.algorithms.amplitude_estimators.ae.AmplitudeEstimation.quantum_instance` is deprecated as of qiskit-terra 0.24.0. It will be removed no earlier than 3 months after the release date. See [https://qisk.it/algo\_migration](https://qisk.it/algo_migration) for a migration guide.
</Admonition>
**Returns**
The quantum instance used to run this algorithm.
**Type**
Deprecated
</Attribute>
### sampler
<Attribute id="qiskit.algorithms.AmplitudeEstimation.sampler">
Get the sampler primitive.
**Returns**
The sampler primitive to evaluate the circuits.
</Attribute>
</Class>