qiskit.aqua.algorithms.AmplitudeEstimation
class AmplitudeEstimation(num_eval_qubits, state_preparation=None, grover_operator=None, objective_qubits=None, post_processing=None, phase_estimation_circuit=None, iqft=None, quantum_instance=None, a_factory=None, q_factory=None, i_objective=None)
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 additional evaluation qubits to find an estimate , that is restricted to the grid
More evaluation qubits produce a finer sampling grid, therefore the accuracy of the algorithm increases with .
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.
References
[1]: Brassard, G., Hoyer, P., Mosca, M., & Tapp, A. (2000).
Quantum Amplitude Amplification and Estimation. arXiv:quant-ph/0005055.
[2]: Grinko, D., Gacon, J., Zoufal, C., & Woerner, S. (2019).
Iterative Quantum Amplitude Estimation. arXiv:1912.05559.
Parameters
- num_eval_qubits (
int
) – The number of evaluation qubits. - state_preparation (
Union
[QuantumCircuit
,CircuitFactory
,None
]) – A circuit preparing the input state, referred to as . - grover_operator (
Union
[QuantumCircuit
,CircuitFactory
,None
]) – The Grover operator used as unitary in the phase estimation circuit. - objective_qubits (
Optional
[List
[int
]]) – A list of qubit indices to specify the oracle in the Grover operator, if the Grover operator is not supplied. A measurement outcome is classified as ‘good’ state if all objective qubits are in state , otherwise it is classified as ‘bad’. - post_processing (
Optional
[Callable
[[float
],float
]]) – A mapping applied to the result of the algorithm , usually used to map the estimate to a target interval. - phase_estimation_circuit (
Optional
[QuantumCircuit
]) – The phase estimation circuit used to run the algorithm. Defaults to the standard phase estimation circuit from the circuit library, qiskit.circuit.library.PhaseEstimation. - iqft (
Optional
[QuantumCircuit
]) – The inverse quantum Fourier transform component, defaults to using a standard implementation from qiskit.circuit.library.QFT when None. - quantum_instance (
Union
[QuantumInstance
,Backend
,BaseBackend
,None
]) – The backend (or QuantumInstance) to execute the circuits on. - a_factory (
Optional
[CircuitFactory
]) – Deprecated, usestate_preparation
. The CircuitFactory subclass object representing the problem unitary. - q_factory (
Optional
[CircuitFactory
]) – Deprecated, usegrover_operator
. The CircuitFactory subclass object representing an amplitude estimation sample (based on a_factory). - i_objective (
Optional
[int
]) – Deprecated, useobjective_qubits
. The index of the objective qubit, i.e. the qubit marking ‘good’ solutions with the state and ‘bad’ solutions with the state .
__init__
__init__(num_eval_qubits, state_preparation=None, grover_operator=None, objective_qubits=None, post_processing=None, phase_estimation_circuit=None, iqft=None, quantum_instance=None, a_factory=None, q_factory=None, i_objective=None)
Parameters
- num_eval_qubits (
int
) – The number of evaluation qubits. - state_preparation (
Union
[QuantumCircuit
,CircuitFactory
,None
]) – A circuit preparing the input state, referred to as . - grover_operator (
Union
[QuantumCircuit
,CircuitFactory
,None
]) – The Grover operator used as unitary in the phase estimation circuit. - objective_qubits (
Optional
[List
[int
]]) – A list of qubit indices to specify the oracle in the Grover operator, if the Grover operator is not supplied. A measurement outcome is classified as ‘good’ state if all objective qubits are in state , otherwise it is classified as ‘bad’. - post_processing (
Optional
[Callable
[[float
],float
]]) – A mapping applied to the result of the algorithm , usually used to map the estimate to a target interval. - phase_estimation_circuit (
Optional
[QuantumCircuit
]) – The phase estimation circuit used to run the algorithm. Defaults to the standard phase estimation circuit from the circuit library, qiskit.circuit.library.PhaseEstimation. - iqft (
Optional
[QuantumCircuit
]) – The inverse quantum Fourier transform component, defaults to using a standard implementation from qiskit.circuit.library.QFT when None. - quantum_instance (
Union
[QuantumInstance
,Backend
,BaseBackend
,None
]) – The backend (or QuantumInstance) to execute the circuits on. - a_factory (
Optional
[CircuitFactory
]) – Deprecated, usestate_preparation
. The CircuitFactory subclass object representing the problem unitary. - q_factory (
Optional
[CircuitFactory
]) – Deprecated, usegrover_operator
. The CircuitFactory subclass object representing an amplitude estimation sample (based on a_factory). - i_objective (
Optional
[int
]) – Deprecated, useobjective_qubits
. The index of the objective qubit, i.e. the qubit marking ‘good’ solutions with the state and ‘bad’ solutions with the state .
Methods
__init__ (num_eval_qubits[, …]) | type num_eval_qubitsint |
confidence_interval (alpha[, kind]) | Compute the (1 - alpha) confidence interval. |
construct_circuit ([measurement]) | Construct the Amplitude Estimation quantum circuit. |
is_good_state (measurement) | Determine whether a given state is a good state. |
post_processing (value) | Post processing of the raw amplitude estimation output . |
run ([quantum_instance]) | Execute the algorithm with selected backend. |
set_backend (backend, **kwargs) | Sets backend with configuration. |
Attributes
a_factory | Get the A operator encoding the amplitude a that’s approximated, i.e. |
backend | Returns backend. |
grover_operator | Get the operator, or Grover operator. |
i_objective | Get the index of the objective qubit. |
objective_qubits | Get the criterion for a measurement outcome to be in a ‘good’ state. |
q_factory | Get the Q operator, or Grover-operator for the Amplitude Estimation algorithm, i.e. |
quantum_instance | Returns quantum instance. |
random | Return a numpy random. |
state_preparation | Get the operator encoding the amplitude . |
a_factory
Get the A operator encoding the amplitude a that’s approximated, i.e.
A |0>_n |0> = sqrt{1 - a} |psi_0>_n |0> + sqrt{a} |psi_1>_n |1>
see the original Brassard paper (https://arxiv.org/abs/quant-ph/0005055) for more detail.
Returns
the A operator as CircuitFactory
Return type
backend
Returns backend.
Return type
Union
[Backend
, BaseBackend
]
confidence_interval
confidence_interval(alpha, kind='likelihood_ratio')
Compute the (1 - alpha) confidence interval.
Parameters
- 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)
Return type
List
[float
]
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.
construct_circuit
construct_circuit(measurement=False)
Construct the Amplitude Estimation quantum circuit.
Parameters
measurement (bool
) – Boolean flag to indicate if measurements should be included in the circuit.
Return type
QuantumCircuit
Returns
The QuantumCircuit object for the constructed circuit.
grover_operator
Get the operator, or Grover operator.
If the Grover operator is not set, we try to build it from the operator and objective_qubits. This only works if objective_qubits is a list of integers.
Return type
Optional
[QuantumCircuit
]
Returns
The Grover operator, or None if neither the Grover operator nor the operator is set.
i_objective
Get the index of the objective qubit. The objective qubit marks the |psi_0> state (called ‘bad states’ in https://arxiv.org/abs/quant-ph/0005055) with |0> and |psi_1> (‘good’ states) with |1>. If the A operator performs the mapping
A |0>_n |0> = sqrt{1 - a} |psi_0>_n |0> + sqrt{a} |psi_1>_n |1>
then, the objective qubit is the last one (which is either |0> or |1>).
If the objective qubit (i_objective) is not set, we check if the Q operator (q_factory) is set and return the index specified there. If the q_factory is not defined, the index equals the number of qubits of the A operator (a_factory) minus one. If also the a_factory is not set, return None.
Returns
the index of the objective qubit
Return type
int
is_good_state
is_good_state(measurement)
Determine whether a given state is a good state.
Parameters
measurement (str
) – A measurement as bitstring, e.g. ‘01100’.
Return type
bool
Returns
True if the measurement corresponds to a good state, False otherwise.
Raises
ValueError – If self.objective_qubits
is not set.
objective_qubits
Get the criterion for a measurement outcome to be in a ‘good’ state.
Return type
Optional
[List
[int
]]
Returns
The criterion as list of qubit indices.
post_processing
post_processing(value)
Post processing of the raw amplitude estimation output .
Parameters
value (float
) – The estimation value .
Return type
float
Returns
The value after post processing, usually mapping the interval to the target interval.
q_factory
Get the Q operator, or Grover-operator for the Amplitude Estimation algorithm, i.e.
where reflects about the |0>_n state and S_psi0 reflects about . See https://arxiv.org/abs/quant-ph/0005055 for more detail.
If the Q operator is not set, we try to build it from the A operator. If neither the A operator is set, None is returned.
Returns
returns the current Q factory of the algorithm
Return type
QFactory
quantum_instance
Returns quantum instance.
Return type
Optional
[QuantumInstance
]
random
Return a numpy random.
run
run(quantum_instance=None, **kwargs)
Execute the algorithm with selected backend.
Parameters
- quantum_instance (
Union
[QuantumInstance
,Backend
,BaseBackend
,None
]) – the experimental setting. - kwargs (dict) – kwargs
Returns
results of an algorithm.
Return type
dict
Raises
AquaError – If a quantum instance or backend has not been provided
set_backend
set_backend(backend, **kwargs)
Sets backend with configuration.
Return type
None
state_preparation
Get the operator encoding the amplitude .
Return type
QuantumCircuit
Returns
The operator as QuantumCircuit.