# Algorithms

`qiskit.algorithms`

The `qiskit.algorithms`

module has been migrated to an independent package: https://github.com/qiskit-community/qiskit-algorithms(opens in a new tab). The current import path is deprecated and will be removed no earlier than 3 months after the release date. If your code uses primitives, you can run `pip install qiskit_algorithms`

and import `from qiskit_algorithms`

instead. If you use opflow/quantum instance-based algorithms, please update your code to use primitives following: https://qisk.it/algo_migration(opens in a new tab) before migrating to the new package.

It contains a collection of quantum algorithms, for use with quantum computers, to carry out research and investigate how to solve problems in different domains on near-term quantum devices with short depth circuits.

Algorithms configuration includes the use of `optimizers`

which were designed to be swappable sub-parts of an algorithm. Any component and may be exchanged for a different implementation of the same component type in order to potentially alter the behavior and outcome of the algorithm.

Quantum algorithms are run via a `QuantumInstance`

which must be set with the desired backend where the algorithm’s circuits will be executed and be configured with a number of compile and runtime parameters controlling circuit compilation and execution. It ultimately uses Terra(opens in a new tab) for the actual compilation and execution of the quantum circuits created by the algorithm and its components.

## Algorithms

It contains a variety of quantum algorithms and these have been grouped by logical function such as minimum eigensolvers and amplitude amplifiers.

### Amplitude Amplifiers

`AmplificationProblem` | The amplification problem is the input to amplitude amplification algorithms, like Grover. |

`AmplitudeAmplifier` | The interface for amplification algorithms. |

`Grover` | Grover's Search algorithm. |

`GroverResult` | Grover Result. |

### Amplitude Estimators

`AmplitudeEstimator` | The Amplitude Estimation interface. |

`AmplitudeEstimatorResult` | The results object for amplitude estimation algorithms. |

`AmplitudeEstimation` | The Quantum Phase Estimation-based Amplitude Estimation algorithm. |

`AmplitudeEstimationResult` | The `AmplitudeEstimation` result object. |

`EstimationProblem` | The estimation problem is the input to amplitude estimation algorithm. |

`FasterAmplitudeEstimation` | The Faster Amplitude Estimation algorithm. |

`FasterAmplitudeEstimationResult` | The result object for the Faster Amplitude Estimation algorithm. |

`IterativeAmplitudeEstimation` | The Iterative Amplitude Estimation algorithm. |

`IterativeAmplitudeEstimationResult` | The `IterativeAmplitudeEstimation` result object. |

`MaximumLikelihoodAmplitudeEstimation` | The Maximum Likelihood Amplitude Estimation algorithm. |

`MaximumLikelihoodAmplitudeEstimationResult` | The `MaximumLikelihoodAmplitudeEstimation` result object. |

### 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.

#### Primitive-based Eigensolvers

These algorithms are based on the Qiskit Primitives, a new execution paradigm that replaces the use of `QuantumInstance`

in algorithms. To ensure continued support and development, we recommend using the primitive-based Eigensolvers in place of the legacy `QuantumInstance`

-based ones.

`eigensolvers` | Eigensolvers Package (qiskit.algorithms.eigensolvers) |

#### Legacy Eigensolvers

These algorithms, still based on the `QuantumInstance`

, are superseded by the primitive-based versions in the section above but are still supported for now.

`Eigensolver` | Deprecated: Eigensolver Interface. |

`EigensolverResult` | Deprecated: Eigensolver Result. |

`NumPyEigensolver` | Deprecated: NumPy Eigensolver algorithm. |

`VQD` | Deprecated: Variational Quantum Deflation algorithm. |

`VQDResult` | Deprecated: VQD Result. |

### Time Evolvers

Algorithms to evolve quantum states in time. Both real and imaginary time evolution is possible with algorithms that support them. For machine learning, Quantum Imaginary Time Evolution might be used to train Quantum Boltzmann Machine Neural Networks for example.

#### Primitive-based Time Evolvers

These algorithms are based on the Qiskit Primitives, a new execution paradigm that replaces the use of `QuantumInstance`

in algorithms. To ensure continued support and development, we recommend using the primitive-based Time Evolvers in place of the legacy `QuantumInstance`

-based ones.

`RealTimeEvolver` | Interface for Quantum Real Time Evolution. |

`ImaginaryTimeEvolver` | Interface for Quantum Imaginary Time Evolution. |

`TimeEvolutionResult` | Class for holding time evolution result. |

`TimeEvolutionProblem` | Time evolution problem class. |

`PVQD` | The projected Variational Quantum Dynamics (p-VQD) Algorithm. |

`PVQDResult` | The result object for the p-VQD algorithm. |

`SciPyImaginaryEvolver` | Classical Evolver for imaginary time evolution. |

`SciPyRealEvolver` | Classical Evolver for real time evolution. |

`VarQITE` | Variational Quantum Imaginary Time Evolution algorithm. |

`VarQRTE` | Variational Quantum Real Time Evolution algorithm. |

#### Legacy Time Evolvers

These algorithms, still based on the `QuantumInstance`

, are superseded by the primitive-based versions in the section above but are still supported for now.

`RealEvolver` | Deprecated: Interface for Quantum Real Time Evolution. |

`ImaginaryEvolver` | Deprecated: Interface for Quantum Imaginary Time Evolution. |

`TrotterQRTE` | Deprecated: Quantum Real Time Evolution using Trotterization. |

`EvolutionResult` | Deprecated: Class for holding evolution result. |

`EvolutionProblem` | Deprecated: Evolution problem class. |

#### Variational Quantum Time Evolution

Classes used by variational quantum time evolution algorithms - `VarQITE`

and `VarQRTE`

.

`time_evolvers.variational` | Variational Quantum Time Evolutions (qiskit.algorithms.time_evolvers.variational) |

#### Trotterization-based Quantum Real Time Evolution

Package for primitives-enabled Trotterization-based quantum time evolution algorithm - `TrotterQRTE`

.

`time_evolvers.trotterization` | This package contains Trotterization-based Quantum Real Time Evolution algorithm. |

### Gradients

Algorithms to calculate the gradient of a quantum circuit.

`gradients` | Gradients (qiskit.algorithms.gradients) |

### Minimum Eigensolvers

Algorithms that can find the minimum eigenvalue of an operator.

#### Primitive-based Minimum Eigensolvers

These algorithms are based on the Qiskit Primitives, a new execution paradigm that replaces the use of `QuantumInstance`

in algorithms. To ensure continued support and development, we recommend using the primitive-based Minimum Eigensolvers in place of the legacy `QuantumInstance`

-based ones.

`minimum_eigensolvers` | Minimum Eigensolvers Package (qiskit.algorithms.minimum_eigensolvers) |

#### Legacy Minimum Eigensolvers

These algorithms, still based on the `QuantumInstance`

, are superseded by the primitive-based versions in the section above but are still supported for now.

`MinimumEigensolver` | Deprecated: Minimum Eigensolver Interface. |

`MinimumEigensolverResult` | Deprecated: Minimum Eigensolver Result. |

`NumPyMinimumEigensolver` | Deprecated: Numpy Minimum Eigensolver algorithm. |

`QAOA` | Deprecated: Quantum Approximate Optimization Algorithm. |

`VQE` | Deprecated: Variational Quantum Eigensolver algorithm. |

### Optimizers

Classical optimizers for use by quantum variational algorithms.

`optimizers` | Optimizers (qiskit.algorithms.optimizers) It contains a variety of classical optimizers for use by quantum variational algorithms, such as VQE. Logically, these optimizers can be divided into two categories: |

### Phase Estimators

Algorithms that estimate the phases of eigenstates of a unitary.

`HamiltonianPhaseEstimation` | Run the Quantum Phase Estimation algorithm to find the eigenvalues of a Hermitian operator. |

`HamiltonianPhaseEstimationResult` | Store and manipulate results from running HamiltonianPhaseEstimation. |

`PhaseEstimationScale` | Set and use a bound on eigenvalues of a Hermitian operator in order to ensure phases are in the desired range and to convert measured phases into eigenvectors. |

`PhaseEstimation` | Run the Quantum Phase Estimation (QPE) algorithm. |

`PhaseEstimationResult` | Store and manipulate results from running PhaseEstimation. |

`IterativePhaseEstimation` | Run the Iterative quantum phase estimation (QPE) algorithm. |

### State Fidelities

Algorithms that compute the fidelity of pairs of quantum states.

`state_fidelities` | State Fidelity Interfaces (qiskit.algorithms.state_fidelities) |

### Exceptions

### AlgorithmError

`qiskit.algorithms.AlgorithmError(*message)`

For Algorithm specific errors.

Set the error message.

### Utility classes

Utility classes used by algorithms (mainly for type-hinting purposes).

`AlgorithmJob` (function, *args, **kwargs) | This empty class is introduced for typing purposes. |

### Utility functions

Utility functions used by algorithms.

### eval_observables

`qiskit.algorithms.eval_observables(quantum_instance, quantum_state, observables, expectation, threshold=1e-12)`

Deprecated: Accepts a list or a dictionary of operators and calculates their expectation values - means and standard deviations. They are calculated with respect to a quantum state provided. A user can optionally provide a threshold value which filters mean values falling below the threshold.

This function has been superseded by the `qiskit.algorithms.observables_evaluator.eval_observables()`

function. It will be deprecated in a future release and subsequently removed after that.

The function `qiskit.algorithms.aux_ops_evaluator.eval_observables()`

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 function `qiskit.algorithms.observables_evaluator.estimate_observables`

. See https://qisk.it/algo_migration(opens in a new tab) for a migration guide.

**Parameters**

**quantum_instance**(*QuantumInstance**|**Backend*) – A quantum instance used for calculations.**quantum_state**(*Statevector**|**QuantumCircuit**|**OperatorBase*) – An unparametrized quantum circuit representing a quantum state that expectation values are computed against.**observables**(*ListOrDict[**OperatorBase**]*) – A list or a dictionary of operators whose expectation values are to be calculated.**expectation**(*ExpectationBase*) – An instance of ExpectationBase which defines a method for calculating expectation values.**threshold**(*float*(opens in a new tab)) – A threshold value that defines which mean values should be neglected (helpful for ignoring numerical instabilities close to 0).

**Returns**

A list or a dictionary of tuples (mean, standard deviation).

**Raises**

**ValueError**(opens in a new tab) – If a `quantum_state`

with free parameters is provided.

**Return type**

ListOrDict[tuple(opens in a new tab)[complex(opens in a new tab), complex(opens in a new tab)]]

### estimate_observables

`qiskit.algorithms.estimate_observables(estimator, quantum_state, observables, parameter_values=None, threshold=1e-12)`

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 can optionally provide a threshold value which filters mean values falling below the threshold.

**Parameters**

**estimator**(*BaseEstimator*) – An estimator primitive used for calculations.**quantum_state**(*QuantumCircuit*) – A (parameterized) quantum circuit preparing a quantum state that expectation values are computed against.**observables**(*ListOrDict[BaseOperator |**PauliSumOp**]*) – A list or a dictionary of operators whose expectation values are to be calculated.**parameter_values**(*Sequence[**float*(opens in a new tab)*] | None*) – Optional list of parameters values to evaluate the quantum circuit on.**threshold**(*float*(opens in a new tab)) – A threshold value that defines which mean values should be neglected (helpful for ignoring numerical instabilities close to 0).

**Returns**

A list or a dictionary of tuples (mean, metadata).

**Raises**

**AlgorithmError** – If a primitive job is not successful.

**Return type**

ListOrDict[tuple(opens in a new tab)[complex(opens in a new tab), dict(opens in a new tab)[str(opens in a new tab), Any]]]