Skip to content

rafaelfgx/QuantumComputing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quantum Computing

It seems like magic, but it is simply nature and the universe in their most intrinsic and fundamental state!

The universe is not classical! Our intuition is limited, shaped by large, slow, and predictable scales!

When we go down to the fundamental level, reality is not deterministic! It is wave-like, probabilistic, and deeply relational!

For centuries, we tried to force the universe to think like classical machines! But now we do the opposite: we build machines that think like the universe itself!

Qubits are not tricks. Superposition is not a mystery. Entanglement is not a miracle. They are facts of nature!

Superpowers

  • Explore many possibilities simultaneously! It's like calculating multiple parallel universes and then collapsing into the correct result!

  • Simulate nature at its deepest and most intrinsic level, because everything that exists in the universe obeys quantum laws!

  • Simulate complex molecules, create new materials, and dramatically accelerate drug discovery!

  • For specific tasks, a quantum computer can solve problems in a fraction of the time (seconds, hours, days) that classical supercomputers would take millions or billions of years!

  • It can break current cryptography with ease, while at the same time making possible cryptography grounded in the very laws of physics - impossible to spy on or break without being detected!

Quantum Physics

Energy Quantization

  • Definition: Energy quantization is the principle that certain physical systems can possess only discrete energy values rather than a continuous range. Energy changes occur through the absorption or emission of fixed amounts called quanta.

  • Example: In an atom, electrons occupy specific energy levels. When an electron transitions between levels, it absorbs or emits a photon whose energy equals the difference between those levels.

  • Analogy: Like standing on the steps of a staircase, a system can occupy only specific energy levels and never the spaces between them.

Wave-Particle Duality

  • Definition: Wave-particle duality states that quantum entities such as electrons and photons exhibit both wave-like and particle-like behavior depending on the experimental conditions.

  • Example: In the double-slit experiment, electrons passing through two openings create an interference pattern typical of waves, yet they are detected as localized impacts like particles.

  • Analogy: Like a cylinder casting different shadows depending on the viewing angle, a quantum object can appear wave-like or particle-like depending on how it is observed.

Heisenberg Uncertainty Principle

  • Definition: The Heisenberg uncertainty principle states that certain pairs of physical quantities, such as position and momentum, cannot be simultaneously determined with arbitrary precision.

  • Example: Increasing the precision in measuring an electron's position necessarily increases the uncertainty in its momentum.

  • Analogy: Like trying to photograph a fast-moving ball, capturing its exact position clearly reduces information about how fast it is moving.

Superposition

  • Definition: Superposition is the principle that a quantum system can exist simultaneously in multiple possible states until a measurement produces a single definite outcome.

  • Example: An electron in an atom is described by a combination of possible states until a measurement determines its specific state.

  • Analogy: Like a spinning coin that represents both heads and tails until it lands.

Entanglement

  • Definition: Entanglement is a quantum phenomenon in which two or more particles share a single correlated quantum state such that measurements performed on one particle are statistically related to measurements on the other.

  • Example: Two entangled photons measured for polarization produce correlated results even when separated by large distances.

  • Analogy: Like two perfectly synchronized dice that always produce related outcomes regardless of how far apart they are rolled.

Pauli Exclusion Principle

  • Definition: The Pauli exclusion principle states that no two identical fermions can occupy the same quantum state within the same quantum system simultaneously.

  • Example: Electrons in an atom fill orbitals in such a way that no two electrons share the same set of quantum numbers.

  • Analogy: Like assigned seats in a theater where each seat can be occupied by only one person.

Wave Function Collapse

  • Definition: Wave function collapse refers to the transition of a quantum system from a superposition of possible states to a single definite state as a result of measurement.

  • Example: Before measurement, an electron is described by a probability distribution of possible positions. Measuring its position yields one specific outcome.

  • Analogy: Like drawing a card from a shuffled deck: before the card is revealed, many outcomes are possible, but only one appears when the card is shown.

Probability and Statistical Interpretation

  • Definition: The statistical interpretation of quantum mechanics states that the wave function describes probability distributions for possible measurement outcomes rather than deterministic predictions.

  • Example: The square of the wave function gives the probability of finding an electron in a particular region around the nucleus.

  • Analogy: Like a weather forecast that predicts the probability of rain rather than guaranteeing whether it will occur.

Quantum Tunneling

  • Definition: Quantum tunneling is the phenomenon in which a particle has a nonzero probability of passing through a potential energy barrier even when its energy is lower than the barrier height.

  • Example: Quantum tunneling allows nuclear fusion reactions in stars and enables electron transport in devices such as tunnel diodes.

  • Analogy: Like a ball occasionally appearing on the other side of a hill without climbing over it.

Principle of Complementarity

  • Definition: The principle of complementarity states that different experimental setups reveal mutually exclusive properties of quantum systems, such as wave behavior or particle behavior, both of which are necessary for a complete description.

  • Example: In the double-slit experiment, measuring which slit a particle passes through removes the interference pattern.

  • Analogy: Like observing a sculpture from different angles, where each perspective reveals a different aspect of the same object.

Quantum Computing

Qubit

  • Definition: A qubit is the fundamental unit of quantum information. Unlike a classical bit, which can take the value 0 or 1, a qubit can exist in a superposition of both states. It is mathematically represented as |ψ⟩ = α|0⟩ + β|1⟩, where α and β are complex probability amplitudes and |α|² + |β|² = 1.

  • Example: A qubit initialized in state |0⟩ can be transformed by a Hadamard gate into a superposition where measurement yields 0 or 1 with equal probability.

Superposition

  • Definition: Superposition is the property that allows a quantum system to exist simultaneously in multiple possible states until a measurement produces a single definite outcome.

  • Example: A qubit can exist in a combination of |0⟩ and |1⟩ before measurement.

Measurement

  • Definition: Measurement is the process of observing a quantum system, causing the superposition to collapse into one of the possible basis states according to probabilities determined by the amplitudes.

  • Example: Measuring a qubit in the state |ψ⟩ = α|0⟩ + β|1⟩ produces outcome 0 with probability |α|² and outcome 1 with probability |β|².

Entanglement

  • Definition: Entanglement is a quantum phenomenon in which two or more qubits share a correlated quantum state such that the measurement outcomes of one are statistically related to those of the others.

  • Example: Two qubits prepared in a Bell state produce correlated results when measured, even when separated by large distances.

Decoherence

  • Definition: Decoherence is the process by which a quantum system loses its coherent quantum properties due to interaction with the environment, causing superposition and entanglement to degrade.

  • Example: Noise and thermal interactions in a quantum processor gradually destroy fragile quantum states.

Quantum State

  • Definition: A quantum state is the complete mathematical description of a quantum system. It is typically represented as a vector in a Hilbert space and contains all information about probabilities and correlations.

  • Example: A single-qubit quantum state can be written as |ψ⟩ = α|0⟩ + β|1⟩.

Bra–Ket (Dirac Notation)

  • Definition: Dirac notation is a mathematical representation used in quantum mechanics. A ket |ψ⟩ represents a state vector, while a bra ⟨ψ| represents its conjugate transpose.

  • Example: Inner products such as ⟨ψ|ψ⟩ are used to calculate probabilities.

Probability Amplitude

  • Definition: A probability amplitude is a complex number associated with a quantum state. The probability of observing a specific outcome is given by the squared magnitude of its amplitude.

  • Example: If a qubit has amplitude α for state |0⟩, the probability of measuring 0 is |α|².

Quantum Gate

  • Definition: A quantum gate is a reversible unitary operation that transforms the state of one or more qubits. Quantum gates form the basic operations of quantum algorithms.

  • Example: The Hadamard gate creates superposition, while the CNOT gate creates entanglement between qubits.

Quantum Circuit

  • Definition: A quantum circuit is a sequence of quantum gates applied to qubits to perform a quantum computation, followed by measurement.

  • Example: Grover's search algorithm is implemented using a specific sequence of quantum gates in a circuit.

Bloch Sphere

  • Definition: The Bloch sphere is a geometric representation of the state of a single qubit as a point on the surface of a unit sphere.

  • Example: The states |0⟩ and |1⟩ correspond to the north and south poles of the sphere.

Quantum Interference

  • Definition: Quantum interference occurs when probability amplitudes combine constructively or destructively, affecting measurement probabilities.

  • Example: Quantum algorithms exploit interference to amplify the probability of correct answers while suppressing incorrect ones.

No-Cloning Theorem

  • Definition: The no-cloning theorem states that it is impossible to create an exact copy of an arbitrary unknown quantum state.

  • Example: A qubit in an unknown superposition cannot be perfectly duplicated.

Quantum Register

  • Definition: A quantum register is a collection of multiple qubits used together to store and process quantum information.

  • Example: A register with n qubits can represent a superposition of 2ⁿ possible classical states simultaneously.

Unitary Evolution

  • Definition: The evolution of a closed quantum system is described by unitary transformations that preserve the total probability of the quantum state.

  • Example: Applying a sequence of quantum gates to a qubit corresponds to unitary evolution.

Density Matrix

  • Definition: A density matrix is a mathematical representation of a quantum state that can describe both pure states and statistical mixtures.

  • Example: Density matrices are used to model quantum systems interacting with noisy environments.

Quantum Error Correction

  • Definition: Quantum error correction is a set of techniques that protect quantum information from noise and decoherence using redundancy and entanglement.

  • Example: The Shor code encodes one logical qubit across multiple physical qubits to detect and correct errors.

Quantum Speedup

  • Definition: Quantum speedup refers to the computational advantage achieved by quantum algorithms over classical algorithms for certain problems.

  • Example: Shor's algorithm can factor large integers exponentially faster than the best known classical algorithms.

Quantum Architecture

Universal Quantum Computer

  • Definition: A universal quantum computer is a device capable of performing any quantum computation by applying a universal set of quantum gates to qubits.

  • Analogy: Like a fully equipped kitchen containing all the tools needed to prepare any possible recipe.

Quantum Processing Unit (QPU)

  • Definition: A quantum processing unit is the hardware component that performs quantum operations on qubits, analogous to the role of a CPU in classical computers.

  • Analogy: Like a stage where performers (qubits) execute coordinated movements directed by a choreography (quantum gates).

Types of Physical Qubits

  • Definition: Physical qubits are implemented using different technologies such as superconducting circuits, trapped ions, quantum dots, photonic systems, and neutral atoms. Each approach presents different trade-offs in coherence, control, and scalability.

  • Analogy: Like different types of engines in vehicles, each optimized for particular performance characteristics.

Quantum Error Correction

  • Definition: Quantum error correction consists of techniques that protect quantum information from noise and decoherence by encoding logical qubits into multiple physical qubits using quantum error-correcting codes.

  • Example: Codes such as the Shor code, Steane code, and surface code distribute quantum information across several qubits to detect and correct errors.

  • Analogy: Like using multiple redundant safety systems to ensure that a failure in one component does not compromise the entire system.

Quantum Circuits

  • Definition: Quantum circuits represent computations as ordered sequences of quantum gates applied to qubits, followed by measurement operations.

  • Example: Algorithms such as Grover’s search or Shor’s factoring algorithm are implemented as quantum circuits.

  • Analogy: Like a choreography where each movement must occur in a specific sequence to produce the final performance.

Repeated Measurement and Readout

  • Definition: Because quantum measurements are probabilistic, results are often obtained by repeating the same circuit many times and collecting statistics from the outcomes.

  • Example: Running a quantum circuit thousands of times allows estimation of the probability distribution of measurement results.

  • Analogy: Like flipping a biased coin many times to estimate the probability of heads.

Topological Quantum Computing

  • Definition: Topological quantum computing uses quantum states protected by topological properties of the system, making them inherently more resistant to noise and decoherence.

  • Example: Proposed implementations involve quasiparticles such as Majorana modes that store quantum information in topological states.

  • Analogy: Like a knot in a rope that remains intact even when the rope is twisted or stretched.

Logical vs Physical Qubits

  • Definition: Physical qubits are the hardware-level implementations susceptible to noise and errors, while logical qubits are encoded combinations of multiple physical qubits designed to provide error-resistant quantum information.

  • Example: A single logical qubit in a surface code may require dozens or hundreds of physical qubits.

  • Analogy: Like a team working together to ensure reliability even if individual members fail.

Quantum Communication

  • Definition: Quantum communication uses quantum states to transmit information, enabling protocols such as quantum key distribution and quantum teleportation.

  • Example: Quantum key distribution allows two parties to generate secure encryption keys by detecting any eavesdropping attempts.

  • Analogy: Like sending a message sealed in a container that reveals any attempt at tampering.

Quantum Gates

In quantum computing, quantum gates are unitary operations applied to qubits. They transform the quantum state of one or more qubits and are the fundamental building blocks of quantum circuits. A qubit state can be represented as |ψ⟩ = α|0⟩ + β|1⟩ where α and β are complex amplitudes.

Pauli-X Gate (Bit Flip)

  • Logical Purpose:

    • The X gate flips the logical value of a qubit.
  • Transformation

    • |0⟩ → |1⟩
    • |1⟩ → |0⟩
  • Logical Role

    • Equivalent to a classical NOT operation

    • Used to initialize qubits

    • Used to invert logical conditions in circuits

  • Common Uses

    • State preparation

    • Circuit control logic

    • Reversible computation

Pauli-Z Gate (Phase Flip)

  • Logical Purpose

    • The Z gate changes the phase of the |1⟩ component without altering probabilities.
  • Transformation

    • |0⟩ → |0⟩

    • |1⟩ → −|1⟩

  • Logical Role

    • Phase manipulation

    • Marking states in algorithms

    • Quantum interference control

  • Common Uses

    • Marking step in Grover's algorithm

    • Phase-based algorithms

    • Error correction circuits

Pauli-Y Gate

  • Logical Purpose

    • The Y gate performs both a bit flip and a phase change.
  • Transformation

    • |0⟩ → i|1⟩

    • |1⟩ → −i|0⟩

  • Logical Role

    • Combined state inversion and phase rotation

    • Used in complete rotations of qubit states

  • Common Uses

    • Quantum simulations

    • Rotational decompositions

Hadamard Gate (H)

  • Logical Purpose

    • The Hadamard gate creates superposition from computational basis states.
  • Transformation

    • |0⟩ → (|0⟩ + |1⟩)/√2

    • |1⟩ → (|0⟩ − |1⟩)/√2

  • Logical Role

    • Generates quantum parallelism

    • Enables interference between amplitudes

    • Changes measurement basis

  • Common Uses

    • Initialization of quantum algorithms

    • Creating superposition registers

    • Grover's algorithm

    • Shor's algorithm

S Gate (Phase π/2)

  • Logical Purpose

    • Adds a phase shift of π/2 to the |1⟩ state.
  • Transformation

    • |0⟩ → |0⟩

    • |1⟩ → i|1⟩

  • Logical Role

    • Precise phase manipulation

    • Construction of more complex gates

  • Common Uses

    • Phase interference control

    • Circuit decompositions

T Gate (Phase π/4)

  • Logical Purpose

    • Adds a phase shift of π/4 to the |1⟩ state.
  • Transformation

    • |0⟩ → |0⟩

    • |1⟩ → e^(iπ/4)|1⟩

  • Logical Role

    • Enables universal quantum computation when combined with H and CNOT

    • Allows fine phase adjustments

  • Common Uses

    • Universal gate sets

    • Fault-tolerant quantum circuits

Rotation Gates (Rx, Ry, Rz)

  • Logical Purpose

    • Rotation gates rotate the qubit state around axes of the Bloch sphere.
  • Types

    • Rx(θ): Rotation around the X-axis.

    • Ry(θ): Rotation around the Y-axis.

    • Rz(θ): Rotation around the Z-axis.

  • Logical Role

    • Continuous transformation of qubit states

    • Preparation of arbitrary quantum states

  • Common Uses

    • Hardware-level operations

    • Quantum simulations

    • Variational quantum algorithms

CNOT Gate (Controlled-NOT)

  • Logical Purpose

    • A two-qubit gate that performs a conditional bit flip.
  • Rule

    • If control = 1 apply X to target
    • If control = 0 do nothing
  • Transformations

    • |00⟩ → |00⟩

    • |01⟩ → |01⟩

    • |10⟩ → |11⟩

    • |11⟩ → |10⟩

  • Logical Role

    • Conditional logic

    • Creation of entanglement

    • Information propagation between qubits

  • Common Uses

    • Bell state generation

    • Entanglement circuits

    • Quantum algorithms

CZ Gate (Controlled-Z)

  • Logical Purpose

    • Applies a phase shift when both qubits are in |11⟩.
  • Transformation

    • |11⟩ → −|11⟩
  • Logical Role

    • Conditional phase manipulation

    • Entanglement creation

  • Common Uses

    • Entanglement circuits

    • Phase-based quantum algorithms

SWAP Gate

  • Logical Purpose

    • Exchanges the quantum states of two qubits.
  • Transformations

    • |01⟩ → |10⟩

    • |10⟩ → |01⟩

  • Logical Role

    • Moving quantum information across a circuit
  • Common Uses

    • Hardware connectivity constraints

    • Quantum routing

Toffoli Gate (CCNOT)

  • Logical Purpose

    • A three-qubit gate with two control qubits and one target.
  • Rule

    • If control1 = 1 AND control2 = 1 → flip target
  • Logical Role

    • Reversible classical logic

    • Logical AND operation

  • Common Uses

    • Quantum arithmetic

    • Reversible computing

    • Error correction circuits

Universal Gate Sets

A universal gate set can approximate any quantum operation.

Example universal set:

  • Hadamard (H)

  • T gate

  • CNOT

Using only these gates, any quantum circuit can be constructed.

Limits of Classical Quantum Simulation

To simulate 1000 qubits classically, you need $2^{1000}$ complex numbers to represent the state vector.

There are not enough atoms in the observable universe to build a classical computer with that much memory!

Usually, local simulators reach their limit at around 25 to 30 qubits.

Quantum scaling is exponential! Every additional qubit doubles the amount of memory required!

The observable universe contains roughly $2^{266}$ atoms. A simulation of 1000 qubits would require $2^{1000}$ states.

It would take about $2^{734}$ observable universes to turn every atom into 1 bit — and even then, simulation would still be impossible!

Qubits States ($2^n$) Memory Required Equivalent
10 $2^{10}$ 16 KB Text File
20 $2^{20}$ 16 MB Photograph
30 $2^{30}$ 16 GB PC
40 $2^{40}$ ~1 Trillion 16 TB Storage
50 $2^{50}$ ~1 Quadrillion 16 PB Supercomputer
1000 $2^{1000}$ Impossible Exceeds Atoms In The Observable Universe

Grover's Algorithm

Classical computers struggle to search large unsorted datasets. For a space of 1 billion items, a classical algorithm may need up to 1 billion checks in the worst case because it must examine each item individually. The time complexity is linear, $O(N)$, which becomes inefficient for very large datasets.

Grover's Algorithm, developed by Lov K. Grover in 1996, is a quantum search algorithm that provides a quadratic speedup. It uses quantum amplitude amplification and interference to increase the probability of measuring the correct solution without requiring $N$ classical checks.

The problem is typically defined using an oracle function $f(x)$ such that $f(x)=1$ if $x$ is a solution and $f(x)=0$ otherwise. The algorithm encodes all possible inputs in a quantum superposition and iteratively amplifies the probability amplitude of states that satisfy the oracle condition.

This amplification is performed using two operations: the oracle, which marks solution states by applying a phase flip, and the diffusion operator, which reflects the quantum state about the average amplitude of all states. Each Grover iteration increases the amplitude of the correct states through constructive interference while reducing the amplitude of incorrect states through destructive interference.

Grover's Algorithm requires approximately $\frac{\pi}{4}\sqrt{N}$ iterations to maximize the probability of measuring the correct result when there is a single solution. For example, in a search space of $2^{30}$ (~1 billion items), a classical computer may require up to 1 billion checks, while Grover's algorithm needs only about 33 thousand iterations. This reduces the complexity from $O(N)$ to $O(\sqrt{N})$, providing a quadratic speedup for unstructured search problems and forming an important example of quantum advantage.

Classical vs Quantum Comparison

Search Space Classical Operations Grover Iterations Speedup
$2^{20}$ 1 million ~1 thousand ~1 thousand
$2^{30}$ 1 billion ~33 thousand ~33 thousand
$2^{40}$ 1 trillion ~1 million ~1 million
$2^{50}$ 1 quadrillion ~33 million ~33 million
$2^{60}$ 1 quintillion ~1 billion ~1 billion

Shor's Algorithm

Classical computers struggle to factor very large integers, especially numbers with hundreds of digits. This difficulty forms the basis of RSA encryption.

The General Number Field Sieve (GNFS) is the most efficient known classical algorithm for factoring large integers. Its running time is sub-exponential. Even with GNFS, factoring very large numbers used in modern cryptography is considered computationally infeasible with current classical resources.

Shor's Algorithm, developed by Peter Shor in 1994, is a quantum algorithm that factors large numbers efficiently. It runs in polynomial time, representing an exponential speedup over known classical algorithms.

The algorithm reduces integer factorization to a period-finding problem. Given the function $f(x) = a^x \pmod{N}$, where $N$ is the number to factor and $a$ is a randomly chosen integer less than $N$ such that $\gcd(a, N) = 1$, the goal is to determine the period $r$, the smallest integer satisfying $a^r \equiv 1 \pmod{N}$.

If such a period $r$ is found and $r$ is even, then $a^r - 1 = (a^{r/2}-1)(a^{r/2}+1)$, which allows factors of $N$ to be extracted using greatest common divisors.

Quantum computers create superpositions representing many possible inputs $x$ simultaneously. Through quantum interference, states consistent with the periodic structure of the function are amplified.

Shor's Algorithm then applies the Quantum Fourier Transform (QFT), which converts this periodic structure into a probability distribution containing information about rational values of the form $k/r$.

A classical post-processing step using the continued fractions method recovers the candidate period $r$ from this measurement.

If $r$ is even and $a^{r/2} \not\equiv -1 \pmod{N}$, the algorithm computes $\gcd(a^{r/2}-1, N)$ and $\gcd(a^{r/2}+1, N)$, which yield non-trivial factors of $N$. Otherwise, the process is repeated with another random value of $a$.

Classical vs Quantum Comparison

Estimated Operations

Bits Classical Shor Speedup
128 ~67 million ~2 Million ~32
256 ~1.1 trillion ~16 Million ~65 thousand
512 ~1.3 octillion ~134 Million ~10 Quintillion
1024 ~1.6 quattuordecillion ~1 Billion Astronomical
2048 ~2.6 quindecillion ~8.5 Billion Astronomical
4096 ~670 sexdecillion ~68 Billion Astronomical

GNFS grows sub-exponentially, increasing extremely fast with the number size.

Shor grows polynomially, making even very large numbers theoretically factorable.

The speedup highlights the astronomical difference between classical and quantum factoring.

Estimated Time

Bits Classical Shor Logical Qubits
2048 Infeasible ~8 Hours ~4096
4096 Infeasible ~2.5 Days ~8192
8192 Infeasible ~3 Weeks ~16384
16384 Infeasible ~5.5 Months ~32768
32768 Infeasible ~3.7 Years ~65536

Infeasible means that GNFS would require longer than the age of the universe.

Shor assumes a fully fault-tolerant large-scale quantum computer.

Logical qubits represent the effective qubits required after error correction.

Code

Contributors