Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF Quantum Starter Example #393

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Rishit-dagli
Copy link

Add a TF Quantum example for beginners to get started with TF Quantum. The notebook demonstrates the following pretty simple operations-

  • Placing a Qubit
  • Working with simple quantum data
  • Building a quantum circuit
  • Creating and training a hybrid model
  • Inferencing the hybrid model

I am aware that the tutorial hello_many_worlds exists which is a beginner tutorial however, this tutorial has different aims.

This PR was originally created on tensorflow/examples#244 ported to this repo as suggested by @lamberta .

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@zaqqwerty
Copy link
Contributor

zaqqwerty commented Sep 20, 2020

So most of this code looks to be copied from our already existing notebook at https://github.com/tensorflow/quantum/blob/research/binary_classifier/binary_classifier.ipynb
I see that, relative to the existing notebook, you simplified the quantum data input to have just two entries. Perhaps if there is interest in the existing notebook becoming a tutorial we could consider such a simplification. @MichaelBroughton thoughts on this? (see also page 9 of the TFQ paper)

@Rishit-dagli
Copy link
Author

Rishit-dagli commented Sep 20, 2020

So most of this code looks to be copied from our already existing notebook at https://github.com/tensorflow/quantum/blob/research/binary_classifier/binary_classifier.ipynb
I see that, relative to the existing notebook, you simplified the quantum data input to have just two entries. Perhaps if there is interest in the existing notebook becoming a tutorial we could consider such a simplification. @MichaelBroughton thoughts on this? (see also page 9 of the TFQ paper)

That's right, this is inspired from that notebook, I built this as a simplification to the existing one, to make it a lot easier for beginners to understand.

@MichaelBroughton
Copy link
Collaborator

MichaelBroughton commented Sep 21, 2020

I think we might be able to fit this in as a tutorial, right after the hello many worlds and before the MNIST classification tutorial. The goal of our tutorials is to showcase the functionality and features of the library so that experts have an easy time making the mental connections between how TFQ functions and QC theory (which we generally expect people to have a strong grasp of).

Even though this is a more "beginner" example and doesn't touch any new library code that hello many worlds doesn't already touch, I think showcasing good visualizations of the single qubit rotation problem might give experts a little more opportunity to connect with and understand how TFQ works. (I think ultimately this means moving that particular example out of research and into tutorials @zaqqwerty )

@lamberta Are you alright if I give this a review and then hand off to you for final say ?

Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of thematic and large changes I think we need here, before we go into a more serious review would be:

  1. If this is going to be a more beginner oriented tutorial we should be sure to include the appropriate descriptions of all the processes in the notebook and do our best to explain every step of what is going on. Throughout the notebook things are a little bit unclear. Ideally after the user is done reading the tutorial, they shouldn't have many questions like: Why are we placing a qubit and rotating it in this way ? Why is the shape of the labels array [2,2] ? what does a label of 1 vs 0 mean ? An effort should be made to leave the user with as few of these kinds of questions as possible (since this is a beginner tutorial this is going to be especially tricky and important).

  2. The length of this tutorial is very short. We create the circuit, generate the data, train the model show a graph and then we are done. To help beginners we should definitely showcase some more math and make sure we firm up understanding for them at every step. For example, a good spot in the tutorial I think would benefit from having more detail is the data preparation section. Instead of making 2 datapoints, make 2,000 and then visualize them like we did in the research tutorial this is based on. You could also show some math like "here are the polar coordinates for this particular datapoint. You can see that because the qubit is rotated in this way it's label is this...." etc.

Overall, this is a good first step, but we will need to build things up a fair bit more if we are going to get it ready to showcase as a tutorial.

Comment on lines 2 to 19
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Getting started with [TensorFlow Quantum](https://www.tensorflow.org/quantum)\n",
"\n",
"_Notebook orignially contributed by: [Rishit-dagli](https://github.com/Rishit-dagli)_\n",
"\n",
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github.com/tensorflow/quantum/blob/master/docs/tutorials/tf_quantum_starter.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/quantum/blob/master/docs/tutorials/tf_quantum_starter.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View source on GitHub</a>\n",
" </td>\n",
"</table>"
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be sure and follow the same format used in all of the other notebook headers. If this is going to be rendered on the websites tutorial page it does not need a self link to tensorflow.org/quantum. You also shouldn't include a link to your own personal github page.

@lamberta
Copy link
Member

lamberta commented Oct 2, 2020

Thanks, @MichaelBroughton
I agree. A beginner's tutorial is good, but need to be mindful of the TFQ audience: beginning researchers (and not beginning practitioners). Seems better to port https://github.com/tensorflow/quantum/blob/research/binary_classifier/binary_classifier.ipynb with the sections added here, but with added explanation.

@Rishit-dagli
Copy link
Author

Rishit-dagli commented Nov 4, 2020

Thanks, @MichaelBroughton These points make sense and I will start working on them.

  1. I am just a bit unclear about adding descriptions, I can most certainly have a description to address the questions you mentioned in the comment but would anything more be required to make this more clear?
  2. This makes sense, I will definitely showcase some more math and make sure I firm up understanding for them.

Thanks, @lamberta

A beginner's tutorial is good, but need to be mindful of the TFQ audience: beginning researchers (and not beginning practitioners)

This is something I need to be mindful of while making changes and maybe could change the tone of the tutorial since this tutorial was originally made for a talk I gave at a TensorFlow User Group where some folks were practitioners and was made to help them out too.

@mhucka mhucka added the area/docs Concerns documentation – problems, ideas, requests label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs Concerns documentation – problems, ideas, requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants