Learn Quantum Computing with the Quantum Katas
I started to learn quantum computing when I joined Microsoft Quantum team less then two years ago. Before that the most exposure I had to the topic was a course on quantum mechanics back in the university, which was long enough ago to not count. Upon joining I was immediately presented with a brand-new copy of “Quantum Computation and Quantum Information” by Nielsen and Chuang. I spent probably a month trying to read it, but inevitably got stuck somewhere around chapter 4 feeling that I hadn’t made much progress.
There were several problems with the book – or, more likely, with this style of learning. First, the exercises in the book didn’t have answers, or any hints for that matter. Once I solved a problem, I had no idea whether my approach was correct, and if I was stuck, I was on my own. I was lucky to have access to a whole team of quantum computing experts, whom I could pester with my questions; most people who want to learn quantum computing on their own don’t have this luxury. Second, the book approaches a lot of things from a theoretical point of view, and I don’t believe you can truly master an algorithm – quantum or classical – until you’ve actually implemented it. There is a world of difference between reading explanations and formulas or even following the calculations with pen and paper and writing the code, making mistakes and finding them, seeing how it behaves on different inputs and so on.
Of course, one can (and should) turn to other sources for the exercises. I’ve greatly enjoyed the Quantum Information Science courses by MIT on EdX, since they had interesting problem sets with solution verification. But still I felt that there should be more to teaching quantum computing than that…
Last winter, after we released the Quantum Development Kit 0.1, I started to think about how to help people learn Q# – and for that they would need to learn quantum computing. Examples and library code showing algorithms’ implementations or step-by-step follow-along tutorials like Writing a quantum program were clearly not sufficient, since they lacked the learn-by-doing aspect, giving the learner neither motivation nor framework to experiment on their own.
And then I recalled FSharpKoans through which I went the previous year when learning F#. Those were really good – fun and engaging (who doesn’t love fixing things?) while useful for learning the syntax and concepts of the language. Could we do something like that for Q#?
Fast forward several months: we proudly presented the Quantum Katas – an open-source project aimed at teaching quantum computing and Q# programming.
Working with the Quantum Katas in Visual Studio The Quantum Katas follow several key principles.
Learning by doing
Each kata offers you programming exercises on one topic or a set of closely related topics. They don’t offer you the theory on these topics – for that they send you to external sources like lecture notes or Wikipedia (you’re also most welcome to find your own favorite resource). Once you’ve gone through the theory, you dive into the exercises to internalize your newly gained knowledge. Each task requires you to write a fragment of code to implement something you’ve learned.
Each kata includes a testing framework which validates your solutions to the tasks as soon as you write them. The level of detail provided varies from topic to topic: if the problem asks you to create a certain superposition state, you’ll know only whether the state you created was correct or not (and if it was not, you can use debugging tools like DumpMachine to see what state you created); if the problem asks you to perform quantum state discrimination, you’ll know what percentage of the given states you’ve misclassified, and so on.
Increasing task complexity
The tasks in each kata start simple and gradually increase in complexity, building up on the previous ones. The Superposition kata, for example, starts with really simple tasks – create a |+⟩ or a |-⟩ state – and builds up to creating a W state, which requires using recursion and some clever rotations or even more clever post-selection tricks.
End-to-end algorithm implementation
If you want to master a classical algorithm, you don’t implement the algorithm alone – you also write some unit tests to run it and verify that your implementation works (at least you should). The same goes for quantum algorithms: if a kata covers an oracle algorithm like Grover’s search or a protocol like teleportation, it will take you through all the steps:
- writing an oracle in the right format for the algorithm or preparing the shared resources for the protocol,
- implementing the algorithm itself,
- putting all the pieces together to run the algorithm or the protocol and to check that you get the expected result.
The Quantum Katas project is still in its early stages – there are only 10 katas, covering the introductory topics – but it has already proven itself quite useful. We’ve used the katas in several guided workshops, where the hands-on work with them was preceded by a lecture on the necessary quantum computing concepts, with great success. And personally I felt that I really understood the Grover’s algorithm only after I test-solved the respective kata contributed in October 🙂
Speaking of contributions… If you have an idea for a nice new task or even a whole new kata, let us know and we’ll be happy to help you implement it!
|Mariia Mykhailova, Senior Software Engineer, Quantum
Mariia Mykhailova is a software engineer at the Quantum Architectures and Computation group at Microsoft. She focuses on developer outreach and education work for the Microsoft Quantum Development Kit. In her spare time she writes problems for programming competitions and creates puzzles.