본문으로 건너뛰기

IQC 003

· 약 12분

Tensor Products

Kronecker product

  • a way to multiply vectors and matrices to generate bigger vectors and matrices

ψϕ=(ψ0ψ1)(ϕ0ϕ1)=(ψ0(ϕ0ϕ1)ψ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 \begin{pmatrix} \phi_0 \\ \phi_1 \end{pmatrix} \\ \\ \psi_1 \begin{pmatrix} \phi_0 \\ \phi_1 \end{pmatrix} \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

Tensor product of Matrices

AB=(a00Ba01Ba10Ba11B)A \otimes B = \begin{pmatrix} a_{00}B & a_{01}B \\ a_{10}B & a_{11}B \end{pmatrix}

  • The tensor product 0110|0\rangle \langle1| \otimes |1\rangle \langle0| is:

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 \cdot \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} & 1 \cdot \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} \\ 0 \cdot \begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix} & 0 \cdot \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}

  • To short hand this, we can write:

011001100110|0\rangle \langle 1| \otimes |1\rangle \langle 0| \equiv |0\rangle|1\rangle \langle 1| \langle 0| \equiv |01\rangle \langle 10|

  • (ab)(cd)=(ac)(bd)=acbd(|a\rangle \langle b|) \otimes (|c\rangle \langle d|) = (|a\rangle |c\rangle)(\langle b| \langle d|) = |ac\rangle \langle bd|

Bases

  • The basis for a single qubit is {0,1}\{|0\rangle, |1\rangle\}
  • It is given by taking the tensor product of the basis for each qubit:
    • {00,01,10,11}\{|0\rangle \otimes |0\rangle, |0\rangle \otimes |1\rangle, |1\rangle \otimes |0\rangle, |1\rangle \otimes |1\rangle\}
    • For short hand, we write {00,01,10,11}\{|00\rangle, |01\rangle, |10\rangle, |11\rangle\}
  • The computational basis for two qubits is {00,01,10,11}\{|00\rangle, |01\rangle, |10\rangle, |11\rangle\}
  • For 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\}

Matrices

{00,  01,  10,  11}\{|0\rangle\langle0|,\; |0\rangle\langle1|,\; |1\rangle\langle0|,\; |1\rangle\langle1|\}

  • forms a basis for the space of 2×22 \times 2 matrices
  • operator basis: a set of matrices that can be used to express any matrix as a linear combination of the basis matrices

(abcd)=a00+b01+c10+d11\begin{pmatrix} a & b \\ c & d \end{pmatrix} = a |0\rangle\langle0| + b |0\rangle\langle1| + c |1\rangle\langle0| + d |1\rangle\langle1|

  • One of the basis elements is: 0000=0000|0\rangle\langle0| \otimes |0\rangle\langle0| = |00\rangle\langle00|
  • Similarly 0001=0001|0\rangle\langle0| \otimes |0\rangle\langle1| = |00\rangle\langle01|
  • In total, the tensor products yields 4×4=164 \times 4 = 16 basis elements for the space of 4×44 \times 4 matrices: {0000,  0001,  0010,  0011,  0100,  0101,  ,  1111}.\{|00\rangle\langle00|,\; |00\rangle\langle01|,\; |00\rangle\langle10|,\; |00\rangle\langle11|,\; |01\rangle\langle00|,\; |01\rangle\langle01|,\; \ldots,\; |11\rangle\langle11|\}.

The Golden Rule of Tensor Products

What starts on the left of the tensor product says on the left

(AB)(ψϕ)=(Aψ)(Bϕ)(A \otimes B)(|\psi\rangle \otimes |\phi\rangle) = (A|\psi\rangle) \otimes (B|\phi\rangle)

(0011)(00)=(0011)(00)=(000)(110)=00=0(|0\rangle\langle0| \otimes |1\rangle\langle1|)(|00\rangle) \\ = (|0\rangle\langle 0| \otimes |1\rangle\langle1|)(|0\rangle \otimes |0\rangle) \\ \\ = (|0\rangle\langle0||0\rangle) \otimes (|1\rangle\langle1||0\rangle) \\ = |0\rangle \otimes 0 \\ = 0

  • ψϕψϕψϕ |\psi\rangle \otimes |\phi\rangle \equiv |\psi\rangle|\phi\rangle \equiv |\psi\phi\rangle
  • (ψϕ)=ψϕ(|\psi\rangle \otimes |\phi\rangle)^\dagger = \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 \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)=ACBD(A \otimes B)(C \otimes D) = AC \otimes BD
  • (AB)=AB(A \otimes B)^\dagger = A^\dagger \otimes B^\dagger

Entanglement

  • Single-qubit state is a two dimensional vector: ψ=α0+β1|\psi\rangle = \alpha|0\rangle + \beta|1\rangle
  • where α\alpha and β\beta are complex numbers such that ψ2=α2+β2=1\||\psi\rangle\|^2 = |\alpha|^2 + |\beta|^2 = 1
  • Two qubits ψ1\psi_1\rangle and ψ2\psi_2\rangle can be combined to form a four-dimensional vector: ψ12=ψ1ψ2ψ1ψ2ψ1ψ2 |\psi_{12}\rangle = |\psi_1\rangle \otimes |\psi_2\rangle \equiv |\psi_1\rangle|\psi_2\rangle \equiv |\psi_1\psi_2\rangle
  • Separable States: can be written as a tensor product of single-qubit states
    • Ψ=α0000+α0101+α1010+α1111=ψ1ψ2|\Psi\rangle = \alpha_{00} |00\rangle + \alpha_{01} |01\rangle + \alpha_{10} |10\rangle + \alpha_{11} |11\rangle \\ = |\psi_1\rangle| \otimes \psi_2\rangle
  • if the state is not separable, it is called entangled.
    • entangled: 12(00+11)\frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)
  • if ad=0ad = 0 and bc=0bc = 0, then acac or bdbd must also vanish.
    • separable: 12(00+01)=012(0+1)\frac{1}{2}(|00\rangle + |01\rangle) = |0\rangle \otimes \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle)

Two-Qubit Gates

  • Two-qubit gates are 4×44 \times 4 unitary matrices that act on two-qubit states.

CNOT Gate

Controlled NOT gate

  • flips target if control is 1|1\rangle

CNOT=(1000010000010010)=00I+11X\text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix} = |0\rangle\langle0| \otimes \mathbb I + |1\rangle\langle1| \otimes X

SWAP Gate

  • Exchanges the two qubits.

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

CZ Gate

Controlled Z gate

  • Applies ZZ to target if control is 1|1\rangle

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

Building Multi-Qubit Gates

  • Two qubits ψ1|\psi_1\rangle and ψ2|\psi_2\rangle can be combined to form a four-dimensional vector:
    • if U1U_1 and U2U_2 are single-qubit gates, then U1U2U_1 \otimes U_2 is a two-qubit gate that acts on the combined state ψ1ψ2|\psi_1\rangle \otimes |\psi_2\rangle.
    • (U1U2)(ψ1ψ2)=(U1ψ1)(U2ψ2)(U_1 \otimes U_2)(|\psi_1\rangle \otimes |\psi_2\rangle) = (U_1|\psi_1\rangle) \otimes (U_2|\psi_2\rangle)
    • For shorthand, U1U2ψ1ψ2U_1 U_2|\psi_1\psi_2\rangle

Order of Operations

  • When gates act independently, it doesn't matter the order in which they are apply with the understanding that if only a single gate is applied, identity acts on the other qubits.

(U1U2)=(IU2)(U1I)=(U1I)(IU2)(U_1 \otimes U_2) = (\mathbb I \otimes U_2)(U_1 \otimes \mathbb I) = (U_1 \otimes \mathbb I)(\mathbb I \otimes U_2)

  • Example: Apply XX to qubit 1 and HH to qubit 2, starting with 00|00\rangle:
  • (XI)00=10 (X \otimes \mathbb I)|00\rangle = |10\rangle
  • (IH)10=(IH)(10)=1H0=112(0+1)=12(10+11)=12(10+11)(\mathbb I \otimes H)|10\rangle \\ = (\mathbb I \otimes H)(|1\rangle \otimes |0\rangle) \\ = |1\rangle \otimes H|0\rangle \\ = |1\rangle \otimes \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) \\ = \frac{1}{\sqrt{2}}(|1\rangle \otimes |0\rangle + |1\rangle \otimes |1\rangle) \\ = \frac{1}{\sqrt{2}}(|10\rangle + |11\rangle)

Quantum Circuits

  • A quantum program is a sequance of gates applied to qubits, which are typically assumed to be initialized in the state 0|0\rangle.
  • Two qubits start in the state 00=00|0\rangle \otimes |0\rangle = |00\rangle

Hadamard and CNOT Circuit

CNOT(HI)00=CNOT(12(00+10))=12(00+11)CNOT(H \otimes \mathbb I)|00\rangle = CNOT\left(\frac{1}{\sqrt{2}}(|00\rangle + |10\rangle)\right) = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)

NameGatesMatrix
Pauli-XXX or \oplus(0110)\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}
Pauli-YYY(0ii0)\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}
Pauli-ZZZ(1001)\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}
Rotation-XRx(θ)R_x(\theta)(cosθ2isinθ2isinθ2cosθ2)\begin{pmatrix} \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix}
Rotation-YRy(θ)R_y(\theta)(cosθ2sinθ2sinθ2cosθ2)\begin{pmatrix} \cos\frac{\theta}{2} & \sin\frac{\theta}{2} \\ -\sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix}
Rotation-ZRz(θ)R_z(\theta)(eiθ/200eiθ/2)\begin{pmatrix} e^{i\theta/2} & 0 \\ 0 & e^{-i\theta/2} \end{pmatrix}
Phase ShiftPh(δ)Ph(\delta)(100eiδ)\begin{pmatrix} 1 & 0 \\ 0 & e^{i\delta} \end{pmatrix}
HadamardHH12(1111)\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}
PhaseSS(100i)\begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}
TTT(100eiπ/4)\begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}
  • S=Ph(π/2)S = Ph(\pi/2)
  • T=Ph(π/4)T = Ph(\pi/4)
  • Z=Ph(π)Z = Ph(\pi)

Multi-Qubit Gates

NameGatesMatrix
CNOTCNOT(1000010000010010)\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}
CZCZ(1000010000100001)\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}
SWAPSWAP(1000001001000001)\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}
ToffoliToffoli(1000000001000000001000000001000000001000000001000000000100000010)\begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix}
  • CNOT gate can be 00I+11X|0\rangle\langle0| \otimes \mathbb I + |1\rangle\langle1| \otimes X
    • 0stateI|0\rangle \text{state} \rightarrow \mathbb I (do nothing)
    • 1stateX|1\rangle \text{state} \rightarrow X (flip the target)
  • Larger gates can be built from smaller ones
  • Toffoli gate (CCNOT): flips the target if both controls are 1|1\rangle.
  • Toffoli=0000I4+1111X\text{Toffoli} = |00\rangle\langle00| \otimes \mathbb I_4 + |11\rangle\langle11| \otimes X
    • two control qubits and one target qubit
    • if both control qubits are 1|1\rangle, then apply XX
    • 110111|110\rangle \rightarrow |111\rangle
    • 111110|111\rangle \rightarrow |110\rangle
  • Can be generalized to nn-qubits: Cn1NOTC^{n-1}NOT gate, which flips the target if all n1n-1 control qubits are 1|1\rangle.
    • CNOT: 1011|10\rangle \rightarrow |11\rangle and 1110|11\rangle \rightarrow |10\rangle
    • Toffoli: 110111|110\rangle \rightarrow |111\rangle and 111110|111\rangle \rightarrow |110\rangle
    • 3-control gate: 11101111|1110\rangle \rightarrow |1111\rangle and 11111110|1111\rangle \rightarrow |1110\rangle

(I111111)I+111111U(\mathbb I - |111\ldots\rangle\langle 111\ldots|)\otimes \mathbb I + |111\ldots\rangle\langle 111\ldots|\otimes U

The Rules of Quantum Computing

Initialization

  • An nn-qubit computation starts in the all-zero state:

phi=000=000|phi\rangle = |0\rangle \otimes |0\rangle \otimes \ldots \otimes |0\rangle = |00\ldots0\rangle

Algorithm

  • Apply a sequence of unitary gates to obtain the final state:

U=U1U2Um    UψU = U_1U_2\ldots U_m \implies U|\psi\rangle

Measurement

The Born Rule

  • Reading nn qubits producs nn classical bits.
  • The probability of outcome b1b2bnb_1b_2\ldots b_n:

Pr(b1b2bn)=b1b2bnψ2Pr(b_1b_2\ldots b_n) = |\langle b_1b_2\ldots b_n|\psi\rangle|^2

  • ψ|\psi\rangle: initial state of the system
  • UU: an unitary matrix summing up the gates applied to the system
  • UψU|\psi\rangle: final state of the system
  • b1b2bnUψ\langle b_1b_2\ldots b_n|U|\psi\rangle: the amplitude of the outcome b1b2bnb_1b_2\ldots b_n
  • amplitude2|\text{amplitude}|^2: The probability of the outcome b1b2bnb_1b_2\ldots b_n being observed when measuring the system
    • if 12(00+11)\frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)
    • then Pr(00)=Pr(11)=12Pr(00) = Pr(11) = \frac{1}{2}

Post-measurement States

Measurement causes the state to collapse

  • Measuring all qubits: outcome b1bnb_1 \ldots b_n collapses state to b1bn|b_1 \ldots b_n\rangle
  • Measuring a subset: keep matching terms and renormalize.

ψ=c000000+c001001++c111111|\psi\rangle = c_{00\ldots0}|00\ldots0\rangle + c_{00\ldots1}|00\ldots1\rangle + \ldots + c_{11\ldots1}|11\ldots1\rangle

  • If we measure all qubits, we get outcome b1b2bnb_1b_2\ldots b_n
    • The state will collapse to ψ=b1b2bn|\psi'\rangle = |b_1b_2\ldots b_n\rangle
    • The probability of this outcome is Pr(b1b2bn)=b1b2bnψ2Pr(b_1b_2\ldots b_n) = |\langle b_1b_2\ldots b_n|\psi\rangle|^2

ψ=α00+β01+γ10+δ11|\psi\rangle = \alpha|00\rangle + \beta|01\rangle + \gamma|10\rangle + \delta|11\rangle

  • If we measure only the first qubit, and get outcome 00, the state maintains only terms with 00 in the first position:
    • 00|00\rangle and 01|01\rangle
    • The remaining state is ψ=α00+β01|\psi'\rangle = \alpha|00\rangle + \beta|01\rangle
    • 10|10\rangle and 11|11\rangle are removed from the state
  • This gives us the unnormalized state: ψunnorm=α00+β01 |\psi'\rangle_{unnorm} = \alpha|00\rangle + \beta|01\rangle
  • The probability of this outcome is Pr(0)=α2+β2Pr(0) = |\alpha|^2 + |\beta|^2
    • 00|00\rangle and 01|01\rangle are the only terms that contribute to the probability of outcome 00 for the first qubit
  • After measurement, the state must be ψ2=1\||\psi\|^2 = 1, so we need to renormalize the state:

ψ=(α00+β01)α2+β2|\psi'\rangle = \frac{(\alpha|00\rangle + \beta|01\rangle)}{\sqrt{|\alpha|^2 + |\beta|^2}}

QASM2.0

Quantum GateQASM EquivalentDescription
Rx(θ)R_x(\theta)rxRotation around X-axis: rx(pi/2) q[0];
Ry(θ)R_y(\theta)ryRotation around Y-axis: ry(0) q[0];
Rz(θ)R_z(\theta)rzRotation around Z-axis: rz(pi) q[0];
XXxPauli-gate bit flip: x q[0];
ZZzPauli-gate phase flip: z q[0];
XZXZyPauli-gate bit+phase flip: y q[0];
HHhHadamard gate: h q[0];
CNOTCNOTcxControlled NOT gate: cx q[0], q[1];
SWAPSWAPswapSwap two qubit registers: swap q[0], q[1];
CZCZczControlled ZZ gate: cz q[0], q[1];