After getting the basics of QC down with quantum.country, I find thinking about and surveying quantum programming languages a lot of fun.
Below, I have my textbook implementation of Grover search in Cirq (runnable Colab). Cirq docs have many other textbook algorithm implementations here.
Some raw thoughts:
- One has to think in terms of individual single-qubit and multi-qubit logic gates, which is very error-prone and tedious, especially when uncomputation is needed. This is in contrast with classical programming, where thinking in terms of elementary NAND gates is too low level.
- Depending on your quantum hardware, some circuits might need redesigning,
since they may not be suited to the underlying device’s constraints. Cirq
exposes these via devices. While it is
easy to grab a
NamedQubit
in simulation mode as needed. In real code, compilers will need to help programmers translate higher level ideas to circuits that can actually run on the target machine. - Testing and debugging quantum programs will be interesting. Black-box testing of classical results can probably be done by running tests on simulators. Interactively debugging programs will be challenging as we now have a legitimate case for Heisenbugs! Interesting papers: 1, 2.
- Imagine a computer game that introduces quantum effects. Most of the game will be a classical program, which will call out to a quantum subsystem to efficiently do the quantum stuff. Would a single language for both classical and quantum components make sense? I think at least in the near future, a separate quantum service will be the norm in large part due to quantum hardware being only available with a few providers.
I will next look at a few quantum programming frameworks, e.g.,
- Quipper: An embedded, scalable functional programming language for quantum computing
- Silq: High-level programming language for quantum computing with a strong static type system: This one sounds particularly promising re. points (1) and (2) above.
- Qiskit: IBM Quantum Lab’s framework
- Q#: A high-level programming language from Microsoft.
- …
__END__
Grover search impl 🔗
In the code below, our “solution” is known in advance. To solve a real search problem, we would need additional logic to check whether a quantum state corresponds to the sought-after solution. Since our solution is known at circuit-build time, we just use some controlled-nottery for the solution-checking step.
BTW, cirq comes with a bunch of algorithm implementations, including Grover search
|
|
Now we instantiate the algorithm to find the solution “1001” and simulate:
|
|
Output:
measurements: x1=1 x2=0 x3=0 x4=1
output vector: -0.354|0000001001⟩ + 0.354|0010001001⟩ + 0.354|0100001001⟩ - 0.354|0110001001⟩ + 0.354|1000001001⟩ - 0.354|1010001001⟩ - 0.354|1100001001⟩ + 0.354|1110001001⟩