New Quantum Programming Language named Twist and How it differs from Qiskit/OpenQASM Phase Disks

New Quantum Programming Language Named Twist And How It Differs From Qiskit/Openqasm Phase Disks

You may have seen recent announcements of a new quantum computing language called Twist. Upon closer inspection, however, Twist is not the full language you might be thinking of when you read the term “language.” For example, you’re not going to use it to run quantum circuits. You’re not even going to use it to fully simulate quantum circuits. What, then, does this new language do?

What is Twist?

Twist: sound reasoning for purity and entanglement in Quantum programs,” by Yuan, McNally, and Carbin, introduces Twist as a language that is really a utility for doing one specific thing: identifying quantum entanglement and its absence.  Supplemental material is available.  This is important, of course, because unwanted entanglement causes undesirable results.

One peculiarity of the paper is the proposed role of Twist in uncomputation, which, to avoid confusion, ought to be called disentanglement. We entangle qubits to perform some multi-qubit operation, and then we want to keep the result while discarding what got us there. The process to do so, is simply repeating all those building operations in reverse order. That’s it. If you build a custom multi-qubit gate, you know that’s what you’re doing, and you know you need to uncompute/disentangle. If you’re building custom multi-qubit gates, you shouldn’t need Twist or any other utility to tell you this.

What are phase disks?

If you use IBM Quantum, not via external Jupyter notebooks but actually logged into the portal, you ought to be familiar with phase disks. These two-dimensional objects convey information about probabilities, phases, and purity. That last one, purity, indicates the presence or absence of entanglement. And, it’s not all-or-nothing, by the way. The phase disks indicate no, partial, or full entanglement.

In other words, phase disks seem to do everything Twist does, with the added bonus of conveying information about probabilities and phases. If you see a qubit that is partially or maximally entangled and you’re somehow not sure with which other qubit, simply do something to it. Apply a single-qubit operation, Hadamards usually work well for this, and observe which other qubit’s phase disk changes.  

How does Twist compare to phase disks?

Using Twist is noticeably more time consuming than using phase disks. Since it’s not a full language, you have to build your circuit with Twist, do all the appropriate analyses, and then build your circuit in another language in order to actually simulate it and/or run it. In other words, you have to build your circuit twice. While that’s a little extra work for small circuits, imagine coding larger circuits twice. Also, compared to OpenQASM, Twist code is noticeably lengthier. And, compared to using Python, Twist does not have loops or any shortcuts for building larger circuits.

Using phase disks, on the other hand, requires no additional effort at all. You can use OpenQASM or Qiskit within IBM Quantum to build your circuits, and the phase disks are right there. As you build your circuits, with no additional effort on your part, the phase disks continuously update about a second or so after you update your code.

One positive note about Twist, however, is that all programs start with “fun.” No kidding. Whereas a C program starts with “main” and other languages have their own starting commands, Twist programs literally start with “fun.” I can appreciate that; quantum computing is most definitely fun.

New Quantum Programming Language Named Twist And How It Differs From Qiskit/Openqasm Phase Disks
a sample teleportation algorithm in Twist, from the paper

A Specific Example

The paper linked to early in this article includes a variation of the textbook teleportation algorithm. An explanation of the algorithm is beyond the scope of this article. But, to prove a point, I recreated the circuit above using IBM Quantum’s OpenQASM editor.

New Quantum Programming Language Named Twist And How It Differs From Qiskit/Openqasm Phase Disks
the same algorithm in the IBM Quantum portal, with phase disks indicating entanglement

If you’re unfamiliar with OpenQASM, the code on the right side of the screen, you can think of the first four lines as overhead. They’re generally always there. There’s one exception that’s beyond the scope of this article.

Lines 6-12 recreate the circuit in the paper. As you can see, the lines of OpenQASM code are noticeably shorter than the associated lines of Twist code. In fact, you should be able to see something resembling the OpenQASM code within the Twist code. This basically means that OpenQASM is faster and easier to work with; all of that extra Twist-specific  code is unnecessary.

Most importantly, look at what happens with lines 11 and 12 commented out. The phase disks to the left of the code and to the right of the circuit, via the inside circles, show that qubits q1 and q2 are maximally entangled.

New Quantum Programming Language Named Twist And How It Differs From Qiskit/Openqasm Phase Disks
after measurements, the phase disks still show correlation

Now look what happens when we uncomment lines 11 and 12. The phase disks don’t show entanglement anymore because measurements have taken place. But, we can still see that qubit q2, if measured, would measure the same as qubit q1, with which it was just recently entangled.

New Quantum Programming Language Named Twist And How It Differs From Qiskit/Openqasm Phase Disks
simulation shows correlation

And, in case you don’t believe me, we can add a measurement to qubit q2. If we look at the simulated results on the left, we see four three-digit bitstrings. For each bitstring, the digit on the right is the measurement from qubit q0, the digit in the middle is the measurement from qubit q1, and the digit on the left is the measurement from qubit q2. The middle and left digits, again from qubits q1 and q2, are perfectly correlated through 20,000 shots on the simulator.

New Quantum Programming Language Named Twist And How It Differs From Qiskit/Openqasm Phase Disks
despite noise, ibmq_belem shows correlation

And, to really drive the point home, we can run this circuit on a real quantum processor, in this case ibmq_belem. Even with noise, we see this correlation between qubit q1 and qubit q2 hold up.


This article was originally going to be a review of Twist and everything it could do. As far as I can tell, the language has one-third the utility of phase disks while requiring more effort to use. For the record, I inquired in several places as to whether I might be missing something. I don’t think I am, and no one replied that I am. Therefore, I recommend watching Twist and observing how it may evolve over time, but, in the meantime, I recommend using IBM Quantum and letting the portal do the work for you.

If you don’t use IBM Quantum, however, everything I just wrote changes. If phase disks are not available through your platform or framework of choice, perhaps Twist can provide some value. Even then, you can detect entanglement visually by building your circuit in Quirk. Quirk has the added advantage of being importable into Cirq, eliminating the duplicate efforts I mentioned earlier. But, if you don’t use Qiskit or Cirq, then perhaps Twist can provide some value.