Getting Started with Qx
I've been building a quantum computing simulator in Elixir for about 18 months. It started as a personal project to force myself to gain a deeper understanding of quantum computing, the kind of understanding that only comes when you have to implement something. The result is Qx, a library that's now at v0.5.1 and available on Hex as qx_sim.
This post is an introduction: what Qx does, why Elixir, and how to get started.
Why Qx, Elixir, and Nx?
Quantum computing simulators exist in Python (Qiskit, Cirq, PennyLane) and that ecosystem has dominated for good reasons. So why Elixir?
I wanted to learn two things at once. When you build a simulator, you're forced to confront the linear algebra, the gate matrices, the state vector representation and I wanted to do that in Elixir to gain a greater understanding of a language I enjoy. By accident, Elixir turned out to be a surprisingly good fit. The Nx numerical computing library gives you tensor operations and optional GPU acceleration (via EXLA or Apple Silicon's EMLX). The pipe operator maps naturally onto quantum circuits so that a sequence of gate applications reads like prose. And LiveBook, Elixir's notebook environment, makes interactive exploration of quantum states easy, visual and fun.
By leveraging Elixir alongside Nx (Numerical Elixir) for blazing-fast matrix multi-dimensional math on CPUs and GPUs, Qx allows developers to build and scale complex quantum simulations elegantly.
When using Qx, you will encounter two primary operating paradigms:
1. Calculation Mode: Operates directly on raw tensors and matrices. It is optimized for building gates mathematically and evaluating theoretical linear algebraic states.
2. Circuit Mode: A higher-level abstraction where you assemble logical quantum circuits. You queue up Hadamard, Pauli, and CNOT gates on specific qubit wires, and then dispatch the entire circuit to be evaluated.
Installing Elixir
Before you can simulate a quantum circuit, you need to install Elixir. The most robust way to manage Elixir and its underlying Erlang VM on any operating system is via a package manager.
- macOS: For getting started, we strongly recommend using Homebrew. Simply run
brew install elixiror look atasdffor more advanced users. - Linux: Standard package managers are great. On Ubuntu/Debian,
sudo apt-get install elixir. Alternatively, theasdfversion manager is highly recommended for managing multiple versions cleanly. - Windows: The easiest path is using Chocolatey (
choco install elixir) or downloading the official installer from the Elixir site.
If you get stuck, the official Elixir Installation Guide has exhaustive instructions for every platform.
Setting Up Livebook
The quintessential tool for exploring data science and numerical workloads in Elixir is Livebook. Think of it like Jupyter Notebooks, but for Elixir. Qx makes heavy use of Livebook to provide interactive, visual, and reproducible quantum tutorials.
To get Livebook installed, check out the our guides section on Qx Quantum:
👉 Install Livebook via QxQuantum Guides
Your First Quantum Tutorial
Once you have Elixir and Livebook installed you are ready to start learning quntum computing in Elixir.
Navigate back to the Qx Guides and download the tutorial file for "Quantum State and The Qubit".
- Launch Livebook on your local machine.
- Click Open and select the
.livemdfile you just downloaded. - Once the environment boots, hit the execute button on the first code block to let Livebook instantly fetch the
qx_simdependencies. - Follow along through the textbook! You will mathematically initialize your very first $|0\rangle$ qubit state and apply matrices to put it into a superposition.
You are officially on your way to mastering quantum computing in Elixir!