Last month we announced Q# integration with Jupyter Notebooks – a web-based environment for creating interactive mixed-media documents. One of the popular applications of Jupyter Notebooks is tutorials. Indeed, the ability to mix text, formulas and images with the code and the results of its execution is just indispensable for explaining an algorithm or teaching a tool and letting the learner experience them first-hand and immediately.
![Jupyter notebook online editor Jupyter notebook online editor](/uploads/1/2/4/9/124904686/657711478.png)
Today, we present the first batch of the Quantum Katas in Notebook format! Those of you who have already tried out the Quantum Katas or attended one of our workshops on quantum computing will recognize the benefits of the new format immediately:
- You don’t need to install anything locally to solve the katas. No more frenzied installations the night before the workshop (or even during the workshop!) – you can run the katas online in any browser using Binder.
- The presentation is a lot smoother and more polished. Even with the Unicode support in Q# comments, there is a dramatic difference in task rendering, since the Notebooks provide full HTML and LaTeX support, and allow images to be incorporated in the task descriptions.Notebooks also allow hints to be hidden until they are needed, as opposed to just being visible in the code upfront. (For the best experience with the hints, we recommend using Firefox, Chrome or Microsoft Edge Dev build.)
- The solution template given in the Notebook does not have to compile, as long as you don’t attempt to solve the task. The solution template given in a Q# project must compile to tell you that your solution is incorrect, so the tasks frequently return a placeholder value just to make the code valid – and for some of the trickier tasks that value is not trivial and sometimes confusing.
A tutorial introducing basic features of Jupyter notebooks and the IPython kernel. Try JupyterLab JupyterLab is the new interface for Jupyter notebooks and is ready for testing.
We will eventually convert all the katas to Notebook format, so that you can solve them in your preferred environment. Meanwhile, try the katas that are already converted and let us know what you think!
IPython kernel of Jupyter notebook is able to display plots of code in input cells. It works seamlessly with matplotlib library. The inline option with the %matplotlib magic function renders the plot out cell even if show() function of plot object is not called. The show() function causes the figure to be displayed below in[] cell without out[] with number.
Now, add plt.show() at the end and run the cell again to see the difference.
Note that the %matplotlib notebook magic renders interactive plot.
Just below the figure, you can find a tool bar to switch views, pan, zoom and download options.
Importantly, if you modify the data underneath the plot, the display changes dynamically without drawing another plot.
In the above example, change the data sets of x and y in the cell below and plot the figure again, the figure above will get dynamically refreshed.