Skip to content

simone-panico/Learning-Quantum-Computing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quantum Computing

This repository documents my journey learning quantum computing from the ground up. I'm building practical understanding of quantum algorithms and circuit design through coding and mathematical exploration.


Introduction

Dirac Notation

Quantum states are represented using the Dirac Notation, a shorthand for vector and matrix algebra.

The Ket ($\ket{\psi}$)

A Ket is a column vector representing the state of a qubit.

$$\displaystyle \ket{0} = \begin{bmatrix} 1 \\ 0 \end{bmatrix}, \quad \ket{1} = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$$

The Bra ($\bra{\psi}$)

A Bra is a row vector, specifically the conjugate transpose of a Ket.

$$\displaystyle \bra{0} = \begin{bmatrix} 1 & 0 \end{bmatrix}, \quad \bra{1} = \begin{bmatrix} 0 & 1 \end{bmatrix}$$

Dot Product ($\langle \phi | \psi \rangle$)

Combining a Bra and a Ket produces a scalar value representing the overlap between two states:

  • $\displaystyle \langle 0 | 0 \rangle = 1$
  • $\displaystyle \langle 0 | 1 \rangle = 0$

Quantum Gates

The X-Gate (Pauli-X)

The X-Gate is the quantum equivalent of the classical NOT gate. It performs a $\pi$ rotation around the X-axis of the Bloch sphere, effectively flipping the state of a qubit.

Matrix:

$$ X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} $$


Logic:

The X-Gate flips the state of the qubit:

  • $X\ket{0} \rightarrow \ket{1}$
  • $X\ket{1} \rightarrow \ket{0}$

X-Gate


The Y-Gate (Pauli-Y)

The Y-Gate performs a $\pi$ rotation around the Y-axis of the Bloch sphere. Like the X-gate, it flips the state of the qubit, but it also introduces a complex phase shift.

Matrix:

$$ Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} $$


Logic:

The Y-Gate flips the state and applies a phase:

  • $Y\ket{0} \rightarrow i\ket{1}$
  • $Y\ket{1} \rightarrow -i\ket{0}$

Y-Gate


The Z-Gate (Pauli-Z)

The Z-Gate performs a $\pi$ rotation around the Z-axis of the Bloch sphere. It is often called the Phase-Flip gate because it leaves the $\ket{0}$ state unchanged while flipping the phase of the $\ket{1}$ state.

Matrix:

$$ Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} $$


Logic:

The Z-Gate preserves the state but flips the phase if it is $\ket{1}$:

  • $Z\ket{0} \rightarrow \ket{0}$
  • $Z\ket{1} \rightarrow -\ket{1}$

Z-Gate


The H-Gate (Hadamard) - Superposition Creator

The H-Gate is one of the most fundamental tools in quantum computing. It acts as a bridge between the computational basis ($\ket{0}$ and $\ket{1}$) and a state of superposition. On the Bloch sphere, it performs a $180^\circ$ rotation around a diagonal axis (the X+Z axis), effectively swapping the Z and X axes.

Matrix:

$$ H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} $$


Logic:

The H-Gate places a qubit into an equal superposition:

  • $H\ket{0} \rightarrow \frac{1}{\sqrt{2}} (\ket{0} + \ket{1}) = \ket{+}$
  • $H\ket{1} \rightarrow \frac{1}{\sqrt{2}} (\ket{0} - \ket{1}) = \ket{-}$

H-Gate


The S-Gate (Phase Shift)

The S-Gate performs a $\pi/2$ ($90^\circ$) rotation around the Z-axis of the Bloch sphere. Like the Z-Gate, it only affects the phase of the $\ket{1}$ state, but it shifts it by a quarter-turn rather than a half-turn.

Matrix:

$$ S = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix} $$


Logic:

The S-Gate shifts the phase:

  • $S\ket{0} \rightarrow \ket{0}$
  • $S\ket{1} \rightarrow i\ket{1}$

The T-Gate

The T-Gate performs a $\pi/4$ ($45^\circ$) rotation around the Z-axis of the Bloch sphere. It is the square root of the S-Gate ($T^2 = S$) and the fourth root of the Z-Gate ($T^4 = Z$).

Matrix:

$$ T = \begin{bmatrix} 1 & 0 \\ 0 & e^{\frac{i\pi}{4}} \end{bmatrix} $$


Logic:

The T-Gate shifts the phase:

  • $T\ket{0} \rightarrow \ket{0}$
  • $T\ket{1} \rightarrow e^{\frac{i\pi}{4}}\ket{1}$

Calculating Probability

In quantum computing, a qubit's state is represented by amplitudes.

Given a state: $\displaystyle \ket{\psi} = \alpha\ket{0} + \beta\ket{1}$

The probability ($P$) is the square of the absolute value of the amplitude:

  • Probability of $\ket{0}$: $\displaystyle P(0) = |\alpha|^2$
  • Probability of $\ket{1}$: $\displaystyle P(1) = |\beta|^2$

Example:

After applying a Hadamard gate to $\ket{0}$, the qubit is in the state:

$\displaystyle \ket{+} = \frac{1}{\sqrt{2}}\ket{0} + \frac{1}{\sqrt{2}}\ket{1}$


The Math:

$\displaystyle P(0) = \left| \frac{1}{\sqrt{2}} \right|^2 = \frac{1}{2}$

$\displaystyle P(1) = \left| \frac{1}{\sqrt{2}} \right|^2 = \frac{1}{2}$


The Tensor Product ($\otimes$)

To represent multiple qubits at once, we use the Tensor Product. This operation combines individual qubit vectors into a larger vector representing the entire system.

Mathematical Definition

For two qubits $\ket{a}$ and $\ket{b}$, the combined state is:

$$\displaystyle \ket{a} \otimes \ket{b} = \begin{bmatrix} a_0 \\ a_1 \end{bmatrix} \otimes \begin{bmatrix} b_0 \\ b_1 \end{bmatrix} = \begin{bmatrix} a_0 b_0 \\ a_0 b_1 \\ a_1 b_0 \\ a_1 b_1 \end{bmatrix}$$

The Computational Basis

Using the tensor product, we define the four possible states for a two-qubit system:

$$\displaystyle \ket{00} = \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \end{bmatrix}, \quad \ket{01} = \begin{bmatrix} 0 \\ 1 \\ 0 \\ 0 \end{bmatrix}, \quad \ket{10} = \begin{bmatrix} 0 \\ 0 \\ 1 \\ 0 \end{bmatrix}, \quad \ket{11} = \begin{bmatrix} 0 \\ 0 \\ 0 \\ 1 \end{bmatrix}$$

Algorithms

Grover's Algorithm

Math Example

Goal: Search for $\ket{01}$


Initialization

$\ket{\psi_0}$ = $\ket{00}$

$\ket{\psi_1}$ = $H\ket{\psi_0}$ = $\frac{1}{2} (\ket{00} + \ket{01} + \ket{10} + \ket{11})$


Mark Target

$\ket{\psi_2}$ = $(X \otimes I) \ket{\psi_1}$ = $\frac{1}{2} (\ket{10} + \ket{11} + \ket{00} + \ket{01})$

$\ket{\psi_3}$ = $(CZ_{0,1}) \ket{\psi_2}$ = $\frac{1}{2} (\ket{10} - \ket{11} + \ket{00} + \ket{01})$

$\ket{\psi_4}$ = $(X \otimes I) \ket{\psi_3}$ = $\frac{1}{2} (\ket{00} - \ket{01} + \ket{10} + \ket{11})$


Diffusion Operator

$$ \begin{aligned} \ket{\psi_5} &= H\ket{\psi_4} = \frac{1}{2} \Bigg[ \frac{1}{2}(\ket{00} + \ket{01} + \ket{10} + \ket{11}) \\ &\quad - \frac{1}{2}(\ket{00} - \ket{01} + \ket{10} - \ket{11}) \\ &\quad + \frac{1}{2}(\ket{00} + \ket{01} - \ket{10} - \ket{11}) \\ &\quad + \frac{1}{2}(\ket{00} - \ket{01} - \ket{10} + \ket{11}) \Bigg] \end{aligned} $$

  1. $\frac{1}{2}\Big(\overset{\color{green}{1}}{\ket{00}} +\overset{\color{green}{1}}{\ket{01}} + \overset{\color{green}{1}}{\ket{10}} + \overset{\color{green}{1}}{\ket{11}}\Big)$

  2. $\frac{1}{2}\Big(-\overset{\color{red}{-1}}{\ket{00}} +\overset{\color{green}{1}}{\ket{01}} -\overset{\color{red}{-1}}{\ket{10}} +\overset{\color{green}{1}}{\ket{11}}\Big)$

  3. $\frac{1}{2}\Big(\overset{\color{green}{1}}{\ket{00}} +\overset{\color{green}{1}}{\ket{01}} -\overset{\color{red}{-1}}{\ket{10}} -\overset{\color{red}{-1}}{\ket{11}}\Big)$

  4. $\frac{1}{2}\Big(\overset{\color{green}{1}}{\ket{00}} -\overset{\color{red}{-1}}{\ket{01}} -\overset{\color{red}{-1}}{\ket{10}} +\overset{\color{green}{1}}{\ket{11}}\Big)$


  • $\ket{00} = \frac{1}{2} - \frac{1}{2} + \frac{1}{2} + \frac{1}{2} = 1$

  • $\ket{01} = \frac{1}{2} + \frac{1}{2} + \frac{1}{2} - \frac{1}{2} = 1$

  • $\ket{10} = \frac{1}{2} - \frac{1}{2} - \frac{1}{2} - \frac{1}{2} = -1$

  • $\ket{11} = \frac{1}{2} + \frac{1}{2} - \frac{1}{2} + \frac{1}{2} = 1$


$= \frac{1}{2}(\ket{00} + \ket{01} - \ket{10} + \ket{11})$


$\ket{\psi_6} = X \ket{\psi_5} = \frac{1}{2}(\ket{11} + \ket{10} - \ket{01} + \ket{00})$

$\ket{\psi_7} = (CZ_{0,1}) \ket{\psi_6} = \frac{1}{2}(-\ket{11} + \ket{10} - \ket{01} + \ket{00})$

$\ket{\psi_8} = X \ket{\psi_7} = \frac{1}{2}(-\ket{00} + \ket{01} - \ket{10} + \ket{11})$

$$ \begin{aligned} \ket{\psi_9} &= H\ket{\psi_8} = \frac{1}{2} \Bigg[ -\frac{1}{2}(\ket{00} + \ket{01} + \ket{10} + \ket{11}) \\ &\quad + \frac{1}{2}(\ket{00} - \ket{01} + \ket{10} - \ket{11}) \\ &\quad - \frac{1}{2}(\ket{00} + \ket{01} - \ket{10} - \ket{11}) \\ &\quad + \frac{1}{2}(\ket{00} - \ket{01} - \ket{10} + \ket{11}) \Bigg] \end{aligned} $$

  1. $\frac{1}{2}\Big(-\overset{\color{red}{-1}}{\ket{00}} -\overset{\color{red}{-1}}{\ket{01}} -\overset{\color{red}{-1}}{\ket{10}} -\overset{\color{red}{-1}}{\ket{11}}\Big)$

  2. $\frac{1}{2}\Big(\overset{\color{green}{1}}{\ket{00}} -\overset{\color{red}{-1}}{\ket{01}} +\overset{\color{green}{1}}{\ket{10}} -\overset{\color{red}{-1}}{\ket{11}}\Big)$

  3. $\frac{1}{2}\Big(-,\overset{\color{red}{-1}}{\ket{00}} -\overset{\color{red}{-1}}{\ket{01}} +\overset{\color{green}{1}}{\ket{10}} +\overset{\color{green}{1}}{\ket{11}}\Big)$

  4. $\frac{1}{2}\Big(\overset{\color{green}{1}}{\ket{00}} -\overset{\color{red}{-1}}{\ket{01}} -\overset{\color{red}{-1}}{\ket{10}} +\overset{\color{green}{1}}{\ket{11}}\Big)$


  • $\ket{00} = - \frac{1}{2} + \frac{1}{2} - \frac{1}{2} + \frac{1}{2} = 0$

  • $\ket{01} = -\frac{1}{2} - \frac{1}{2} - \frac{1}{2} - \frac{1}{2} = -2$

  • $\ket{10} = -\frac{1}{2} - \frac{1}{2} + \frac{1}{2} + \frac{1}{2} = 0$

  • $\ket{11} = \frac{1}{2} - \frac{1}{2} - \frac{1}{2} + \frac{1}{2} = 0$


$= \frac{1}{2}(-2\ket{01})$

$= -\ket{01}$

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors