qubit
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| qubit [May 23, 2026 at 18:16] – Ivan Janevski | qubit [June 13, 2026 at 03:46] (current) – Ivan Janevski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| # Qubit | # Qubit | ||
| - | **Qubit** is the quantum | + | **Qubit** |
| - | A classical bit can be `0` or `1`. There are no probabilities involved at all, but we can assign them anyway. If a bit is `1`, then it's `1` with 100% probability | + | A classical bit can only be 0 or 1. A qubit can be in a **superposition**: |
| - | A qubit works in a similar way. It also has two states: $\lvert 0\rangle$ and $\lvert 1\rangle$, except | + | A general |
| - | $$\lvert\psi\rangle = a\lvert 0\rangle + b\lvert 1\rangle$$ | + | $$\lvert\psi\rangle = \begin{pmatrix}a\\b\end{pmatrix} = a\underbrace{\begin{pmatrix}1\\ 0\end{pmatrix}}_{\lvert 0\rangle} + b\underbrace{\begin{pmatrix}0\\1\end{pmatrix}}_{\lvert 1\rangle} = a\lvert 0\rangle + b\lvert 1\rangle, \qquad |a|^2 + |b|^2 = 1$$ |
| - | These probabilities $a$ and $b$ are not percentages. Rather, they are complex numbers called " | + | ## Basis states |
| - | A qubit state continues | + | There are infinitely many single-qubit states but three orthonormal bases are standard, corresponding |
| - | But how do we know whether a qubit is going to collapse to `0` or `1` if $a$ and $b$ are complex numbers rather than percentages? | + | ### Z-basis |
| - | $$P_0 = |a|^2 \qquad P_1 = |b|^2$$ | + | The Z-basis states |
| - | We do, however, require the qubit always exists as *at least something* with 100% probability when we measure it i.e. a qubit can't half exist or exist with 150% probability. Therefore the square magnitudes must add up to 100% which in probability theory is written as $1$. This is also called the second axiom of probability: | + | $$\lvert 0\rangle = \begin{pmatrix}1\\0\end{pmatrix} \qquad \lvert 1\rangle = \begin{pmatrix}0\\1\end{pmatrix}$$ |
| - | $$|a|^2 + |b|^2 = 1$$ | + | ^ State ^ Description ^ |
| + | | [[ket-0|$\lvert 0\rangle$]] | Eigenstate of Z with eigenvalue $+1$. Default initial state of every qubit. | ||
| + | | [[ket-1|$\lvert 1\rangle$]] | Eigenstate of Z with eigenvalue $-1$. | | ||
| + | ### X-basis (Hadamard basis) | ||
| - | ## States | + | The X-basis states $\lvert +\rangle$ and $\lvert -\rangle$ are the eigenstates of the Pauli X gate. They look " |
| - | ### Basis state | + | $$\lvert +\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\1\end{pmatrix} \qquad \lvert -\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\{-1}\end{pmatrix}$$ |
| - | ### Pure state | + | ^ State ^ Expansion in computational basis ^ Description ^ |
| + | | [[ket-plus|$\lvert +\rangle$]] | $\tfrac{1}{\sqrt{2}}(\lvert 0\rangle + \lvert 1\rangle)$ | Eigenstate of X with eigenvalue $+1$. Prepared from $\lvert 0\rangle$ by $H$. | | ||
| + | | [[ket-minus|$\lvert -\rangle$]] | $\tfrac{1}{\sqrt{2}}(\lvert 0\rangle - \lvert 1\rangle)$ | Eigenstate of X with eigenvalue $-1$. Prepared from $\lvert 1\rangle$ by $H$. | | ||
| - | A qubit is in a pure state when it's in one of the basis states with 100% probability. When we say 100% probability we mean a complex probability amplitude $1 + i0$. Conversely, when we say 0% probability we mean a complex probability amplitude $0 + i0$. | + | ### Y-basis (Phase basis) |
| - | Because there are only two basis states, and a pure state is when a qubit is in one of the two basis states, there are also only two pure states: | + | The Y-basis states |
| - | $$ \lvert\psi\rangle = \underbrace{\left(1 + i0\right)}_{a}\cdot \lvert | + | $$\lvert |
| - | $$ \lvert\psi\rangle | + | ^ State ^ Expansion in computational basis ^ Description ^ |
| + | | [[ket-plus-i|$\lvert | ||
| + | | [[ket-minus-i|$\lvert -i\rangle$]] | $\tfrac{1}{\sqrt{2}}(\lvert 0\rangle - i\lvert 1\rangle)$ | Eigenstate of Y with eigenvalue $-1$. | | ||
| - | ### Mixed state | + | ## Measurement |
| - | A qubit is in a mixed state when total probability distributed among states. | + | |
| - | $$ \lvert\psi\rangle = \underbrace{\left(\frac{1}{2} + i0\right)}_{a}\cdot | + | Measuring a qubit in the Z basis gives outcome 0 or 1 and collapses the state. For $\lvert\psi\rangle = a\lvert 0\rangle + b\lvert 1\rangle$, the [[born-rule|Born rule]] gives the probabilities: |
| - | $$ \lvert\psi\rangle = \left(\frac{1}{\sqrt{2}} + i 0 \right)\cdot\lvert 0\rangle + \left(\frac{1}{\sqrt{2}} + i\frac{1}{\sqrt{2}}\right)\cdot \lvert 1\rangle$$ | + | $$P(0) = |a|^2 \qquad P(1) = |b|^2$$ |
| - | When a qubit is measured | + | Result 0 collapses |
| - | ### Invalid state | + | ## Bloch sphere |
| - | A qubit is in an invalid state when the square magnitutdes of its probability amplitudes don't add up to $1$. This is not allowed by quantum mechanics so a qubit will never find itself in an invalid state. | + | |
| - | An example is a qubit that' | + | Every pure qubit state corresponds to a unique point on the surface of the [[bloch-sphere|Bloch sphere]], a unit sphere |
| - | $$ \lvert\psi\rangle = \left(1 + 0i\right)\lvert | + | |
| - | When we sum the square magnitudes we get the result | + | $$\lvert\psi\rangle = \cos\tfrac{\theta}{2}\lvert 0\rangle |
| - | $$ |1 + 0i|^2 + |1 + 0i|^2 = 1^2 + 1^2 = 2$$ | + | |
| - | The interpretation of this result | + | The north pole ($\theta = 0$) is $\lvert 0\rangle$; |
| - | ## Evolution | + | ## Gates |
| - | The equation that governs quantum mechanics is the Shrodinger equation. In the most general case it's written in the following form. | + | |
| - | $$i\hbar\frac{\partial}{\partial t}\lvert \psi\rangle = H\lvert\psi\rangle$$ | + | Single-qubit gates are $2\times 2$ unitary matrices acting on $\mathbb{C}^2$. The three Pauli gates and the Hadamard are the most common. |
| - | The ket $\lvert \psi\rangle$ is a quantum state. Mathematically, | + | $$X = \begin{pmatrix}0& |
| + | \qquad Y = \begin{pmatrix}0& | ||
| + | \qquad Z = \begin{pmatrix}1& | ||
| + | \qquad | ||
| + | \qquad S = \begin{pmatrix}1& | ||
| + | \qquad T = \begin{pmatrix}1& | ||
| - | In quantum | + | X flips $\lvert 0\rangle \leftrightarrow \lvert 1\rangle$ (the quantum |
| - | When the Hilbert space is chosen, one identifies a Hamiltonian that captures the energies of the system. This is done either by looking (e.g. the spherical symmetry in the Hydrogen atom) or just by constructing one that satisfies being a linear Hermitian operator. The Hamiltonian is then plugged in the Schrodinger equation as solved for state $\lvert\psi\rangle$. | + | ## Qiskit |
| - | ### Hydrogen atom | + | ```python |
| - | Let's take a particle like an electron inside a hydrogen atom. A postulate in quantum mechanics is that an electron should be fully described by its state $\lvert\psi\rangle$. We need a Hilbert space that captures all possible states of an electron. But first, what is an electron state? | + | # Requires: pip install qiskit qiskit-aer |
| + | # Run: python qubit.py | ||
| + | # Prepares |+⟩ and samples 1000 shots; expect roughly equal counts of ' | ||
| + | from qiskit import QuantumCircuit | ||
| + | from qiskit_aer import AerSimulator | ||
| - | An electron is an object in 3D space. Like with qubit, its probability amplitudes are complex numbers. Therefore a state should be something that associates a complex number $\mathbb C$ with every point in space $\mathbb R^3$. So we'll define the electron state as a function $\lvert\psi\rangle: \mathbb R^3\mapsto\mathbb C$. | + | qc = QuantumCircuit(1, 1) |
| + | qc.h(0) # Hadamard: |0⟩ → |+⟩ = equal superposition | ||
| + | qc.measure(0, 0) | ||
| - | We also need the electron to exist *somewhere* in the universe. According to the Born rule, the probability of finding an electron at a point $(x, y, z)$ is proportional to the square magnitude of the complex number associated with that point. Therefore, if we integrate square magnitude of the function across all of 3D space we should get $1$. | + | counts = AerSimulator().run(qc, shots=1000).result().get_counts() |
| + | print(counts) | ||
| + | ``` | ||
| - | So, to capture all possible electron states, we choose the Hilbert space to be a space of all square-integrable functions. This is compactly written as $L^2(\mathbb R^3)$. | ||
| - | |||
| - | $$ \lvert\psi\rangle\in \left\{ f:\mathbb R^3\mapsto\mathbb C \text{ such that } \int_{\mathbb R^3} |f(x)|^2 \mathrm dx = 1\right \} \quad \text{ same as } \quad \lvert\psi\rangle\in L^2(\mathbb R^3)$$ | ||
| - | |||
| - | When it comes to the Hamiltonian, | ||
| - | |||
| - | $$H = -\frac{\hbar^2}{2m}\nabla^2 + V$$ | ||
| - | |||
| - | The Schrodinger equation becomes: | ||
| - | $$-i\hbar\frac{\partial}{\partial t}\lvert\psi\rangle = \left(-\frac{\hbar^2}{2m}\nabla^2 + V\right)\lvert\psi\rangle$$ | ||
| - | |||
| - | If we let the potential $V$ be the Coulomb potential $V = e^2/ | ||
| - | |||
| - | ### Qubit | ||
| - | Let's turn back to the qubit. A postulate in quantum mechanics is that a qubit should be fully described by its state $\lvert\psi\rangle$. We need a Hilbert space that captures all possible states of a qubit. But what is a qubit state? | ||
| - | |||
| - | Unlike the electron, qubit is quite limited in its degrees of freedom: instead of being distributed across all of 3D space, there are only two places the probability amplitudes can go to. We can do something similar to an electron and define a qubit state to be a function $\lvert\psi\rangle: | ||
| - | |||
| - | So, to capture all qubit states, we choose the Hilbert space to be the 2-dimensional complex vector space $\mathbb C^2$. | ||
| - | $$ \lvert \psi\rangle\in \left\{\begin{pmatrix}a \\ b\end{pmatrix}\text{ where } a, b\in \mathbb C \text{ and } |a|^2 + |b|^2 = 1 \right \} \text{ same as } \lvert\psi\rangle\in\mathbb C^2$$ | ||
| - | |||
| - | Now we need a Hamiltonian. The Hamiltonian is a bit odd. It encodes the energy of the system -- but what is the kinetic and potential energy of a qubit? The truth is, qubit doesn' | ||
| - | |||
| - | Mathematically, | ||
| - | |||
| - | $$H = \begin{pmatrix}x & z - iw \\ z + iw & y \end{pmatrix}$$ | ||
| - | |||
| - | When we plug this in the Schrodinger equation we get the following expression:; | ||
| - | |||
| - | $$i\hbar\frac{\partial}{\partial t}\begin{pmatrix}a(t)\\b(t)\end{pmatrix} = \begin{pmatrix}x & z - iw \\ z + iw & y \end{pmatrix}\cdot\begin{pmatrix}a(t)\\b(t)\end{pmatrix}$$ | ||
| - | |||
| - | This is a first order differential equation with respect to time, so when we solve it for the column vector (a, b): | ||
| - | |||
| - | $$\begin{pmatrix}a(t)\\b(t)\end{pmatrix} = e^{iH(t)/ | ||
| - | |||
| - | Notice $H$ is in an exponential function $e^x$, yet $H$ is a 2x2 matrix. How do we define an exponential function of a matrix? We can do it by defining $e^x$ via its Maclaurin series $e^x = 1 + x + x^2 / 2 + \cdots$. | ||
| - | |||
| - | $$e^H = 1 + H + \frac{H^2}{2} + \frac{H^2}{6} + \cdots$$ | ||
| - | |||
| - | ## Visualization | ||
| - | A classical bit only has two states, `0` and `1`. Therefore you can easily picture a classical bit as an on-off switch. | ||
| - | |||
| - | A qubit is a little more complex. However we've seen it consists of two probability amplitudes $\alpha$ and $\beta$, both of which are complex numbers. According to the Schrodinger equation their phases evolve in opposite directions (both at the same angular frequency), but their amplitudes do not change. | ||
| - | |||
| - | Therefore, you can picture a qubit like an analog clock with two hands: One hand spinning clockwise and the other hand spinning counter-clockwise. They' | ||
qubit.1779560219.txt.gz · Last modified: by Ivan Janevski
