Qubits, Superposition, and Twist
For this week, we take a closer look at Twist, the first entanglement-aware quantum programming language. Before getting ahead of ourselves, we’ll set the anchor a bit in superposition to better frame the ramifications of what Twist offers. For quantum computing, the combination of superposition, entanglement, and interference, make for radically different paradigms than are possible with classical computing. Today’s newsletter goes more deeply into things than usual, including some programming analogies to help lock in some of the concepts. This is a deviation from our typical newsletter format, so please let us know what you think.
Qubits in Superposition
One of the most immediately striking things people latch onto about quantum science and technology surrounds the qubit, aka the quantum bit. To call it a quantum version of the classical bit is would be getting it backward since the classical bit is a low-fi abstraction of the qubit. One of the qubit’s most popular party tricks is known as superposition. This is often described as the qubit having multiple values at the same time, vastly expanding its effective storage capacity. The wave/particle duality encourages this, since the qubit being in two places at once when behaving as a wave is a direct consequence, and much larger bodies have been confirmed to achieve superposition. Regardless, thinking of the superposition principle, we should be comfortable thinking of a qubit’s state in non-scalar terms as a wave function—a probability distribution.
In Constructor Theory, beautifully articulated in Chiara Marletto’s The Science of Can and Can’t: A Physicist’s Journey through the Land of Counterfactuals, one is encouraged to frame things in terms of what is possible, in terms of what the universe allows. It’s helpful to think of that when considering a qubit’s wave function, its state space. Instead of waiting to figure out which possible value a qubit will assume, we can treat its current value as the wave function itself. For example, if chances are even a qubit is a 0 or a 1, it can be seen as the probability itself.
As the probability distribution is expressed in terms of wave functions, probability amplitudes are used to express each case, such as 1/squareRoot(2) instead of a direct probability, like the corresponding 50%. This makes sense because 1/squareRoot(2) is 1/2, and the probabilities need to add up to 1.
In programming terms, what we are doing is not bothering to reduce a variable from its expression. This laziness is beneficial if it turns out that we never need the value. In programming languages with lazy evaluation, this tends to be an optimization for cases where we don’t need to use the variable. The other case where we don’t need a term comes from maths, when we can cancel out negating terms. If two expressions are equivalent and they cancel out, there’s no need to do the work of evaluating the expression. This is commonplace in quantum computing owing to quantum interference.
If we take superposition itself as a proper value, we can consider larger superpositions made up of other superpositions. Think of lazy variables whose valuations will depend on other lazy variables once a special function called measure() is invoked. Then, with the help of purposeful quantum interference, we can arrange to have unwanted qubit states cancel out automatically when performing basic operations via quantum circuits. For complex problems loaded with permutations, this technique can tame intractable problems.
Purity as Entanglement Abstinence
As hinted at, programmers can think of superposition being a sort of lazily evaluated expression, while non-programmers can forget they heard this. In any case, it should be known that superposition often leads to something called entanglement, where a qubit can become linked to another qubit. Such a link persists across vast distances, such that the values of these entangled qubits are correlated. Furthermore, interacting with one entangled qubit has the effect of interacting with its paired qubit, again, even across vast distances. Spooky, eh?
Developed within MIT’s Computer Science & Artificial Intelligence Laboratory (CSAIL), Twist is the first entanglement-aware quantum programming language. Its central notion is the concept of purity, which it defines as the absence of entanglement. This readily suggests other concepts of purity—Rust and its borrow-checker, as well as pure functional programming (FP) languages like Haskell and Clean. Whether it is purity from memory reference, as with Rust and its notion of ownership; or purity of functions in FP languages, ensuring referential transparency and the absence of side effects; or now, for Quantum Programming, pure qubits, free of entanglements with every other qubit, we have a common level of abstraction, the shared concept of isolation and independence of programmatic entities.
As with Rust, Twist incorporates static type-checking to evaluate purity, but unlike Rust, it also utilizes runtime analysis, as detecting and tracking entangled states can be an involved process. It helps to discuss how entangled states arise—rather than birds and bees, we’ve got Hadamard gates and Controlled Not gates. By gates, we are speaking on a logical level of transforms. Hadamard gates represent one way to achieve superposition in a qubit, while Controlled Not gates represent one way to achieve entanglement between qubits. After a qubit passes through a Hadamard gate, it has an equal likelihood of being a 1 or a 0. In the case of the Controlled Not gate, it accepts two qubits, where one of the qubits serves as the control qubit and performs a Not operation on the non-control qubit whenever the control qubit is set to 1. For the record, other entangling gates can produce unequal amplitudes.
As previously mentioned, detecting and tracking entangled states can be an involved process. For example, in various cases, when two qubits each in superposition pass through an entangling gate, it may be that they do not become entangled, just like one might not get COVID from a super spreader.
The thing about programming with qubits is that not knowing which qubits are potentially entangled can lead to unpredictable, malfunctioning programs. Twist provides a construct that designates whether or not a qubit is expected to be pure, and thus, free of entanglements. When programming at the gate level, which is at a lower level, it is quite easy to perform operations on entangled qubits that affect their entangled partners unintentionally. Twist provides mechanisms to avoid unintended side effects that sabotage the intended program functionality, bringing the promise of easier paths to program correctness with less risk of inadvertent entanglement errors. Additionally, the programming language suggests some directions in which quantum-specific higher-level programming languages may involve.
MIT Computer Science & Artificial Intelligence Laboratory
MIT Introduces Twist – A New Quantum Programming Language to Help Curb Errors
New Quantum Programming Language named Twist and How it differs from Qiskit/OpenQASM Phase Disks