{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Welcome\n", "\n", "This is a Binder repository containing tutorial notebooks for learning about [pyQuil](https://github.com/rigetti/pyquil) and the rest of the Forest SDK ([quilc](https://github.com/quil-lang/quilc) and the [QVM](https://github.com/quil-lang/qvm)). The table of contents for the repository can be found at the bottom of this notebook. If you'd like to add a notebook, or change an existing one, make a pull request to the [rigetti/forest-tutorials](https://github.com/rigetti/forest-tutorials) repository!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The Basics" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pyquil import get_qc, Program\n", "from pyquil.gates import H, CNOT, MEASURE" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Get a quantum virtual machine (simulator)\n", "qvm = get_qc(\"2q-qvm\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "H 0\n", "CNOT 0 1\n", "DECLARE ro BIT[2]\n", "MEASURE 0 ro[0]\n", "MEASURE 1 ro[1]\n", "\n" ] } ], "source": [ "# Build a program\n", "p = Program()\n", "p += H(0)\n", "p += CNOT(0, 1)\n", "ro = p.declare(\"ro\", \"BIT\", 2)\n", "p += MEASURE(0, ro[0])\n", "p += MEASURE(1, ro[1])\n", "p.wrap_in_numshots_loop(10)\n", "print(p)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 1],\n", " [0, 0],\n", " [0, 0],\n", " [0, 0],\n", " [1, 1],\n", " [1, 1],\n", " [0, 0],\n", " [1, 1],\n", " [0, 0],\n", " [0, 0]])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Execute the program synchronously\n", "qvm.run(p).readout_data.get(\"ro\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 1],\n", " [0, 0],\n", " [0, 0],\n", " [1, 1],\n", " [0, 0],\n", " [1, 1],\n", " [0, 0],\n", " [0, 0],\n", " [0, 0],\n", " [1, 1]])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Alternately, asynchronous execution is supported\n", "job = qvm.qam.execute(p)\n", "\n", "# When ready, fetch job results\n", "qvm.qam.get_result(job).readout_data.get(\"ro\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Tutorial Notebooks\n", "\n", "1. [BellStateTomography.ipynb](notebooks/BellStateTomography.ipynb)\n", "2. [GateNoiseModels.ipynb](notebooks/GateNoiseModels.ipynb)\n", "3. [LaTeXQuilCircuits.ipynb](notebooks/LaTeXQuilCircuits.ipynb)\n", "4. [MeyerPennyGame.ipynb](notebooks/MeyerPennyGame.ipynb)\n", "5. [NoiseInvestigation.ipynb](notebooks/NoiseInvestigation.ipynb)\n", "6. [QuantumDie.ipynb](notebooks/QuantumDie.ipynb)\n", "7. [QuantumTeleportation.ipynb](notebooks/QuantumTeleportation.ipynb)\n", "8. [QuantumWalk.ipynb](notebooks/QuantumWalk.ipynb)\n", "9. [QubitPlaceholder.ipynb](notebooks/QubitPlaceholder.ipynb)\n", "10. [ReadoutErrorMitigation.ipynb](notebooks/ReadoutErrorMitigation.ipynb)\n", "11. [ReadoutNoise.ipynb](notebooks/ReadoutNoise.ipynb)\n", "12. [VariationalQuantumEigensolver.ipynb](notebooks/VariationalQuantumEigensolver.ipynb)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.11" } }, "nbformat": 4, "nbformat_minor": 4 }