✅ Put your name here

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#Pre-Class Assignment 23: Background for Quantum Computing

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook starts a unit introducing a different model of computation, a model that plays by the rules ofItinerary for Quantum Computing Unit

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "Assignment | Topic | Description |

Pre Class 23 | Background for Quantum Computing | How Computers Store Information |

In Class 23 | Classsical and Quantum Bits | Information in Quantum States |

Pre Class 24 | Software for Quantum Computing | High Level Software and the Circuit Model |

In Class 24 | Programming Quantum Computers | Manipulating Quantum Bits to Perform Useful Computations |

Before you start...

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Take ten seconds to answer these survey questions:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import HTML\n", "HTML(\n", "\"\"\"\n", "\n", "\"\"\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Learning Goals for Today's Pre-Class Assignment

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By the end of today's pre-class assignment, you should be able to:\n", "\n", "1. Describe how computers store information using binary digits.\n", "1. State the fundamental difference between classical and quantum computers in terms of how they store information.\n", "1. Review/learnHow Computers Store Information

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Watch the following video to learn aboutHow Quantum Computers Store Information

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Recall the last statement from the above video on bits and data:\n", "\n", "\n", "\n", "In the same way, if you want to understand how\"If you want to understand how computers work on the inside, it all comes down to these simple ones and zeros and the electrical signals in the circuits behind them.\"

\n", "\n", "Watch the following short video to get introduced to qubits." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Introduction to qubits.\"\"\"\n", "from IPython.display import YouTubeVideo\n", "YouTubeVideo(\"KBpYK3i3kDs\",width=640,height=360)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#Quantum computers store information inquantum bits, orqubits(pronounced \"CUE bits\") for short.

Understanding Qubits: Three Key Concepts

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To understand a qubit, we only have to understand three concepts.\n", "\n", "1.Concept #1: Complex Numbers

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Watch the following video on complex numbers." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Complex numbers.\"\"\"\n", "from IPython.display import YouTubeVideo\n", "YouTubeVideo(\"3AmdT0CsLbk\",width=640,height=360)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Video Recap

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* TheExercise: Working with Complex Numbers

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "✎ **Do this:** Run the cell below to see how to perform some operations on complex numbers in Python." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Working with complex numbers in Python.\"\"\"\n", "# define two complex numbers\n", "alpha = 1 + 2j # note: j is used for the imaginary unit in Python\n", "beta = 3 - 4j\n", "print(\"alpha =\", alpha)\n", "print(\"beta =\", beta)\n", "\n", "# print out the type of alpha\n", "print(\"\\ntype(alpha) =\", type(alpha))\n", "\n", "# print out the real and imaginary part of alpha\n", "print(\"\\nThe real part of alpha is\", alpha.real)\n", "print(\"The imaginary part of alpha is\", alpha.imag)\n", "\n", "# print out the sum of alpha and beta\n", "print(\"\\nalpha + beta =\", alpha + beta)\n", "\n", "# print out the complex conjugate of alpha and beta\n", "print(\"\\nalpha* =\", alpha.conjugate())\n", "print(\"beta* =\", beta.conjugate())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "✎ **Do this:** Write a function called `modulus_squared` that inputs a complex number $\\alpha$ and returns its modulus squared $|\\alpha|^2 = \\alpha^* \\alpha$. \n", "\n", "Concept #2: Probability

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Watch the following video on probability distributions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Probability.\"\"\"\n", "from IPython.display import YouTubeVideo\n", "YouTubeVideo(\"rfmmhXzi5lk\",width=640,height=360)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Video Recap

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "AExercise: Working with Probabilities

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Question:** Could the following list of numbers be a probability distribution? Why or why not?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Potential probability distribution.\"\"\"\n", "distribution = np.array([0.1, 0.3, 0.2, 0.2, 0.1, 0.2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "✎ **Answer:** Erase the contents of this cell and put your answer here!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Question:** Write a function, called `is_valid`, that inputs a numpy array and returns `True` if the list of numbers defines a valid probability distribution, else returns `False`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Put code for implementing your function here!\"\"\"\n", "def is_valid(array):\n", " pass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the next cell to test your function. If your function is correct, no errors should be thrown." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Run this cell to test your function.\"\"\"\n", "assert is_valid(np.array([0.5, 0.3, 0.2]))\n", "assert not is_valid(np.array([0.2, 0.4, 0.2]))\n", "assert not is_valid(np.array([1.0, -1.0, 1.0]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Concept #3: Linear Algebra & Vectors

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Watch the following video on vectors." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Linear algebra and vectors.\"\"\"\n", "from IPython.display import YouTubeVideo\n", "YouTubeVideo(\"klDm1eC1gxg\",width=640,height=360)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###Video Recap

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* AExercise: Working with Vectors

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following cell shows how we use Numpy arrays to work with vectors in Python." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Using numpy to perform vector operations.\"\"\"\n", "# the |0> == zero vector and |1> == one vector from above\n", "zero = np.array([1, 0], dtype=np.complex64)\n", "one = np.array([0, 1], dtype=np.complex64)\n", "\n", "# print out the vectors\n", "print(\"|0> =\", zero)\n", "print(\"|1> =\", one)\n", "\n", "# some complex numbers\n", "alpha = 0.5 + 0.5j\n", "beta = 1 - 2j" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "✎ **Do this:** Run the following code cell to see how Numpy arrays handle vector operations for us. Complete the last portion, labeled `TODO`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\"\"\"Run this cell. Complete the last portion.\"\"\"\n", "# print out the sum of zero and one\n", "print(\"|0> + |1> =\", zero + one)\n", "\n", "# compute and print out alpha * |0>\n", "print(\"alpha |0> =\", alpha * zero)\n", "\n", "# compute and print out beta * |1>\n", "print(\"beta |1>> =\", beta * one)\n", "\n", "# TODO: print out the superposition alpha |0> + beta |1>\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tying Together the Concepts

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When we introduced a qubit, we said it could be the state $|0\\rangle$, $|1\\rangle$, or superpositions of $|0\\rangle$ and $|1\\rangle$. We can now fully understand this statement.\n", "\n", "AAssignment Wrapup

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Survey

" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "from IPython.display import HTML\n", "HTML(\n", "\"\"\"\n", "\n", "\"\"\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##Congrats, You're Finished!

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, you just need to submit this assignment by uploading it to the course Desire2Learn web page for today's submission folder. (Don't forget to add your name in the first cell.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**© Copyright 2019, Michigan State University Board of Trustees.**