We keep trying to learn more about quantum computers. But the truth is, the way we program quantum computers — or their simulators — today will probably not have much in common with how we program them in the future. Think about it. Programming your PC is nothing like programming the ENIAC. So we expect we’ll see more and more abstractions over the “bare metal” quantum computer. The latest of these is Twist, from MIT.
According to the paper (and the video, below), Twist expresses entangled data and processes in a way that traditional programmers can understand. The key concept is known as “purity” of expressions which helps the compiler determine if data is actually entangled with another piece of data or if any potential entanglement is extraneous. A pure expression only depends on qubits it owns, while a mixed expression may use qubits owned by other expressions.
Here’s an example of a teleportation program in Twist:
This may seem strange, but discarding a qubit has the same effect as measuring it, so discarding an intermediate result can affect an entangled result that doesn’t immediately seem related. This is similar to how, in conventional programming, you might free memory used by two different pointers. Discarding memory containing, say, an employee record while holding another pointer to the same record will cause problems if you reuse that memory later. However, with Twist, you can promise the compiler that there are no entanglements between pure expressions.