本实现基于IBM QISKit 0.7.0版本,python 3.7版本。
HHL Experiment (Quantum Algorithm for linear systems of equations)
This experiment is implemented based on IBM QISKit version 0.7.0. It is a quantum implementation of finding x ⃗ \vec{x} x satisfying A x ⃗ = b ⃗ A\vec{x}=\vec{b} Ax=b, and only for the case when A A A is a 2 by 2 matrx, while b ⃗ \vec{b} b is a 2 by 1 vector.
The whole process can be divided into several steps:
- Quantum phase estimation
- Controlled rotation
- Inverse quantum phase estimation
The quantum circuit for this experiment is (from reference3):
The first qubit ∣ x 1 ⟩ |x_1 \rangle ∣x1⟩ is the ancilla register for controlled rotation. The second and third qubit ∣ x 2 x 3 ⟩ |x_2x_3\rangle ∣x2x3⟩ (the register C) will save the superposition of the eigenvalues of A, after the quantum phase estimation. The forth qubit ∣ x 4 ⟩ |x_4 \rangle ∣x4⟩ is used to save ∣ b ⟩ |b \rangle ∣b⟩, and after the whole process of HHL, it will save the approximate value of x ⃗ \vec{x} x.
# Import packages
%matplotlib inline
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import execute
from qiskit import BasicAer
from math import pi
from qiskit.tools.visualization import plot_histogram
import warnings # Ignore the warning message
warnings.filterwarnings('ignore')
The known A A A and b ⃗ \vec{b} b are set like this in this experiment:
A = 1 2 ( 3 1 1 3 ) A=\frac{1}{2}\begin{pmatrix} 3 & 1\\ 1 & 3 \end{pmatrix} A=21(3113) and b ⃗ = ( b 1 b 2 ) \vec{b}=\begin{pmatrix} b_1\\ b_2 \end{pmatrix} b=(b1b2).
b ⃗ \vec{b} b can be encoded in a quantum state that ∣ b ⟩ = b 1 ∣ 0 ⟩ + b 2 ∣ 1 ⟩ |b \rangle = b_1|0 \rangle+b_2|1 \rangle ∣b⟩=b1∣0⟩+b2∣1⟩, which fulfills b 1 2 + b