The post Inside the Quantum Katas, part 2: testing quantum programs appeared first on Q# Blog.

]]>In this blog post we will continue the deep dive into testing different types of quantum programming tasks.

Tasks that ask the learner to implement a given unitary transformation – an operation on qubits that changes their state – are frequently seen in the katas. Quantum oracles and more complicated operations such as quantum Fourier transform or quantum arithmetic are just a few examples that justify their popularity.

Verifying that the learner’s solution is correct can be done by comparing it to the reference implementation using the AssertOperationsEqualReferenced library operation. This operation relies on the Choi–Jamiołkowski isomorphism to reduce the comparison of two unitaries to a comparison of a quantum state to the all-zeros state. Let’s take a quick look at how it works for the small case of single-qubit unitaries (for unitaries acting on multiple qubits the principle is the same but the math is bulkier).

- We will start by preparing an entangled state |Φ⁺⟩ = 1/√2 (|00⟩ + |11⟩).
- Apply the learner’s solution that implements the unitary U to the second qubit:
1/√2 (|0⟩ ⊗ U|0⟩ + |1⟩ ⊗ U|1⟩) This state carries all information about the effects of the unitary on all basis states, and thus, all the information about the unitary itself (up to a global phase). - Now apply the adjoint of the reference implementation R to the second qubit:
1/√2 (|0⟩ ⊗ R†U|0⟩ + |1⟩ ⊗ R†U|1⟩) The trick turns out to be similar to the one we’ve seen when testing the state preparation tasks. If the unitaries R and U are the same, their effects on the state are going to cancel out, and we’ll get the state |Φ⁺⟩ with which we started. If the unitaries are different, their effects either on the |0⟩ state or on the |1⟩ state will not cancel out, and we’ll end up with a different state. - To check whether we ended up with the original state |Φ⁺⟩, we can use the same trick again: apply the adjoint of the routine used to prepare it from the |0⟩ state and compare the result to the |0⟩ state.

With all these steps hidden away in the library operation, the actual test code ends up very short. Here is the testing harness from the first task of the MultiQubitGates tutorial:

@Test("QuantumSimulator") operation TestCompoundGate () : Unit { AssertOperationsEqualReferenced(3, CompoundGate, CompoundGate_Reference); }

In the previous examples we’ve covered tasks that focused on practicing using quantum gates; now let’s learn more about the tasks that offer measurements practice.

The Measurements kata offers tasks which give the learner qubits in one of two or more possible orthogonal states (for example, |0⟩ or |1⟩) and ask to figure out which state it was. This type of task can be tested as follows:

- Pick one of the possible input states randomly.
- Prepare the qubits in this state and pass them to the solution.
- Compare the solution’s answer with the state we picked to see if it’s a match.
- Repeat the steps 1-3 several times to reduce the probability that the solution guessed the state accidentally. This also allows us to gather statistics on the incorrect guesses to help the learner identify their mistakes, such as confusing the indices of states returned or making randomized guesses instead of deterministic.

The testing harness complete with error tracking can get somewhat lengthy; you can find the complete example from the Measurements kata here.

This testing approach can be used for other types of tasks as well. The second part of the Measurements kata offers tasks in which the solution has to identify the state with a certain probability or without errors but with some “unknown state” verdicts allowed. A more recent DistinguishUnitaries kata asks the learner to figure out which of the two unitaries they are given by designing the right experiment.

Sometimes we care not only about the results produced by the solution but also about the operations used by it. Here are several examples of such tasks:

- The Deutsch-Jozsa algorithm example from part 1, in which we want to ascertain that the learner uses the quantum algorithm rather than the classical one, and the most reliable way to do this is to limit the number of times they can use the oracle.
- The random numbers generation tutorial prohibits the use of classical random number generation routines to make sure the learner uses the quantum approach to generating randomness.
- The task that asks the user to implement CNOT using joint measurements restricts the use of two-qubit gates, since otherwise calling CNOT or Controlled X would achieve the formal goal without making the point.

Some of these needs can be addressed by the library operation AllowAtMostNCallsCA. However, the Quantum Katas use a more sophisticated and more flexible approach: the CounterSimulator. It is a custom simulator built as an extension to the full state simulator provided with the QDK, and it counts various resources used during the “normal” program simulation. Developing a simulator with resource counting capabilities is out of scope for this blog post, but since it exists (and is shipped as part of the Microsoft.Quantum.Katas NuGet package), the testing harnesses can use its methods to get the necessary resource counts.

Here is the testing harness for the Deutsch-Jozsa algorithm which runs the algorithm on the given oracle, checks that its result is correct and then checks that the solution doesn’t overuse the oracle calls:

operation TestDJAlgorithm (N : Int, oracle : (Qubit[], Qubit) => Unit, expected : Bool, msg : String) : Unit { EqualityFactB(DJ_Algorithm(N, oracle), expected, msg); let nu = GetOracleCallsCount(oracle); Fact(nu <= 1, $"You are allowed to call the oracle at most once, and you called it {nu} times"); }

Similarly, sometimes we care about the number of auxiliary qubits allocated by the solution. The simplest examples are tasks that ask the learner to implement a phase oracle for a certain function. If the task aims to teach phase manipulation, it might prohibit the solution allocating extra qubits to render implementing a marking oracle and then using the phase kickback trick impossible.

What will the testing harness look like in this case? We can validate that the solution implements the right unitary using the AssertOperationsEqualReferenced operation from the example 1. On top of that, we can use another library operation, AllowAtMostNQubits, to check that AssertOperationsEqualReferenced allocates exactly 2N qubits, where N is the number of qubits on which the oracle acts. (Why 2N? Remember that AssertOperationsEqualReferenced uses 2N qubits to compare the unitaries that act on N qubits. If the reference solution does not allocate extra qubits, any qubits allocated on top of 2N must come from the learner’s solution!)

Here is the testing harness used for the task:

@Test("QuantumSimulator") operation TestPhaseOracle () : Unit { let N = 3; within { AllowAtMostNQubits(2*N, "You are not allowed to allocate extra qubits"); } apply { AssertOperationsEqualReferenced(N, PhaseOracle, PhaseOracle_Reference); } }

These testing patterns are the ones most frequently used in the Quantum Katas. There are plenty of one-off tasks that require more elaborate testing logic (the whole counting multi-qubit gates functionality of the CounterSimulator is only used in one task!), but these should help you get started with testing your own quantum code.

If you’re looking for more advanced scenarios of code verification, see the paper “A Resource Estimation and Verification Workflow in Q#” by Mathias Soeken et al.

The post Inside the Quantum Katas, part 2: testing quantum programs appeared first on Q# Blog.

]]>If you’re reading this blog post, you probably have heard of the Quantum Katas – our collection of tutorials and programming exercises that help one learn quantum computing via quantum programming.

The post Inside the Quantum Katas, part 1 appeared first on Q# Blog.

]]>If you’re reading this blog post, you probably have heard of the Quantum Katas – our collection of tutorials and programming exercises that help one learn quantum computing via quantum programming. (If you haven’t, check them out – I’ve heard great feedback about them )

The Katas are about two and a half years old, and I’ve written about them before once or twice – from the first overview of the project and the summary of its first year in public to its part in this year’s Hacktoberfest celebration (we got 23 pull requests from 11 different folks, 8 of them first-time contributors!)

Oddly enough, I’ve never written about the internal workings of the katas or their most important component – the testing harnesses that provide the learner immediate feedback on their solutions. Testing quantum programs is an interesting topic, very different from testing classical code in some respects and quite similar to it in others. Let’s see how we build the Quantum Katas and how we test them.

Each kata is a sequence of individual tasks, and each task consists of several pieces working in concert.

- The task.

This is the “frontend” of the task, the part where the user spends most of their time. It includes the description of the task (what needs to be accomplished, the format of inputs and outputs, examples and any restrictions imposed on the solution) and the signature of the Q# operation that the learner needs to implement.

A typical kata will have two “frontends” – in the`Tasks.qs`

file (used when solving the kata in Visual Studio or VS Code) and in the Jupyter Notebook. The task description and, most importantly, the operation signature of the task should always match in both cases, though the Jupyter Notebook “frontend” certainly looks much fancier! - The reference solution.

`ReferenceImplementation.qs`

file contains the “reference” solutions to all tasks – correct solutions to the tasks that will pass the tests. Sometimes these solutions play a significant role in the testing of the learner’s code, and one can always turn to them to get an idea about the expected approach to the task. That last goal, though, is often better served by the workbooks – the worked-out explanations of the tasks and their implementation in code that are included in many katas. - The testing harness.

Finally,`Tests.qs`

file contains the code that verifies whether the learner’s code is correct. It is implemented as a collection of unit tests, one per task, that pass if the learner filled in the right code to solve the task and fail otherwise. (This means that when you start solving the kata in VS or VS Code, all tests are failing – a somewhat scary set up!)

The Jupyter Notebook “frontend” doesn’t support unit tests, so the testing harness is invoked using the`%kata`

magic command included in the code cell that contains the task operation.

The most important part of developing a new task is creating the testing harness for it. When we consider the ways to test a solution, we follow one main principle:

In other words, we test whether the solution accomplishes the given task, not the exact path it takes to do that.

Consider, for example, the following task: given a pair of qubits in the |00⟩ state, prepare one of the Bell states |Φ⁻⟩ = 1/√2 (|00⟩ – |11⟩). There are a lot of ways to do this – start by preparing a different Bell state |Φ⁺⟩ = 1/√2 (|00⟩ + |11⟩) and then adjust the relative phase of the second term by applying the Z gate to one of the qubits, or apply an X gate to one of the qubits before applying the Hadamard gate to it and using it as a control in CNOT gate – the possibilities are endless! At the same time we don’t really care which path to the solution the learner takes – the idea of the task is to practice using Pauli gates and the CNOT gate to prepare entangled states, and if the end result is the right superposition state, the task achieved its goal.

Of course, sometimes the goals of the task are more sophisticated than this. The first time we hosted a workshop using the prototype of the DeutschJozsaAlgorithm kata, one of the attendees went ahead and implemented the classical solution to the problem solved by the Deutsch-Jozsa algorithm (figuring out whether the given function is constant or balanced), applying the quantum oracle to basis states to evaluate the classical function. This is a valid classical approach (and later we added it as a separate task to the ExploringDeutschJozsaAlgorithm tutorial), but not the quantum algorithm we’re looking for! We had to add an extra check to count the number of times the given oracle is applied in the learner’s solution, and if it is more than once, fail the test.

Over the years we have accumulated quite a box of tricks for testing different kinds of programming tasks, and I’ll share some of them in the second part of this post. For now, let’s take a look at the simplest example (that is also historically the first type of tasks developed for the Katas) – testing a state preparation task.

Let’s use our Bell state preparation task again: given a pair of qubits in the |00⟩ state, prepare the state |Φ⁻⟩ = 1/√2 (|00⟩ – |11⟩).

First, how does the task signature look like? We want the task to take a pair of qubits as a parameter and have no return – the result of the task is the change in the qubits’ state. The Q# signature that matches this is

operation PrepareBellStatePhiMinus (qs : Qubit[]) : Unit { // ... }

This is it! In the task we leave the operation body blank and mark the part that needs to be filled by the learner with a `// ...`

comment.

To get the reference solution, we just copy the task signature, rename the operation and fill in the code that solves the task.

operation PrepareBellStatePhiMinus_Reference (qs : Qubit[]) : Unit { H(qs[0]); CNOT(qs[0], qs[1]); Z(qs[0]); }

Now, how can we test this kind of a task?

Remember that Q# doesn’t give us direct programmatic access to the amplitudes of the quantum state vector, since that doesn’t match the physical reality of a quantum-mechanical system. Instead, it offers a variety of operations in the Microsoft.Quantum.Diagnostics namespace that can only be applied when running the code on a simulator – which is the case for the Katas – and allow to provide diagnostics on the simulator and to check various assertions about its state. In our case we’ll run the test on the full state simulator and use AssertAllZero operation which passes if all qubits of the given array are in the |0⟩ state and fails otherwise.

At this point an attentive reader should ask “Wait, we are given the |00⟩ state, we’re not trying to prepare it, are we?” We’ll need to do one more step before we can use this assertion to implement our test, and this step involves the reference solution for the task and the very convenient ability of Q# compiler to generate adjoints of quantum operations automatically.

More specifically, we have the learner’s solution that implements a transformation U, and we need to check whether it transforms the initial |00⟩ state to the required state |Φ⁻⟩:

We also know that our reference solution R performs this transformation correctly:

Let’s apply adjoint of our reference solution R† to both parts of the check we want to do:

We see that if we start with the |00⟩ state and apply first the learner’s solution and then the adjoint of the reference solution, we’ll end up with the |00⟩ state again if and only if the learner’s solution did indeed prepare the |Φ⁻⟩ state. Importantly, the results of this check don’t depend on the path the solution took to arrive to the required state.

The code implementation of this test ends up being shorter than the explanation of the logic behind it: once we add “is Adj” to the signature of the reference implementation to enable automatic adjoint generation,

@Test("QuantumSimulator") operation TestPrepareBellStatePhiMinus () : Unit { using (qs = Qubit[2]) { PrepareBellStatePhiMinus(qs); Adjoint PrepareBellStatePhiMinus_Reference(qs); AssertAllZero(qs); } }

This testing harness can be improved further. For example, the error message it produces, “Qubit in invalid state.”, is not very helpful for the learner. The Superposition kata makes an extra effort to output the desired superposition state and the state prepared by the learner’s solution (using another convenient diagnostic operation DumpMachine) before comparing these states.

In part 2 of this blog post we’ll take a look at other types of programming tasks offered in the Quantum Katas and the tools we use to test them. Stay tuned!

The post Inside the Quantum Katas, part 1 appeared first on Q# Blog.

]]>The post Interning at Microsoft Quantum – 2021 appeared first on Q# Blog.

]]>This summers’ internships turned out to be quite different from what we planned for when we sent out offers to our interns in February. We were looking forward to a perfectly regular summer, the interns flying in from all over the world to join us in Redmond… And then COVID happened, which, among everything else, meant that there would be no travel and no in-person interactions with the interns. Fortunately, Microsoft has been able to save most internships by switching them to virtual format. But that posed a new set of challenges: how to make a virtual experience as immersive, educational, and enjoyable as an in-person internship would have been?

The work on the projects looked very similar to a regular year, with the addition of a fair number of extra meetings. Admittedly, it is a lot easier to catch your mentor online in a scheduled one-on-one than in an impromptu meeting like one would normally do when sharing an office. The interns’ project presentations were not changed much compared to last year as well, with other interns and employees stopping by to listen in a Teams meeting instead of a meeting room.

Social and networking events proved to be more of a challenge. Some of them, like the OneWeek Hackathon and Intern Puzzle Day, switched to online format relatively easily – a lot of the experience in these events depends on one’s team, and both offered great ways to find a good team to hack or to solve puzzles with. The “Introduction to quantum computing” workshop hosted by our team for the interns made the transition nicely as well, attracting over 700 interns from across the company and ending up being one of the favorite intern events throughout the summer. The main downside of the newly online events format? No new cool photos to commemorate them!

Other events required some ingenuity to orchestrate. How do you replace bumping into a fellow intern at the watercooler or joining an employee from a different part of the company for a chat at lunchtime? Our team organized multiple events to attempt to replicate or replace various parts of the experience – from “open office” times with team leaders and weekly brown bags where team members talked about their work to a Q# learners club to weekly online “board game nights” and an occasional virtual escape room. Some of these opportunities were only introduced this year, and we hope that helped to make the virtual experience both useful and memorable!

In the upcoming season we will be offering three different types of internships:

- Research internships are the most traditional of our internships, targeting graduate students pursuing a PhD in quantum computing. (Read more about the past research internships in the last year’s announcement.)
- In 2019 we introduced quantum programming internships, focusing on software projects in Quantum Development Kit or Azure Quantum. I hope to share more information about our interns’ projects later, as they are polished up and/or released to the public. Here is a sneak peek at the project two of our interns worked on – new %trace and %debug commands for Q# Jupyter Notebooks. (You can also read more about the previous quantum programming internships in last year’s announcement.)
- In the new program management internship the intern will work with our Azure customers to design Azure Quantum to help them achieve their goals.

Regardless of the kind of projects our interns will work on, one thing I’m certain about – this will be an awesome experience for them!

Does this sound like a great way to spend your summer? Apply to our open internship positions today! Application deadline is January 8

^{th}, 2021.

**Update (November 23 ^{rd})**: Per the announcement, our 2021 Intern Program will be fully virtual in 2021. As was the case last season, our program is able to support internships for students located in the US and Canada.

The post Interning at Microsoft Quantum – 2021 appeared first on Q# Blog.

]]>The post Q# Advent Calendar 2020 appeared first on Q# Blog.

]]>The rules are simple:

- Reserve a slot by leaving a comment on this post. (You can also tweet about it, but you’ll have to mention @tcNickolas to make sure we’ve seen it!) The slots are assigned on the first come, first serve basis. You do not have to announce the topic of your blog post until you’re ready to publish it, but we’d really love to hear it beforehand. (This also helps other bloggers to pick a topic that is not too close to the ones already covered.)
- Prepare a blog post (in English) about Q#, cool project you’ve done in Q#, learning Q#, teaching Q#, using Q# for research, tools for working with Q#… You got the idea.* Don’t forget to check out the previous calendars for inspiration!
- Publish your blog post on your assigned date. Don’t forget to link back to the Q# Advent Calendar from your post, so that your readers can find the entire advent.
- Leave the link to your blog post in a comment to this post, and we’ll add it to the calendar. If you share a link to your post on Twitter, use hashtags #qsharp and #QsAdvent.

**Q# Advent Calendar accepts only original content.*

Looking forward to reading your Q# stories!

The post Q# Advent Calendar 2020 appeared first on Q# Blog.

]]>The post Celebrating our open source community with Hacktoberfest appeared first on Q# Blog.

]]>The Quantum Development Kit (QDK) includes a lot of components: from the samples and libraries that were released as open source back in 2017, to the compiler and runtime open sourced in 2019, to the newest addition to the roster – Q# language repository that hosts language design discussions. (Here is an excellent overview of the components and open source repositories that are part of the QDK.)

As the footprint of our open source code grew, so did the community around it. The most active of our open source repositories – the collection of tutorials and programming exercises on quantum computing called the Quantum Katas – has over a hundred contributors, only around 20% of them from Microsoft Quantum team!

Some of our contributors have been with us for over a year; it doesn’t seem like a long time, until you remember that the QDK itself is less than three years old! Today I am delighted to recognize one of our most dedicated contributors, Vincent van Wingerden, and to promote him to the role of maintainer of the Quantum Katas. In his day job Vincent is a technical architect at Microsoft for Data & AI, helping people create the best possible data solutions on Azure. He started contributing to the Quantum Katas in November 2019, and since then he did a lot of work on the workbooks – the detailed explanations of the solutions to the programming tasks offered in the tutorials. In fact, Vincent is the second most active contributor to the Katas – and now he has a chance to experience the other side of the open source, helping others to do their first contributions.

Over the past year we hosted several internal Hackathons, including a Hacktoberfest celebration at the Microsoft Garage.

This October, in-person meetups are not really an option, so we decided to take the experience online – and open it to everybody worldwide!

One of the most important things in getting started is finding just the right thing to work on. People new to GitHub need something very simple, so that they can focus on mastering the contribution process itself – it is not complicated but can be baffling when going though it for the first time. Experienced GitHub users might pick a slightly more complicated issue to learn more about quantum computing or compilers. And regular contributors can challenge themselves to do an advanced project, though they are not shy about doing it any time of year!

With this in mind, we selected a variety of issues spanning nearly all areas in the QDK and a broad range of complexity, from small writing tasks to fixing bugs and developing small features.

- The Quantum Katas issues.
- Q# samples issues.
- Q# libraries issues.
- Q# compiler issues.
- Documentation issues.

You can also check out our contribution guide and browse all our repositories to see if there is something not on this list that piques your curiosity.

Ready to start? Here are three easy steps:

- Register for Hacktoberfest. Once you send 4 pull requests to GitHub repositories this October, you’ll be eligible for their “tee or tree” reward – a Hacktoberfest T-shirt or a tree planted on your behalf.
- Join our kick-off call on October 8th to meet the maintainers of our repositories and learn about the areas you can contribute to.
- Head to our open source repositories, pick an issue with Hacktoberfest label and get started!

We’ll be there to answer your questions and guide you through the contributions.

Happy hacking!

The post Celebrating our open source community with Hacktoberfest appeared first on Q# Blog.

]]>We hear from many students that they’re excited about quantum computing,

The post Interning at Microsoft Quantum appeared first on Q# Blog.

]]>We hear from many students that they’re excited about quantum computing, but are not sure whether they should apply. So we’re going to demystify our internships by sharing some of the projects our past interns have worked on and how being a research intern with our team differs from being an engineering intern.

The Microsoft Quantum internship program started back in 2012 with just three research interns. The program has been growing steadily ever since, reaching a total of 21 interns during summer 2019. Research interns are typically graduate students pursuing a PhD in quantum computing or related subjects. Their internship projects involve exploring new research directions under guidance of full-time researchers on our team, resulting in a paper or even a patent. These internships can grow into a long-term research relationship, and several of our former interns have joined our team as full-time employees soon after their internships. Here are just a few examples:

- Bettina Heim worked on decoding surface codes using maximum likelihood decoding.
- Vadym Kliuchnikov developed an algorithm for circuit synthesis – approximating single-qubit unitary operations with a limited set of gates used by some topological quantum computers.
- Thomas Haner worked on reducing resource requirements for evaluating classical functions on quantum computers, including addition using dirty qubits and evaluating piecewise polynomial approximations.
- Adam Paetznick developed a decomposition technique that uses non-deterministic circuits to approximate single-qubit unitary operations.

In summer 2019, undergraduate students joined our internship program for the first time in software engineering positions. These students focused on software-oriented projects such as improving the Quantum Development Kit. Although our undergraduate software engineering internship are much newer, we already have some neat success stories to share:

- Sarah Marshall implemented code completion for Q# and a state visualization tool that allows you to track the state of the Q# program during the simulation – and just this week she joined the team as a full-time software engineer!
- Rory Soiffer built a framework for Q# code optimizations.
- Artem Astapchuk created a set of tutorials on the basics of quantum computing.

Most of our interns join us on the Microsoft Redmond campus. This means they can participate in all summer events there, from the all-Microsoft OneWeek Hackathon and celebration that bring together interns and employees across the company to intern-only events like Microsoft Intern Puzzle Day and workshops hosted by various teams.

*“Introduction to quantum computing” workshop hosted by our team for all Microsoft interns*

They also get ample exposure to various directions of ongoing quantum computing research, both via their fellow interns’ presentations of their projects and via a weekly journal club.

Does this sound like a great way to spend your summer? Apply to our open intern positions today! Application deadline is January 31

^{st}.

The post Interning at Microsoft Quantum appeared first on Q# Blog.

]]>First,

The post Festivus: Q# Feats of Strength appeared first on Q# Blog.

]]>- First, we open-sourced the QDK and deprecated the UserVoice channel, so there is no single channel for QDK feedback any longer.
- Second, our users don’t typically open GitHub issues just to thank the language creators for an especially nice feature!

Instead, we decided to poll our team members for their favorite Q# feature or a particularly useful tool. Check out their replies below – you might find something new to try!

- The partial application syntax to create closures is actually quite nifty and very useful… Here is an example. –
*Alan Geller* - The functor support is very straightforward and easy to use. Just put Adjoint in front of an adjointable operation and [the compiler] figures it out. –
*Scott Carda* - And that we support borrowing is neat too, for the more quantum savvy people. –
*Bettina Heim* - I would highlight that qubit management happens automatically in a well structured context. –
*Andres Paz* - apply … within and AssertProb. –
*Vadym Kliuchnikov* - QDK is open source! Plus first-class functions and operations + partial application lets you do just about everything. –
*Chris Granade* - Tools for testing and debugging and Jupyter Notebooks support: the first feature to make the Quantum Katas possible and the second one to make them beautiful! –
*Mariia Mykhailova* - It is hard to pick just one thing…
- Q# libraries, from simple (but really useful) tools in the Canon to more complex things like the multiplexer and state preparation tools to specialized libraries written in collaboration with domain experts like the chemistry library and the numerics library.
- The resource estimator that allows you to gather metrics such as number of qubits, circuit depth, and circuit size at scale, i.e., for quantum programs that may involve millions of qubits and billions of quantum gates!
- The effortless ease with which simple quantum algorithms such as Bernstein-Vazirani or hidden shift or Simon’s algorithm can be implemented. Simon’s algorithm needs complex post-processing (linear algebra over GF(2)) and I like how this can be done by using Q# in tandem with C#. Also, the synthesis of permutations is a cool feature.

*Martin Roetteler*

How about you – what is your favorite Q# feature?

The post Festivus: Q# Feats of Strength appeared first on Q# Blog.

]]>Let me continue the topic of teaching and learning quantum computing that I touched upon yesterday and share with you the project done by my summer intern Artem Astapchuk –

The post New Tutorials: Learn the Basic Concepts of Quantum Computing appeared first on Q# Blog.

]]>Let me continue the topic of teaching and learning quantum computing that I touched upon yesterday and share with you the project done by my summer intern Artem Astapchuk – a set of tutorials that introduce the most basic concepts used in quantum computing.

The Quantum Katas start with the BasicGates kata – a set of exercises that ask the learner to identify the quantum gate that will perform the described transformation of a qubit state. It seems like a very easy thing to do – how hard can it be to look up a list of quantum gates and match one of them to the task?

Turns out, it is pretty hard for somebody who sees the quantum computing notation for the first time. Even the easiest task that asks to apply the Pauli X gate relies on a lot of implied knowledge. What is a qubit and its state? What are these weird symbols around 0 and 1? What kind of tools do you use to change the state of the qubit? And how do you express all this in Q#?

Historically the Katas sent the learner to find an external source for learning the basic concepts and notations used in quantum computing. However, eventually it started to make more sense to create a set of tutorials that would teach the learner everything they need to start solving the first katas in one place and using one style.

Well, here they are! Two tutorials that cover the math necessary for working with quantum computing – complex arithmetic and linear algebra – are written in Python, and the four that introduce the quantum computing concepts – qubits and superposition, multi-qubit systems and entanglement, and single- and multi-qubit gates – are implemented in Q#.

We tried to steer away from too much theory and to give just the definitions and the tools necessary for getting started (yes, qubit states are described using Hilbert spaces; no, you don’t need to know this to start learning). Instead, we focused on making the learning process as hands-on as possible, using demos and programming exercises to help learner internalize the new concepts and ideas by applying them to solving simple tasks.

For example, the definition of the imaginary unit *i* is immediately followed by a programming task that asks one to calculate the *n*-th power of *i* *iⁿ*; the introduction of the qubit states is followed by a demo that shows how to examine and interpret the qubit state in Q# using the DumpMachine function, and so on.

If you’re looking to get started with quantum computing, give these tutorials a try and let us know what you think!

Meanwhile, we’ll keep working on bringing you more tutorials. Next up: measurements!

The post New Tutorials: Learn the Basic Concepts of Quantum Computing appeared first on Q# Blog.

]]>This winter our team had an exciting opportunity to teach an introductory course on quantum computing at the University of Washington, led by Krysta Svore.

The post Teaching Quantum Computing with Q# appeared first on Q# Blog.

]]>This winter our team had an exciting opportunity to teach an introductory course on quantum computing at the University of Washington, led by Krysta Svore. It was a special experience for all of us, but especially for me, since I’ve never been involved in the university education process in any role other than a student.

*If you prefer watching videos to reading, here are the videos from Microsoft Faculty Summit 2019, where Martin Roetteler and I talk about our experience teaching this course: part 1 and part 2.*

First of all we had to figure out what we are going to cover in the course and how to teach it. Quantum computing is a huge field, and can be taught from a variety of different angles, from quantum physics and the physical realization of quantum computers to pure quantum information theory. What to choose?

We decided to approach the subject from a computer scientist’s point of view, focusing on programming and solving practical problems. Indeed, a typical course in classical computing starts by introducing a programming language and teaching the students to use it to solve simple tasks; then it covers basic algorithms and data structures, with homework assignments centered around implementing the data structures and using the algorithms to solve more complicated tasks; finally, the students have a choice of courses on more advanced topics (again with practical applications), capstone projects etc. You don’t often see a classical software engineer who would be trained in transistor physics and computational complexity theory but who only ever implemented algorithms on paper!

We ended up creating a course leaning heavily towards the practical implementation of quantum algorithms; it included both written assignments and programming assignments, with the latter accounting for a larger share of the final grade than the former, and a final programming project instead of a more customary written exam or a presentation-style project.

Our main tool for teaching the students quantum programming were the Quantum Katas. I’ve mentioned them before once or twice, so I won’t go into great detail on them again – I’ll just note that they are as good for classroom learning as they are for self-paced. In addition, they did a really good job of preparing the students for their homework.

Programming assignments were structured exactly like the katas (that was before we introduced the Jupyter Notebooks, so all programming materials were Q# projects): the students would get a file with task descriptions and the skeleton operations for them, and they’d have to fill in the code that solves the tasks. Here, for example, is the first task from week 4 of the course, in which we covered quantum oracles:

The neatest thing about the programming assignments was that they were graded automatically. (I’ve never been in a TA’s shoes myself, but I can certainly sympathize with the need to grade over 30 assignments!) Similarly to the katas, each task of the assignment was covered by a test, and if the test passed, the solution was judged correct.

In week 6 of the course we tried a different flavor of a programming assignment: the students had to do resource estimation for Shor’s algorithm implemented in our samples. These tools would come handy for them later in the course.

The last programming assignment was even more unusual for quantum computing courses than the previous ones: the students were to take part in the Q# Coding Contest, which was conveniently held during the last month of the course. Programming courses on algorithms or machine learning sometimes use a similar approach, offering problems from Kaggle, Codeforces or other online judges as assignments or even hosting small programming competitions for the students.

However exciting hosting the contest was for us, the students didn’t take it well. A lot of topics in the contest were covered in the course, but the contest tasks were much harder than the homework assignments. Add the extra pressure from the timed nature of the competition and the requirement to participate in it alone, and the results were disappointing: only one student solved all problems.

The final projects were small capstones for the course: the students would form teams of 2-3 people and work on a quantum computing problem of their choice, going through all the steps from choosing and defining the problem to solving it and implementing the solution in Q# to describing the solution in a mini-paper and presenting it to the class.

This was the favorite part of the course for a lot of students. On the one hand, it allowed them to focus on any topic they were excited about and to deep-dive into it. On the other hand, it was extremely practical: the students had a chance to actually experiment with their algorithms of choice, figure out how much resources are required to run them and how to construct a small instance of a problem that can be solved on a simulator, optimize their solutions and compare different implementations — in other words, do a lot of things that comprise a quantum software engineer’s day work!

The last two lectures of the course were dedicated to the final projects presentations. This was when I got to finally meet the students in person (before that I focused on behind-the-scenes parts of the course, so the students knew me only as a disembodied online presence). The range of projects done by the students was quite impressive — from entanglement games and key distribution protocols to quantum chemistry and a Bitcoin mining algorithm!

The course has completed over half a year ago, but it had more lasting outcomes than just a pass/fail grade for the students who took it.

First, several teams chose to frame their final projects as new katas and to contribute them back to the Quantum Katas project for the next generation of learners to use.

Second, several students went on to do internships at companies who work on quantum computing (well, most of those were on our team, but that still counts!) and quite possibly will make a career in it.

Finally, we learned a lot about the best ways to teach people quantum computing. We really hope to teach a new, updated and improved version of this course soon! Meanwhile, we are happy to share our materials and learnings with other instructors looking to teach quantum computing from a practical point of view (if you’re interested, contact me at mamykhai@microsoft.com).

The post Teaching Quantum Computing with Q# appeared first on Q# Blog.

]]>The post Q# Advent Calendar 2019 appeared first on Q# Blog.

]]>The rules are simple:

- Reserve a slot by leaving a comment on this post. (You can also tweet about it, but you’ll have to mention @tcNickolas to make sure we’ve seen it!) The slots are assigned on the first come, first serve basis. You do not have to announce the topic of your blog post until you’re ready to publish it, but we’d really love to hear it beforehand
- Prepare a blog post (in English) about Q#, cool project you’ve done in Q#, learning Q#, teaching Q#, using Q# for research, tools for working with Q#… You got the idea. Don’t forget to check out last year’s calendar for inspiration!
- Publish your blog post on your assigned date. Don’t forget to link back to the Q# Advent Calendar from your post, so that your readers can find the entire advent.
- Leave the link to your blog post in a comment to this post, and we’ll add it to the calendar. If you share a link to your post on Twitter, use hashtags #qsharp and #QsAdvent.

The post Q# Advent Calendar 2019 appeared first on Q# Blog.

]]>