Learning Notes
Home
Home
  • Guide
    • Shortkeys
    • Commands
  • Cpp
    • Basic
    • Scope, Duration, and Linkage
    • Pointers(1)
    • Pointers(2)
  • Rust Learning
    • 1.Number Types
    • 2.Ownership
    • 3.Struct
    • 4.Enum
    • 5.Package-management
    • 6.Vector
    • 7.Error handle
    • 8.Trait 泛型
    • 9.Life time
    • 10.Test
    • 11.Minigrep
    • 12.Closure 闭包
    • 13.Smart pointer 智能指针
    • 14.Fearless concurrency 无畏并发
  • Quantum Computing
    • Basic computing and quantum computing Theory
    • Teleportation
    • QKD and QFT
    • QFE and Shor's algorithm
    • QAOA
    • Quantum algorithms
    • Week 11
  • Statical Machine Learning
    • Bayesian Linear Regression
    • Linear regression and logistic regresion
    • Bais
    • SVM, Kernel Methods
    • Precepction and Artificial Neural Network
    • Cross validation, experts learning, MAB
    • Bayesian inference
    • GMM-EM
    • final
  • Software Project Management
    • Lecture
    • Revision
  • AI-planning
    • Classical planning
    • MDP and reinforcement learning
    • Game theory and final recap

Basic computing and quantum computing Theory

Basic Math

Recall that the modulus of a complex number a+iba + iba+ib is given by ∣a+ib∣=a2+b2| a + ib | = \sqrt{a^2 + b^2}∣a+ib∣=a2+b2​
and the complex conjugate is given by a+ib‾=a−ib\overline{a + ib} = a - iba+ib​=a−ib.

∣6+πi∣=62+π2;6+πi‾=6−πi| 6 + \pi i | = \sqrt{6^2 + \pi^2}; \quad \overline{6 + \pi i} = 6 - \pi i∣6+πi∣=62+π2​;6+πi​=6−πi

∣0⟩=[10];∣1⟩=[01] \begin{align*} |0\rangle = \begin{bmatrix} 1 \\ 0 \end{bmatrix}; \quad |1\rangle = \begin{bmatrix} 0 \\ 1 \end{bmatrix} \end{align*} ∣0⟩=[10​];∣1⟩=[01​]​

Quantum gates:

H=12[111−1];T=[100eiπ4];S=[100i]=T2 \begin{align*} H = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}; \quad T = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\frac{\pi}{4}} \end{bmatrix}; \quad S = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix} = T^2 \end{align*} H=2​1​[11​1−1​];T=[10​0ei4π​​];S=[10​0i​]=T2​

Pauli matrices:

σ0≡I≡[1001]σ1≡σx≡X≡[0110] \begin{align*} \sigma_0 \equiv I \equiv \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} \quad \sigma_1 \equiv \sigma_x \equiv X \equiv \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} \end{align*} σ0​≡I≡[10​01​]σ1​≡σx​≡X≡[01​10​]​

σ2≡σy≡Y≡[0−ii0]σ3≡σz≡Z≡[100−1] \begin{align*} \sigma_2 \equiv \sigma_y \equiv Y \equiv \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} \quad \sigma_3 \equiv \sigma_z \equiv Z \equiv \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} \end{align*} σ2​≡σy​≡Y≡[0i​−i0​]σ3​≡σz​≡Z≡[10​0−1​]​

Inner product:

⟨ψ∣φ⟩=a0∗b0+a1∗b1 \begin{align*} \langle\psi|\varphi\rangle = a_0^* b_0 + a_1^* b_1 \end{align*} ⟨ψ∣φ⟩=a0∗​b0​+a1∗​b1​​

Outer product:

∣0⟩⟨0∣=[1000],∣0⟩⟨1∣=[0100],∣1⟩⟨0∣=[0010],∣1⟩⟨1∣=[0001] |0 \rangle \langle 0| = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix}, \quad |0 \rangle \langle 1| = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}, \quad |1 \rangle \langle 0| = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix}, \quad |1 \rangle \langle 1| = \begin{bmatrix} 0 & 0 \\ 0 & 1 \end{bmatrix} ∣0⟩⟨0∣=[10​00​],∣0⟩⟨1∣=[00​10​],∣1⟩⟨0∣=[01​00​],∣1⟩⟨1∣=[00​01​]

∣ψ⟩⟨φ∣=[a0b0∗a0b1∗a1b0∗a1b1∗]=a0b0∗∣0⟩⟨0∣+a0b1∗∣0⟩⟨1∣+a1b0∗∣1⟩⟨0∣+a1b1∗∣1⟩⟨1∣ \begin{align*} |\psi\rangle\langle\varphi| = \begin{bmatrix} a_0 b_0^* & a_0 b_1^* \\ a_1 b_0^* & a_1 b_1^* \end{bmatrix} = a_0 b_0^* |0\rangle\langle0| + a_0 b_1^* |0\rangle\langle1| + a_1 b_0^* |1\rangle\langle0| + a_1 b_1^* |1\rangle\langle1| \end{align*} ∣ψ⟩⟨φ∣=[a0​b0∗​a1​b0∗​​a0​b1∗​a1​b1∗​​]=a0​b0∗​∣0⟩⟨0∣+a0​b1∗​∣0⟩⟨1∣+a1​b0∗​∣1⟩⟨0∣+a1​b1∗​∣1⟩⟨1∣​

Tensor product:

∣ψ⟩⊗∣φ⟩=a0b0∣00⟩+a0b1∣01⟩+a1b0∣10⟩+a1b1∣11⟩=[a0b0a0b1a1b0a1b1] \left|\psi\right\rangle \otimes \left|\varphi\right\rangle = a_0b_0\left|00\right\rangle + a_0b_1\left|01\right\rangle + a_1b_0\left|10\right\rangle + a_1b_1\left|11\right\rangle = \begin{bmatrix} a_0b_0 \\ a_0b_1 \\ a_1b_0 \\ a_1b_1 \end{bmatrix} ∣ψ⟩⊗∣φ⟩=a0​b0​∣00⟩+a0​b1​∣01⟩+a1​b0​∣10⟩+a1​b1​∣11⟩=​a0​b0​a0​b1​a1​b0​a1​b1​​​

Basic Operations:

H∣0⟩=∣+⟩,H∣1⟩=∣−⟩,H∣+⟩=∣0⟩,H∣−⟩=∣1⟩ H |0 \rangle = |+ \rangle, \quad H |1 \rangle = |- \rangle, \quad H |+\rangle = |0 \rangle, \quad H |-\rangle = |1 \rangle H∣0⟩=∣+⟩,H∣1⟩=∣−⟩,H∣+⟩=∣0⟩,H∣−⟩=∣1⟩

Where ∣+⟩=12(∣0⟩+∣1⟩)∣−⟩=12(∣0⟩−∣1⟩)|+\rangle = \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) \quad |- \rangle = \frac{1}{\sqrt{2}}(|0\rangle - |1\rangle)∣+⟩=2​1​(∣0⟩+∣1⟩)∣−⟩=2​1​(∣0⟩−∣1⟩).

I∣0⟩=∣0⟩,I∣1⟩=∣1⟩;X∣0⟩=∣1⟩,X∣1⟩=∣0⟩;Y∣0⟩=i∣1⟩,Y∣1⟩=−i∣0⟩;Z∣0⟩=∣0⟩,Z∣1⟩=−∣1⟩ I|0\rangle = |0\rangle, \quad I|1\rangle = |1\rangle; \quad X|0\rangle = |1\rangle, \quad X|1\rangle = |0\rangle; \newline Y|0\rangle = i|1\rangle, \quad Y|1\rangle = -i|0\rangle; \quad Z|0\rangle = |0\rangle, \quad Z|1\rangle = -|1\rangle I∣0⟩=∣0⟩,I∣1⟩=∣1⟩;X∣0⟩=∣1⟩,X∣1⟩=∣0⟩;Y∣0⟩=i∣1⟩,Y∣1⟩=−i∣0⟩;Z∣0⟩=∣0⟩,Z∣1⟩=−∣1⟩

Pauli Gates and the Bloch Sphere

The Pauli gates are Hermitian and unitary, which means that they are self-adjoint and their inverse is equal to their conjugate transpose. The Pauli gates are also involutory, which means that applying the gate twice will return the original state. The Pauli gates are also traceless, which means that the sum of the diagonal elements is zero.

X basis:{∣+⟩=∣0⟩+∣1⟩2,∣−⟩=∣0⟩−∣1⟩2}Y basis:{∣i⟩=∣0⟩+i∣1⟩2,∣−i⟩=∣0⟩−i∣1⟩2}Z basis:{∣0⟩,∣1⟩} \textbf{X basis:} \quad \left\{|+\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}}, \quad |-\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}} \right\} \\[1em] \textbf{Y basis:} \quad \left\{|i\rangle = \frac{|0\rangle + i|1\rangle}{\sqrt{2}}, \quad |-i\rangle = \frac{|0\rangle - i|1\rangle}{\sqrt{2}} \right\} \\[1em] \textbf{Z basis:} \quad \left\{|0\rangle, |1\rangle \right\} X basis:{∣+⟩=2​∣0⟩+∣1⟩​,∣−⟩=2​∣0⟩−∣1⟩​}Y basis:{∣i⟩=2​∣0⟩+i∣1⟩​,∣−i⟩=2​∣0⟩−i∣1⟩​}Z basis:{∣0⟩,∣1⟩}

  • the X, Y and Z basis states are orthogonal and normalized;
  • the X, Y and Z basis states are eigenstates of the Pauli X, Y and Z gates

The X, Y, and Z Pauli matrices are ways of “flipping” the Bloch sphere 180◦ about the x, y, and z axes respectively.

Rotation-y



A generic qubit is of the form

∣ψ⟩=c0∣0⟩+c1∣1⟩ |\psi\rangle = c_0|0\rangle + c_1|1\rangle ∣ψ⟩=c0​∣0⟩+c1​∣1⟩

where ∣c0∣2+∣c1∣2=1|c_0|^2 + |c_1|^2 = 1∣c0​∣2+∣c1​∣2=1. The equation can be written as:

∣ψ⟩=cos⁡(θ)∣0⟩+eiϕsin⁡(θ)∣1⟩ |\psi\rangle = \cos(\theta)|0\rangle + e^{i\phi}\sin(\theta)|1\rangle ∣ψ⟩=cos(θ)∣0⟩+eiϕsin(θ)∣1⟩

with only two parameters θ\thetaθ and ϕ\phiϕ to describe the state.

bloch-sphere
  • A phase shift gate is defined as

R(θ)=[100eiθ] R(\theta) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i\theta} \end{bmatrix} R(θ)=[10​0eiθ​]

  • Sometimes we want to rorate a particular number of degrees around the x,y or z axis, which can be represented as:

Rx(θ)=cos⁡θ2I−isin⁡θ2X=[cos⁡θ2−isin⁡θ2−isin⁡θ2cos⁡θ2] R_x(\theta) = \cos{\frac{\theta}{2} I} - i \sin{\frac{\theta}{2}X} = \begin{bmatrix} \cos{\frac{\theta}{2}} & -i \sin{\frac{\theta}{2}} \\ - i \sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} \end{bmatrix} Rx​(θ)=cos2θ​I−isin2θ​X=[cos2θ​−isin2θ​​−isin2θ​cos2θ​​]

Ry(θ)=cos⁡θ2I−isin⁡θ2Y=[cos⁡θ2−sin⁡θ2sin⁡θ2cos⁡θ2] R_y(\theta) = \cos{\frac{\theta}{2} I} - i \sin{\frac{\theta}{2}Y} = \begin{bmatrix} \cos{\frac{\theta}{2}} & - \sin{\frac{\theta}{2}} \\ \sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} \end{bmatrix} Ry​(θ)=cos2θ​I−isin2θ​Y=[cos2θ​sin2θ​​−sin2θ​cos2θ​​]

Rz(θ)=cos⁡θ2I−isin⁡θ2Z=[e−iθ/200eiθ/2] R_z(\theta) = \cos{\frac{\theta}{2} I} - i \sin{\frac{\theta}{2}Z} = \begin{bmatrix} e^{-i\theta/2} & 0 \\ 0 & e^{i\theta/2} \end{bmatrix} Rz​(θ)=cos2θ​I−isin2θ​Z=[e−iθ/20​0eiθ/2​]

Basic Quantum Mechanics

The time evoluation of the state of a closed quantum system is described by the Schrödinger equation:

iℏd∣ψ⟩dt=H∣ψ⟩ i\hbar \frac{d|\psi\rangle}{dt} = H|\psi\rangle iℏdtd∣ψ⟩​=H∣ψ⟩

ℏ\hbarℏ is a physical constant known as Planck's constant whose value must be experimentally determined.

where HHH is the Hamiltonian of the system.

Density matrix Density matrix or density operator (ρ\rhoρ) is an alternative formulation for state vectors.

  • The trace of a density matrix tr(ρ)=1tr(\rho) = 1tr(ρ)=1.

The evolution of a closed quantum system is described by a unitary transformation.That is, the state ρ\rhoρ of the system at time t1t_1t1​ is related to the state ρ′\rho'ρ′ of the system at time t2t_2t2​ by a unitary operator UUU which depends only on the time t1t_1t1​ and t2t_2t2​

ρ′=UρU† \rho' = U\rho U^{\dagger} ρ′=UρU†

A pure state satisfied Tr(ρ2)=1Tr(\rho^2) = 1Tr(ρ2)=1
For a mixed state, Tr(ρ2)<1Tr(\rho^2) < 1Tr(ρ2)<1

For pure state: rank = 1, det(ρ)=λ1λ2=0det(\rho) = \lambda_1 \lambda_2 = 0det(ρ)=λ1​λ2​=0

Calculation tricks

Complex Conjugate of a matrix

A=[1+i2−3i45i]A†=[1−i42+3i−5i] A = \begin{bmatrix} 1+i & 2-3i \\ 4 & 5i\end{bmatrix} \quad A^{\dagger} = \begin{bmatrix} 1- i & 4 \\ 2 + 3i & -5i\end{bmatrix} A=[1+i4​2−3i5i​]A†=[1−i2+3i​4−5i​]

Trace of a matrix

A=[a11a12a21a22]tr(A)=∑i=13aii=a11+a22 A = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22}\end{bmatrix} \quad \text{tr}(A) = \sum_{i = 1}^3 a_{ii} = a_{11} + a_{22} A=[a11​a21​​a12​a22​​]tr(A)=i=1∑3​aii​=a11​+a22​

Transformation of complex number

Regular form:

z=x+iy z=x+iy z=x+iy

Polar Form:

r=∣z∣=x2+y2θ=arg(z)=tan−1(yx)z=r(cos⁡θ+isin⁡θ)←final form r = |z| = \sqrt{x^2 + y^2} \\[5pt] \theta = arg(z) = tan^{-1} (\frac{y}{x}) \\[5pt] \bf{z = r(\cos{\theta} + i \sin{\theta})} \quad \leftarrow \text{final form} r=∣z∣=x2+y2​θ=arg(z)=tan−1(xy​)z=r(cosθ+isinθ)←final form

Exponential Form:
Euler's formula : eiθ=cos⁡θ+isin⁡θe^{i \theta} = \cos{\theta} + i \sin{\theta}eiθ=cosθ+isinθ

Thus the exponential form:

z=reiθ z = r e^{i \theta} z=reiθ

Matric multipliation

A=[abcd]B=[efgh]A×B=[a×e+b×ga×f+b×hc×e+d×gc×f+d×h] A = \begin{bmatrix} a & b \\ c & d\end{bmatrix} \quad B = \begin{bmatrix} e & f \\ g & h\end{bmatrix} \\[6pt] A \times B = \begin{bmatrix} a×e+b×g & a×f+b×h \\ c×e+d×g & c×f+d×h \end{bmatrix} A=[ac​bd​]B=[eg​fh​]A×B=[a×e+b×gc×e+d×g​a×f+b×hc×f+d×h​]

Some normal gate combination

X2=Y2=Z2=IH=12(X+Z)X=HZHZ=HXH−1Y=HYHS=T2−1Y=XYX X^2 = Y^2 = Z^2 = I \\ H = \frac{1}{\sqrt{2}}(X+Z)\\ X = HZH \quad Z = HXH \quad -1Y = HYH \\ S = T^2 \\ -1Y = XYX X2=Y2=Z2=IH=2​1​(X+Z)X=HZHZ=HXH−1Y=HYHS=T2−1Y=XYX

Embedding Data

Basis Embedding

b=(b0,b1,...,bn−1)→∣b0,b1,…,bn−1⟩ b = (b_0, b_1, ..., b_{n-1}) \rightarrow |b_0, b_1, \ldots, b_{n-1}\rangle b=(b0​,b1​,...,bn−1​)→∣b0​,b1​,…,bn−1​⟩

Pros:

  • Simple and intuitive: It directly maps binary data into quantum states, making it suitable for data that is inherently binary.

Cons:

  • High resource consumption: If the input data is not binary, it needs to be converted before encoding. Each bit requires one qubit, leading to high resource consumption, especially for large datasets.

Angle Embedding

Angle embedding is suitable for floating-point data.

It encodes each input value 𝑥 as a rotation around one of the axes (𝑥,𝑦,𝑧) on the Bloch sphere

x↦Rk(x)∣0⟩=e−ix2σk∣0⟩, x \mapsto R_k(x) \lvert 0 \rangle = e^{-i \frac{x}{2} \sigma_k} \lvert 0 \rangle, x↦Rk​(x)∣0⟩=e−i2x​σk​∣0⟩,

Pros:

  • Fewer qubit requirements: Each feature can be encoded using a rotation gate, which saves qubit resources.
  • Ideal for continuous data: It works well for handling floating-point or other continuous data.

Cons:

  • Non-unique mapping: Different data may be mapped to the same quantum state since the same rotation angle can result in identical quantum states.
  • Initial state limitation: If the initial state is ∣0⟩|0\rangle∣0⟩, rotations around the z-axis have no effect, making them unusable for encoding in such cases.

Amplitude Embedding Amplitude embedding encodes the values of an input array as the amplitudes of a quantum state. Specifically, the input a=(a0,a1,...,a2n−1)a = (a_0, a_1, ..., a_{2^n-1})a=(a0​,a1​,...,a2n−1​) is encoded as:

∣a⟩=∑i=02n−1ai∣i⟩ |a\rangle = \sum_{i=0}^{2^n-1} a_i |i\rangle ∣a⟩=i=0∑2n−1​ai​∣i⟩

requiring that the amplitudes are normalized, i.e. ∥ai∥=1\|a_i\| = 1∥ai​∥=1.

Pros:

  • Efficient qubit usage: It can represent a large amount of data in a single quantum state, particularly suitable for large-scale data where an exponential number of data points can be represented.
  • High representational capacity: It allows data to be embedded into high-dimensional quantum states, enabling quantum machine learning models to learn complex features in higher-dimensional space.

Cons:

  • Normalization requirement: Input data must be normalized to ensure that all the squared amplitudes sum to 1, which can add computational complexity.

  • Complex circuit design: Implementing amplitude embedding requires complex multi-controlled rotations, making the circuit design and implementation more challenging.

Last Updated:
Contributors: pingzhihe
Next
Teleportation