# Quantum State and The Qubit ```elixir Mix.install([ {:qx, path: "/Users/richarc/Development/qx"}, {:kino, "~> 0.12"}, {:vega_lite, "~> 0.1.11"}, {:kino_vega_lite, "~> 0.1.11"} ]) ``` ## Introduction The fundamental unit of information in this domain is the qubit, or quantum bit. A qubit functions as the quantum mechanical generalization of the classical bit. While currently available quantum computers typically have a limited number of qubits, the hardware is widely expected to improve in terms of qubit count, quality, and connectivity. A qubit is fundamentally a two-dimensional quantum system. ## State Vectors The state of any quantum system is always represented by a vector in a complex vector space known as a Hilbert space. The complete description of an isolated quantum system is given by its state vector, which is a unit vector in the system’s state space. For a single qubit, this state vector is represented mathematically using the Dirac or "ket" notation. $\ket{\psi} = \alpha\ket{0} + \beta\ket{1}$ The scalar values $\alpha$ and $\beta$ are complex amplitudes. This representation extends the geometrical notion of a quantum state being described by a point on a unit sphere (the Bloch sphere). We also write $\ket{\psi}$ as the vector form of $\ket{\psi} = \begin{pmatrix} \alpha \\ \beta \end{pmatrix}$ being the state vector for this qubit. In this vector form, $\alpha$ represents the aplitude (amount) that $\ket{\psi}$ is in the $\ket{0}$ state and $\beta$ represents the amplitude (amount) that $\ket{\psi}$ is in the $\ket{1}$ state. ## Superposition Unlike a classical bit that must be in the definite state of 0 or 1, a qubit can exist in a state that is a linear combination of its basis states, a phenomenon known as superposition. Mathematically, this linear combination is expressed as $\ket{\psi} = \alpha\ket{0} + \beta\ket{1}$, where $\alpha$ and $\beta$ are complex numbers. Any linear combination of two quantum states, once normalized, is also a valid quantum state. This inherent property allows a quantum register of $n$ qubits to exist simultaneously in up to $2^n$ computational basis configurations. ## Basis States Because a qubit is a two-dimensional system, it possesses two possible, perfectly distinguishable configurations, known as the computational basis states. These states are universally denoted $\ket{0}$ and $\ket{1}$, corresponding to the classical values 0 and 1, respectively. The computational basis states form an orthonormal basis for the qubit's state space. In a standard matrix representation, $\ket{0}$ written as the column vector $\begin{pmatrix} 1 \\ 0 \end{pmatrix}$ and $\ket{1}$ as $\begin{pmatrix} 0 \\ 1 \end{pmatrix}$. Our state $\ket{\psi}$ can also be written as: $\ket{\psi} = \alpha\ket{0} + \beta\ket{1} = \alpha \begin{pmatrix} 1 \\ 0 \end{pmatrix} + \beta \begin{pmatrix} 0 \\ 1 \end{pmatrix} = \begin{pmatrix} \alpha \\ \beta \end{pmatrix}$ ## Normalisation The state vector $\ket{\psi}$ must adhere to the normalization condition, meaning it must be a unit vector. This condition requires that the sum of the squares of the absolute magnitudes of the amplitudes equals one $|\alpha|^2 + |\beta|^2 = 1$. This constraint is essential because it ensures that the total probability of all measurement outcomes sums to unity. When a measurement is performed on the qubit state, the probability of observing outcome 0 is $|\alpha|^2$ and the probability of observing outcome 1 is $|\beta|^2$. ## Working with Qx qubits That's enough of the basics to start playing with simulated qubits in Qx and exploring some of the concepts just discussed. ```elixir # let's create a qubit and look at the state vector q1 = Qx.Qubit.new() Qx.Qubit.show_state(q1) ``` The default state for our 'new' qubits is the $\ket{0}$ state. As you can see above the 'show_state' function gives you the key infomation about our new qubit. Note that the probability of our state being in the $\ket{0}$ state is 1 and in the $\ket{1}$ state is 0 as we expect, as $\ket{0}$ is a basis state and hence a perfectly distinguishable state. ```elixir # let's create another qubit in the |1> state # we will use the more Elixir idomatic pipe operator from now onwards q2 = Qx.Qubit.one() |> Qx.Qubit.show_state() ``` As before, $\ket{1}$ is a basis state and perfectly distinguisable so the probabality of us measuring and finding it in the state $\ket{1}$ is 100% or 1 (1 representing a probabaility of 100%). ```elixir #let's look at a state that has a more interesting probabaility q3 = Qx.Qubit.new() |> Qx.Qubit.h() |> Qx.Qubit.show_state() ``` What we have above is a $\ket{0}$ state which has had an Hadamard gate applied which results in the following state $\ket{\psi} = \frac{1}{\sqrt{2}}(\ket{0} + \ket{1})$. You will see this a lot and we will explain it in detail later. As you can from the 'show_state' function that the amplitudes reflect the the value of $\frac{1}{\sqrt{2}}$ which is equel to 0.707106... You can also see the 'probabilities:' reflect the nomalisation constraint $|\alpha|^2 + |\beta|^2 = 1$. That is, $|\frac{1}{\sqrt{2}}|^2 + |\frac{1}{\sqrt{2}}|^2 = \frac{1}{2} + \frac{1}{2} = 1$. The probabilities are 0.49999.. which is due to the imperfect representation of real numbers in computer systems. We take this into consideration when comparing probabilities in Qx. ```elixir EXLA.Client.get_supported_platforms() ```