Site Tools


qubit

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
qubit [May 23, 2026 at 18:16] Ivan Janevskiqubit [June 13, 2026 at 03:46] (current) Ivan Janevski
Line 1: Line 1:
 # Qubit # Qubit
-**Qubit** is the quantum computing equivalent of a bit.+**Qubit** (or **quantum bit**) is the basic unit of quantum information. The Hilbert space of a single qubit is $\mathbb{C}^2$, meaning two complex amplitudes to describe it, not one.
  
-A classical bit can be `0or `1`There are no probabilities involved at all, but we can assign them anyway. If bit is `1`, then it's `1` with 100% probability and `0` with 0% probability. Conversely, if bit is `0`, then it's `1` with 0% probability and `0` with 100% probability.+A classical bit can only be 0 or 1. A qubit can be in **superposition**: a combination of $\lvert 0\rangle$ and $\lvert 1\rangle$ with complex coefficients called [[probability-amplitude|probability amplitudes]]The state evolves according to the [[schrodinger-equation|Schrödinger equation]] and collapses to definite or only when measured.
  
-A qubit works in similar way. It also has two states: $\lvert 0\rangle$ and $\lvert 1\rangle$except the total probability is distributed between those two. A qubit is often in both states at the same time: a small amount in state $\lvert 0\rangle$ and a small amount in state $\lvert 1\rangle$. A qubit  $\lvert\psi\rangle$ is written in the following form, using what is known as [[dirac-notation|Dirac notation]]:+general qubit state is superposition over the two computational basis states, with the normalization condition saying the total probability must be 1:
  
-$$\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 "probability amplitudes". For example, a qubit might be in a state $\lvert 0\rangle$ with probability amplitude $a = \frac{\sqrt 2}{2} + i\frac{\sqrt 2}{2}$, and in state $\lvert 1\rangle$ with probability amplitude $b = \frac{\sqrt 2}{2} - i\frac{\sqrt 2}{2}$, all at the same time. The probability amplitudes evolve over time according to the Schrodinger equation. For eample, $a$ and $b$ can rotate or exchange magnitudes over time.+## Basis states
  
-qubit state continues to evolve as this weird object of two complex probabilities amplitudes -- until it is measuredWhen a qubit is measured, it collapses to either $\lvert 0\rangle$ or $\lvert 1\rangle$ with 100% probability. At that point, there are no longer any probabilities or complex numbers inolved. The qubit behaves exactly like a classical bit and we might as well refer to $\lvert 0\rangle$ as `0`, and $\lvert 1\rangle$ as `1`.+There are infinitely many single-qubit states but three orthonormal bases are standard, corresponding to the three axes of the [[bloch-sphere|Bloch sphere]]In each basis the two states are perfectly sharp for that observable and spread out for the others.
  
-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? The answer is given by the [Born rule](https://en.wikipedia.org/wiki/Born_rule). The Born rule states that the real probability of measurement yielding a certain result is proportional to the square of the probability amplitude associated with that result.+### Z-basis (Computational basis)
  
-$$P_0 = |a|^2 \qquad P_1 = |b|^2$$+The Z-basis states $\lvert 0\rangleand $\lvert 1\rangle$ are the eigenstates of the Pauli Z gate. They behave exactly like a classical bit: each has a definite value with no superposition. Every qubit state can be written as a linear combination of them.
  
-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 "spread out" in the computational basis, because each is an equal superposition of $\lvert 0\rangle$ and $\lvert 1\rangle$. In the X basis they are perfectly sharp. You get from the computational basis to the X basis by applying a Hadamard.
  
-### 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 statesand a pure state is when a qubit is in one of the two basis statesthere are also only two pure states:+The Y-basis states $\lvert +i\rangle$ and $\lvert -i\rangle$ are the eigenstates of the Pauli Y gate. Their coefficients are complexso they are the first states on this page with imaginary entries. You get from the computational basis to the Y basis by applying $SH$ ($H$ first, then $S$).
  
-$$ \lvert\psi\rangle = \underbrace{\left(+ i0\right)}_{a}\cdot \lvert 0\rangle \underbrace{\left(0 + i0\right)}_{b}\cdot\lvert 1\rangle$$+$$\lvert +i\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\i\end{pmatrix} \qquad \lvert -i\rangle \frac{1}{\sqrt{2}}\begin{pmatrix}1\\{-i}\end{pmatrix}$$
  
-$$ \lvert\psi\rangle \underbrace{\left(0 + i0\right)}_{a}\cdot\lvert 0\rangle + \underbrace{\left(+ i0\right)}_{b}\cdot\lvert 1\rangle$$+^ State ^ Expansion in computational basis ^ Description ^ 
 +| [[ket-plus-i|$\lvert +i\rangle$]] | $\tfrac{1}{\sqrt{2}}(\lvert 0\rangle + i\lvert 1\rangle)$ | Eigenstate of Y with eigenvalue $+1$. | 
 +| [[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 \lvert 0\rangle + \underbrace{\left(\frac{1}{2} + i0\right)}_{b}\cdot \lvert 1\rangle$$+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 \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 the state collapses to a pure stateIn both of these examples, the probabilities are equally distributed. Measuring these qubits will yield either state with 50% probability.+Result 0 collapses the state to $\lvert 0\rangle$; result 1 collapses it to $\lvert 1\rangle$The probability amplitudes are destroyed by measurement and cannot be recovered. Measuring in the X or Y basis works the same way with different outcome states: to measure in the X basis, apply $H$ before measuring in Z; to measure in the Y basis, apply $S^\dagger H$ before measuring in Z.
  
-### 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 qubit that'in both states with 100% probability, like $\lvert\psi\rangle = \lvert 0\rangle + \lvert 1 \rangle$. Expanding the notation to see the structure more clearly: +Every pure qubit state corresponds to unique point on the surface of the [[bloch-sphere|Bloch sphere]], a unit sphere in $\mathbb{R}^3$. The parametrisation uses two angles $\theta \in [0\pi]and $\phi \in [0, 2\pi)$:
-$$ \lvert\psi\rangle = \left(1 + 0i\right)\lvert 0\rangle + \left(1 + 0i\right)\lvert 1\rangle$$+
  
-When we sum the square magnitudes we get the result $2$ +$$\lvert\psi\rangle = \cos\tfrac{\theta}{2}\lvert 0\rangle e^{i\phi}\sin\tfrac{\theta}{2}\lvert 1\rangle$$
-$$ |1 + 0i|^2 + |1 + 0i|^2 1^2 + 1^2 = 2$$+
  
-The interpretation of this result is that the qubit exists with a total probability of 200%, which doesn't make sense. The total probability distribution among all states must always add up to 100%.+The north pole ($\theta = 0$) is $\lvert 0\rangle$; the south pole ($\theta = \pi$) is $\lvert 1\rangle$. The equator ($\theta = \pi/2$) holds all equal-amplitude superpositions: $\lvert +\rangle$ at $\phi = 0$, $\lvert -\rangle$ at $\phi = \pi$, $\lvert +i\rangle$ at $\phi = \pi/2$, $\lvert -i\rangle$ at $\phi = 3\pi/2$. Single-qubit gates act as rotations of the Bloch sphere.
  
-## 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, it's a vector in a Hilbert space. The operator $H$ is called a Hamiltonian. Mathematically, it's a linear Hermitian opeartor acting on vectors in that space. The Hamiltonian represents the total energy of the system (kinetic energy + potential energy).+$$X = \begin{pmatrix}0&1\\1&0\end{pmatrix} 
 +\qquad Y = \begin{pmatrix}0&{-i}\\i&0\end{pmatrix} 
 +\qquad Z = \begin{pmatrix}1&0\\0&{-1}\end{pmatrix} 
 +\qquad = \frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&{-1}\end{pmatrix} 
 +\qquad S = \begin{pmatrix}1&0\\0&i\end{pmatrix} 
 +\qquad T = \begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix}$$
  
-In quantum mechanics, there is postulate that the system should be fully described its state $\lvert\psi\rangle$. This is not a law of nature. Rather it's our responsibility to make that so, by choosing a Hilbert space that appropriately captures all possible statesOften it's possible to combine Hilbert spaces with a tensor product to make more general Hilbert space that fits our needs.+X flips $\lvert 0\rangle \leftrightarrow \lvert 1\rangle$ (the quantum NOT gate). Z applies $-1$ phase to $\lvert 1\rangle$ and leaves $\lvert 0\rangle$ unchangedis equivalent to $iXZ$H maps $\lvert 0\rangle \to \lvert +\rangle$ and $\lvert 1\rangle \to \lvert -\rangle$, converting between the Z and X bases. S is the square root of Z ($S^2 = Z$); T is the square root of S ($T^2 = S$). For full list see [[single-qubit-gates]].
  
-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 atomA 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 '0' and '1'. 
 +from qiskit import QuantumCircuit 
 +from qiskit_aer import AerSimulator
  
-An electron is an object in 3D space. Like with qubitits probability amplitudes are complex numbersTherefore 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(11) 
 +qc.h(0)        # Hadamard|0⟩ → |+⟩ = equal superposition 
 +qc.measure(0, 0)
  
-We also need the electron to exist *somewhere* in the universeAccording to the Born rule, the probability of finding an electron at a point $(xy, z)$ is proportional to the square magnitude of the complex number associated with that pointThereforeif we integrate square magnitude of the function across all of 3D space we should get $1$.+counts = AerSimulator().run(qcshots=1000).result().get_counts() 
 +print(counts)  # {'0': ~500'1': ~500} 
 +```
  
-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, we need a Hermitian linear operator acting on vectors in our Hilbert space. It's out of the scope of this section, but it can be proven that if we take the classical equation for energy $E = \frac{p^2}{2m} + V$, and promote $p\mapsto -i\hbar\nabla^2$ and $V\mapsto V$ to operators in Hilbert space we get: 
- 
-$$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/4\pi\varepsilon_0r$ created by the presence of a proton, solving the Schrodinger equation yields the equation for electron orbitals in 3D space. 
- 
-### 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: \{0, 1\}\mapsto\mathbb C$. But this is isomorphic to the column vector $\mathbb C^2$. So rather, it's better if we define the state to be a column vector $\lvert\psi\rangle\in\mathbb C^2$. This lets us take advantage of linear algebra. 
- 
-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't have those. Kinetic and potential energies arise when a system has spatial degrees of freedom. A qubit has two internal degrees of freedom instead. A Hamiltonian can still be defined, just not in terms of kinetic and potential energies. 
- 
-Mathematically, Hamiltonian is a linear hermitian operator over Hilbert space. Our Hilbert space is $\mathbb C^2$ so linear operators are complex 2x2 matrices. To satisfy being a Hamiltonian, we just need our 2x2 matrix to be Hermitian. A Hermitian matrix is one where if you do a transpose and apply complex conjugation to all its elements it stays the same. A general 2x2 hermitian matrix for some real numbers $x,y,z,w\in\mathbb R$ is: 
- 
-$$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)/\hbar}\cdot\begin{pmatrix}a(0)\\b(0)\end{pmatrix}$$ 
- 
-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're both spinning at the same speed, just in the opposite direction. One is shorter and the other one is longer. The area of the circle they sweep represents the probability. Area of a circle is proportional to the radius squared $\pi r^2$. This matches the Born rule that that the probability of collapsing a qubit in a given state is given by magnitude squared $P(0) = |\alpha|^2$ and $P(1) = |\beta|^2$.  
qubit.1779560219.txt.gz · Last modified: by Ivan Janevski