English
Languages
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

HHL

class HHL(epsilon=0.01, expectation=None, quantum_instance=None)[source]

Bases: qiskit.algorithms.linear_solvers.linear_solver.LinearSolver

The deprecated systems of linear equations arise naturally in many real-life applications in a wide range of areas, such as in the solution of Partial Differential Equations, the calibration of financial models, fluid simulation or numerical field calculation. The problem can be defined as, given a matrix \(A\in\mathbb{C}^{N\times N}\) and a vector \(\vec{b}\in\mathbb{C}^{N}\), find \(\vec{x}\in\mathbb{C}^{N}\) satisfying \(A\vec{x}=\vec{b}\).

A system of linear equations is called \(s\)-sparse if \(A\) has at most \(s\) non-zero entries per row or column. Solving an \(s\)-sparse system of size \(N\) with a classical computer requires \(\mathcal{ O }(Ns\kappa\log(1/\epsilon))\) running time using the conjugate gradient method. Here \(\kappa\) denotes the condition number of the system and \(\epsilon\) the accuracy of the approximation.

The deprecated HHL is a quantum algorithm to estimate a function of the solution with running time complexity of \(\mathcal{ O }(\log(N)s^{2}\kappa^{2}/\epsilon)\) when \(A\) is a Hermitian matrix under the assumptions of efficient oracles for loading the data, Hamiltonian simulation and computing a function of the solution. This is an exponential speed up in the size of the system, however one crucial remark to keep in mind is that the classical algorithm returns the full solution, while the HHL can only approximate functions of the solution vector.

The HHL class is deprecated as of Qiskit Terra 0.22.0 and will be removed no sooner than 3 months after the release date. It is replaced by the tutorial at HHL

Examples

import warnings
import numpy as np
from qiskit import QuantumCircuit
from qiskit.algorithms.linear_solvers.hhl import HHL
from qiskit.algorithms.linear_solvers.matrices import TridiagonalToeplitz
from qiskit.algorithms.linear_solvers.observables import MatrixFunctional

with warnings.catch_warnings():
    warnings.simplefilter('ignore')
    matrix = TridiagonalToeplitz(2, 1, 1 / 3, trotter_steps=2)
    right_hand_side = [1.0, -2.1, 3.2, -4.3]
    observable = MatrixFunctional(1, 1 / 2)
    rhs = right_hand_side / np.linalg.norm(right_hand_side)

# Initial state circuit
num_qubits = matrix.num_state_qubits
qc = QuantumCircuit(num_qubits)
qc.isometry(rhs, list(range(num_qubits)), None)

with warnings.catch_warnings():
    warnings.simplefilter('ignore')
    hhl = HHL()
    solution = hhl.solve(matrix, qc, observable)
approx_result = solution.observable

References

[1]: Harrow, A. W., Hassidim, A., Lloyd, S. (2009).

Quantum algorithm for linear systems of equations. Phys. Rev. Lett. 103, 15 (2009), 1–15.

[2]: Carrera Vazquez, A., Hiptmair, R., & Woerner, S. (2022).

Enhancing the Quantum Linear Systems Algorithm Using Richardson Extrapolation. ACM Transactions on Quantum Computing 3, 1, Article 2

Parameters
  • epsilon (float) – Error tolerance of the approximation to the solution, i.e. if \(x\) is the exact solution and \(\tilde{x}\) the one calculated by the algorithm, then \(||x - \tilde{x}|| \le epsilon\).

  • expectation (Optional[ExpectationBase]) – The expectation converter applied to the expectation values before evaluation. If None then PauliExpectation is used.

  • quantum_instance (Union[Backend, QuantumInstance, None]) – Quantum Instance or Backend. If None, a Statevector calculation is done.

Methods

construct_circuit

Construct the HHL circuit.

solve

Tries to solve the given linear system of equations.

Attributes

expectation

The expectation value algorithm used to construct the expectation measurement from the observable.

Return type

ExpectationBase

quantum_instance

Get the quantum instance.

Return type

Optional[QuantumInstance]

Returns

The quantum instance used to run this algorithm.

scaling

The scaling of the solution vector.

Return type

float