본문으로 건너뛰기

"quantum" 태그로 연결된 1개 게시물개의 게시물이 있습니다.

모든 태그 보기

OpenQASM

· 약 9분

OpenQASM 2.0

오픈캐즘

OPENQASM 2.0; // 언어 버전 선언

qreg q[1]; // 큐비트 레지스터 q를 선언 (큐비트 1개, 초기 상태 |0⟩)
creg c[1]; // 고전 비트 레지스터 c를 선언 (측정 결과 저장용)

h q[0]; // Hadamard 게이트 적용: |0⟩ → (|0⟩ + |1⟩) / √2

measure q[0] -> c[0]; // q[0]을 측정하고 결과(0 또는 1)를 c[0]에 저장
OPENQASM 2.0;

qreg q[10]; // ∣0000000000⟩
creg c[10];

// x 게이트를 사용하여 처음 세 큐비트를 ∣1⟩ 상태로 변경
x q[0];1000000000
x q[1];1100000000
x q[2];1110000000

measure q[0] -> c[0]; // 1
measure q[1] -> c[1]; // 1
measure q[2] -> c[2]; // 1

Linear Algebra

Vectors

  • In quantum computing, vectors represent quantum states.
  • A 2-dimensional vactor can be written as:
  • ψ=(ψ0ψ1)|\psi\rangle = \begin{pmatrix} \psi_0 \\ \psi_1 \end{pmatrix}

Computational Basis

0=(10),1=(01)|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \quad |1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix}

  • ψ|\psi\rangle is a linear combination of basis states as follows:
  • ψ=ψ00+ψ11=(ψ0ψ1)|\psi\rangle = \psi_0|0\rangle + \psi_1|1\rangle = \begin{pmatrix} \psi_0 \\ \psi_1 \end{pmatrix}

Indentity Matrix

  • Iψ=[ψ0ψ1]\mathbb I \psi\rangle = \begin{bmatrix} \psi_0 \\ \psi_1 \end{bmatrix}
  • I2=[1001]\mathbb I^2 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}

Conjugate Transpose

  • Bra: ψ=(ψ0ψ1)=(ψ0ψ1)=ψ|\psi\rangle^\dagger = \begin{pmatrix} \psi_0 \\ \psi_1 \end{pmatrix}^\dagger = \begin{pmatrix} \overline{\psi_0} & \overline{\psi_1} \end{pmatrix} = \langle \psi|
    • ψ:=ψ\langle \psi| := |\psi\rangle^\dagger
    • ket: ψ|\psi\rangle
    • bra: ψ\langle \psi|
    • bra + ket: dot product ϕψ\langle \phi|\psi\rangle
  • Dagger: A=[abcd]    A=[acbd]A = \begin{bmatrix} a & b \\ c & d \end{bmatrix} \implies A^\dagger = \begin{bmatrix} \overline{a} & \overline{c} \\ \overline{b} & \overline{d} \end{bmatrix}
psi_dagger = psi.conjugate().T
psi_dagger = psi.conjugate().transpose()
psi_dagger = psi.H
  • (αA)=αA(\alpha A)\dagger = \overline\alpha A^\dagger
  • (A)=A(A^\dagger)^\dagger = A
  • (A+B)=A+B(A + B)^\dagger = A^\dagger + B^\dagger
  • (AB)=BA(AB)^\dagger = B^\dagger A^\dagger

Hermitian

  • A matrix is equal to its conjugate transpose.
  • H=HH = H^\dagger
A_dagger = A.H
AA_dagger = A * A_dagger
# (AA†)†=AA†?
is_hermitian = AA_dagger.is_hermitian

Unitary

  • A matrix whose conjugate transpose is also its inverse.
  • UU=UU=IU^\dagger U = U U^\dagger = \mathbb I
  • U=(cosθsinθsinθcosθ)U = \begin{pmatrix} \cos\theta & \sin\theta \\ -\sin\theta & \cos\theta \end{pmatrix}
U = Matrix([
[cos(theta), sin(theta)],
[-sin(theta), cos(theta)]
])

U_dagger = U.H
U_dagger_U = trigsimp(U_dagger * U)

is_unitary = U_dagger_U == I

Inner Product

  • ψϕ=(ψ0ψ1)(ϕ0ϕ1)=ψ0ϕ0+ψ1ϕ1\langle \psi|\phi\rangle = \begin{pmatrix} \overline{\psi_0} & \overline{\psi_1} \end{pmatrix} \begin{pmatrix} \phi_0 \\ \phi_1 \end{pmatrix} = \overline{\psi_0}\phi_0 + \overline{\psi_1}\phi_1
  • ψϕ2=ψϕϕψ|\langle \psi|\phi\rangle|^2 = \langle \psi|\phi\rangle \langle \phi|\psi\rangle
  • ψϕ=ϕψ|\langle\psi|\phi\rangle| = |\langle\phi|\psi\rangle|

Orthogonality

  • 0=(10),1=(01)|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \quad |1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix}
    • orthonormal basis
  • 01=(10)(01)=0\langle 0 | 1 \rangle = \begin{pmatrix} 1 & 0 \end{pmatrix} \begin{pmatrix} 0 \\ 1 \end{pmatrix} = 0
    • 10=0\langle 1 | 0 \rangle = 0
  • 00=(10)(10)=1\langle 0 | 0 \rangle = \begin{pmatrix} 1 & 0 \end{pmatrix} \begin{pmatrix} 1 \\ 0 \end{pmatrix} = 1
    • 11=1\langle 1 | 1 \rangle = 1

ψϕ=ψ0ϕ0+ψ1ϕ1\langle \psi|\phi\rangle = \overline{\psi_0}\phi_0 + \overline{\psi_1}\phi_1

  • ψ=ψ00+ψ11,ϕ=ϕ00+ϕ11|\psi\rangle = \psi_0|0\rangle + \psi_1|1\rangle, \quad |\phi\rangle = \phi_0|0\rangle + \phi_1|1\rangle
  • ψ=ψ00+ψ11\langle \psi| = \overline{\psi_0}\langle 0| + \overline{\psi_1}\langle 1|
  • ψϕ=ψ0ϕ000+ψ0ϕ101+ψ1ϕ010+ψ1ϕ111\langle \psi|\phi\rangle = \overline{\psi_0}\phi_0\langle 0|0\rangle + \overline{\psi_0}\phi_1\langle 0|1\rangle + \overline{\psi_1}\phi_0\langle 1|0\rangle + \overline{\psi_1}\phi_1\langle 1|1\rangle
  • 01=0,10=0\langle 0|1\rangle = 0, \quad \langle 1|0\rangle = 0

Magnitude

ψ2=ψ02+ψ12\|\psi\rangle\|^2 = |\psi_0|^2 + |\psi_1|^2

  • ψ=ψψ=ψ02+ψ12\|\psi\rangle\| = \sqrt{\langle \psi|\psi\rangle} = \sqrt{|\psi_0|^2 + |\psi_1|^2}
  • ψ2=ψψ\| |\psi\rangle\|^2 = \langle \psi|\psi\rangle
    • ψψ=ψ0ψ0+ψ1ψ1=ψ02+ψ12\langle \psi|\psi\rangle = \overline{\psi_0}\psi_0 + \overline{\psi_1}\psi_1 = |\psi_0|^2 + |\psi_1|^2

Outer product

  • ψϕ=(ψ00+ψ11)(ϕ00+ϕ11)=ψ0ϕ000+ψ0ϕ101+ψ1ϕ010+ψ1ϕ111|\psi\rangle\langle\phi| = (\psi_0 | 0\rangle + \psi_1 |1\rangle)(\overline{\phi_0}\langle 0| + \overline{\phi_1}\langle 1|) \\ \quad =\psi_0\overline{\phi_0}|0\rangle\langle 0| + \psi_0\overline{\phi_1}|0\rangle\langle 1| + \psi_1\overline{\phi_0}|1\rangle\langle 0| + \psi_1\overline{\phi_1}|1\rangle\langle 1|
  • ψϕ=(ψ0ψ1)(ϕ0ϕ1)=(ψ0ϕ0ψ0ϕ1ψ1ϕ0ψ1ϕ1)|\psi\rangle\langle\phi| = \begin{pmatrix} \psi_0 \\ \psi_1 \end{pmatrix} \begin{pmatrix} \overline{\phi_0} & \overline{\phi_1} \end{pmatrix} = \begin{pmatrix} \psi_0\overline{\phi_0} & \psi_0\overline{\phi_1} \\ \psi_1\overline{\phi_0} & \psi_1\overline{\phi_1} \end{pmatrix}
  • 0=(10),1=(01)|0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \quad |1\rangle = \begin{pmatrix} 0 & 1 \end{pmatrix}
  • 00=(10)(01)=(0100)|0\rangle\langle 0| = \begin{pmatrix} 1 \\ 0 \end{pmatrix} \begin{pmatrix} 0 & 1 \end{pmatrix} = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}
  • A=(a00a01a10a11)=a0000+a0101+a1010+a1111A = \begin{pmatrix} a_{00} & a_{0 1} \\ a_{1 0} & a_{1 1} \end{pmatrix} \\ \quad = a_{00}|0\rangle\langle 0| + a_{01}|0\rangle\langle 1| + a_{10}|1\rangle\langle 0| + a_{11}|1\rangle\langle 1|

Tensor Product

  • ψϕ=(ψ0ψ1)(ϕ0ϕ1)=(ψ0ϕ0ψ0ϕ1ψ1ϕ0ψ1ϕ1)|\psi\rangle \otimes |\phi\rangle = \begin{pmatrix} \psi_0 \\ \psi_1 \end{pmatrix} \otimes \begin{pmatrix} \phi_0 \\ \phi_1 \end{pmatrix} = \begin{pmatrix} \psi_0\phi_0 \\ \psi_0\phi_1 \\ \psi_1\phi_0 \\ \psi_1\phi_1 \end{pmatrix}
  • ψϕψϕψϕ|\psi\rangle \otimes |\phi\rangle \equiv |\psi\rangle|\phi\rangle \equiv |\psi\phi\rangle
  • AB=(a00Ba01Ba10Ba11B)A \otimes B = \begin{pmatrix} a_{00}B & a_{01}B \\ a_{10}B & a_{11}B \end{pmatrix}
  • 0110=(0100)(0010)|0\rangle \langle 1| \otimes |1\rangle \langle 0| = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} \otimes \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}
  • 0110=(0(0010)1(0010)0(0010)0(0010))=(0000001000000000)|0\rangle \langle 1| \otimes |1\rangle \langle 0| = \begin{pmatrix} 0\begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} & 1\begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} \\ 0\begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} & 0\begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} \end{pmatrix} = \begin{pmatrix} 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \end{pmatrix}
  • 0110(01)(10)01010110|0\rangle \langle 1| \otimes |1\rangle \langle 0| \equiv (|0\rangle \otimes |1\rangle)(\langle 1| \otimes \langle 0|) \\ \quad \equiv |0\rangle|1\rangle \langle 0|\langle 1| \\ \quad \equiv |01\rangle \langle 10|
    • ketket,brabraket \otimes ket, \quad bra \otimes bra

Qubit

ψ=α0+β1|\psi\rangle = \alpha|0\rangle + \beta|1\rangle

  • where α,β\alpha, \beta are complex numbers satisfying α2+β2=1|\alpha|^2 + |\beta|^2 = 1.
  • phase factor: eiϕe^{i\phi}, turn the state by angle ϕ\phi in the complex plane, but does not affect measurement probabilities.
    • eiϕ=1|e^{i\phi}| = 1

One-Qubit Gates

Identity Gate

I=(1001)\mathbb{I} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}

Pauli-X Gate

X=(0110)X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}

  • NOT gate

Pauli-Y Gate

Y=(0ii0)Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}

Pauli-Z Gate

Z=(1001)Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}

Hadamard Gate

H=12(1111)H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}

Rotation Gate

R(θ)=(cosθsinθsinθcosθ)R(\theta) = \begin{pmatrix} \cos{\theta} & \sin{\theta} \\ -\sin{\theta} & \cos{\theta} \end{pmatrix}

The Bloch Sphere

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

  • where 0θπ0 \leq \theta \leq \pi and 0ϕ<2π0 \leq \phi < 2\pi.
  • θ\theta: the polar (or colatitude) angle, measured from the "north pole" of the sphere.
    • polar angle: 편각
  • ϕ\phi: the azimuthal (or longitude) angle around the equator.
    • azimuthal angle: 방위각

bloch_sphere

Two-Qubit Gates

CNOT Gate

Controlled-NOT or CX gate

CNOT=(1000010000010010)CNOT = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}

  • CNOT gate flips the second qubit (target) if the first qubit (control) is 1|1\rangle.

SWAP Gate

SWAP=(1000001001000001)SWAP = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

  • SWAP gate exchanges the states of the two qubits.

Controlled-Z Gate

CZ=(1000010000100001)CZ = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}

  • CZ gate applies a Z gate to the second qubit if the first qubit is in state 1|1\rangle.

Bases

  • Computational Basis: {0,1}\{|0\rangle, |1\rangle\}
  • two qubits: {00,01,10,11}\{|00\rangle, |01\rangle, |10\rangle, |11\rangle\}
  • three qubits: {000,001,010,011,100,101,110,111}\{|000\rangle, |001\rangle, |010\rangle, |011\rangle, |100\rangle, |101\rangle, |110\rangle, |111\rangle\}

Rule of Thumb

What starts on the left of the tensor product stays on the left.

  • ψϕψϕψϕ|\psi\rangle \otimes |\phi\rangle \equiv |\psi\rangle|\phi\rangle \equiv |\psi\phi\rangle
  • (ψϕ)=ψϕ(|\psi\rangle \otimes |\phi\rangle)^* = \langle\psi| \otimes \langle\phi|
  • (αψ+βϕ)ω=αψω+βϕω(\alpha |\psi\rangle + \beta |\phi\rangle) \otimes |\omega\rangle = \alpha|\psi\rangle \otimes |\omega\rangle + \beta |\phi\rangle \otimes | \omega\rangle
  • (ψϕ)(ωη)=ψωϕη)(\langle\psi| \otimes \langle\phi|)(|\omega\rangle \otimes |\eta\rangle) = \langle\psi|\omega\rangle \cdot \langle\phi|\eta\rangle)
  • (A+B)C=AC+BC(A + B) \otimes C = A \otimes C + B \otimes C
  • A(B+C)=AB+ACA \otimes (B + C) = A \otimes B + A \otimes C
  • (AB)(CD)=(AC)(BD)(A \otimes B)(C \otimes D) = (AC) \otimes (BD)
  • (AB)=AB(A \otimes B)^* = A^* \otimes B^*

Entanglement

  • Ψ=α0000+α0101+α1010+α1111|\Psi\rangle = \alpha_{00} |00\rangle + \alpha_{01} |01\rangle + \alpha_{10} |10\rangle + \alpha_{11} |11\rangle
    • where Ψ2=1\|\Psi\rangle\|^2 = 1
  • If the state is not separable, it is entangled.
  • A state is separable if it can be written as a tensor product of two individual qubit state.
  • Ψ=12(00+01)=120(0+1)=012(0+1)|\Psi\rangle = \frac{1}{\sqrt{2}} (|00\rangle + |01\rangle) \\ \quad = \frac{1}{\sqrt{2}} |0\rangle \otimes (|0\rangle + |1\rangle) \\ \quad = |0\rangle \otimes \frac{1}{\sqrt{2}} (|0\rangle + |1\rangle)
    • separable
  • Φ=12(00+11)|\Phi\rangle = \frac{1}{\sqrt{2}} (|00\rangle + |11\rangle)
    • Φ=(a0+b1)(c0+d1)=ac00+ad01+bc10+bd11|\Phi\rangle = (a|0\rangle + b|1\rangle) \otimes (c|0\rangle + d|1\rangle) \\ \quad = ac|00\rangle + ad|01\rangle + bc|10\rangle + bd|11\rangle
    • ad=0,bc=0ad = 0, \quad bc = 0 which is impossible.
    • entangled

Latex

  • \texttip{}: Displays a tooltip when hovering over the equation.
  • \toggle{}: Toggles between two expressions.
  • \begin{align}: Aligns equations, where the ampersand (&) marks the alignment points.
  • \bbox[color, padding]{}: Puts a bounding box with the specified color and padding around an expression.
  • \boldsymbol{}: Renders a bold version of symbols like variables.
  • \cancel{}: Strikes through an expression.
  • \cancelto{value}{}: Strikes through and labels with the specified value.
  • \begin{cases}: Creates a piecewise function with conditions.
  • \color{}: Applies a color to text or math expressions. You can use predefined colors or hex values.
  • \enclose{}: Encloses an expression with various effects like circles or strikes.
  • [mathcolor="color", mathbackground="color"]: Adds custom colors to the enclosing effect.
  • \xmapsto{}: Creates an arrow with a label for mapping.
  • \xlongequal{}: Creates a long equals sign with a label.
  • \ce{}: Renders chemical equations or formulas.
  • \newcommand{\ket}[1]{\left|#1\right\rangle}: defines a custom command for ket notation. \ket{\psi}
  • \tag{}: Assigns a custom tag to an equation.
  • \unicode{}: Inserts a Unicode character using its code.

Ref