OpenAI Codex “Speaks” Qiskit

Iskandar Sitdikov
Qiskit
Published in
3 min readSep 7, 2021

Research company OpenAI recently released Codex, a neural network that translates natural language into programming code. For input parameters, the system takes in a request expressed in natural language (specifically English), and the response is a piece of generated code. Codex itself is a descendant of Open AI’s GPT-3 language model, and it also happens to be backbone of GitHub Copilot.

Codex is trained on open data and public GitHub repositories. So, keeping this in mind, I decided to give it a shot on quantum computing using Qiskit.

The interface for the Codex playground is very simple: you have text area where you have to specify is a string which explains whatever you want to be implemented, and where Codex responds with the code. On the right side there are bunch of network parameters with explanations of what they are doing. That’s pretty much it!

OpenAI Codex Playground UI

I started with something simple, creating a quantum circuit.

2 qubit circuit

Okay, it worked! :) I then asked it to create Bell state, a simple entangled quantum state:

Bell state

The Bell state is already a much more complex concept that just creating an object of a specific class. Once again, it worked! The stakes were higher now, so I asked Codex to implement an entire algorithm:

Deutsch-Jozsa algorithm

What about quantum teleportation?

Quantum teleportation

Codex even wrote a code to execute teleportation circuit and printed out measurements!

I also checked what other Qiskit specific functions Codex could help us execute. Did Codex knows about OpenQASM?

Conver to OpenQASM

Should I go completely crazy and work with low level pulses?

Parametric Pulse schedule

o_O even the parametric pulse schedule worked!

Did you notice that we never told Codex to use Qiskit specifically, but it still knew it was supposed to write Qiskit code? This was unexpected for me at first, but actually made total sense. Qiskit is Codex’s quanutm framework of choice because we produce a lot of open-source Qiskit content, tutorials, and examples of how to implement different quantum algorithms and procedures.

Overall Codex is more than impressive when it comes to programming quantum computers. Of course, you have to play around with parameters and formulation of docstrings to make most out of the system. And, as it’s still in beta, the output programs are not always correct. But the target usecase for Codex and Copilot is to act as an assistant for developers to writing code. This demonstration shows that Codex can already serve as an assistant to quantum programmers using Qiskit.

This blog post came from just my first hour of playing around with Codex for quantum computing. I think there’s a lot more to explore, and encourage you to play around with it, too.

Want to read more stories like this? Then subscribe to the Qiskit Medium!

--

--