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

Consolidate Forest-Tutorials here #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ RUN apt-get update && apt-get -yq dist-upgrade && \
apt-get install --no-install-recommends -yq \
ghostscript imagemagick texlive-latex-base texlive-latex-extra && \
rm -rf /var/lib/apt/lists/*
RUN sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<policy domain="coder" rights="read | write" pattern="PDF" \/>/g' /etc/ImageMagick-6/policy.xml

# install requirements for running pyQuil tutorial notebooks
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

# install jupyter notebook and jupyter lab
RUN pip install --no-cache-dir notebook jupyterlab
RUN pip install poetry
COPY pyproject.toml poetry.lock ./
RUN poetry config virtualenvs.create false
RUN poetry install

# create user with UID 1000 and associated home dir (required by binder)
ARG NB_USER=binder
Expand All @@ -25,8 +25,9 @@ RUN adduser --disabled-password \
--uid ${NB_UID} \
${NB_USER}

# copy over files from the repository into /home/forest-notebook
COPY . /src/forest-notebook
WORKDIR ${HOME}
COPY tutorials ./tutorials/
COPY Welcome.ipynb .

# transfer ownership of /home/binder and /src to binder user
USER root
Expand All @@ -37,6 +38,4 @@ USER ${NB_USER}
# signal that we need to publish port 8888 to run the notebook server
EXPOSE 8888

# run the notebook server
WORKDIR /src/pyquil
CMD ["jupyter", "lab", "--ip=0.0.0.0"]
CMD ["poetry", "run", "jupyter", "lab", "--ip=0.0.0.0"]
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Interactive quantum programming with Forest & Jupyter
The `forest-notebook` repository contains the [`Dockerfile`][dockerfile]
for building the [`rigetti/forest-notebook`][forest-notebook] image.
This image contains an interactive quantum programming environment
backed by [JupyterLab][jupyter], akin to the applications available
in the [Docker Stacks][docker-stacks] repository.
backed by [JupyterLab][jupyter].

The image is based off of the [`rigetti/forest`][forest] image, which comes
with [pyQuil][pyquil] installed, as well as [quilc][quilc] and [QVM][qvm]
Expand All @@ -18,7 +17,7 @@ additionally has the [`forest-benchmarking`][benchmarking] library installed,
along with some useful Python packages for data analysis and visualization.
Finally, it contains `jupyter` and the new JupyterLab interface, and is
configured to spin up a notebook server when the image is run, which can
be done via the following command (optionally changing `PORT` to `localhost`
be done via the following command (optionally changing `PORT` to the `localhost`
port you'd like to run the notebook server on):

```bash
Expand Down Expand Up @@ -76,12 +75,20 @@ For some examples of existing Forest-backed Binder repositories, check out the f
- [`exeter-quantum/senior-project`][exeter]:
Notebooks from a quantum computing senior project at Phillips Exeter Academy.


Tutorials
---------

This repository also contains tutorial notebooks for learning about [pyQuil][pyquil],
the Forest SDK ([quilc][quilc] and the [QVM][qvm]). If you'd like to add a notebook, or change an
existing one, make a pull request! And, to run the existing notebooks in a preconfigured environment
on Binder, click the badge above!

[arxiv]: https://arxiv.org/abs/2001.04449
[benchmarking]: https://github.com/rigetti/forest-benchmarking
[binder]: https://mybinder.org/v2/gh/rigetti/forest-tutorials/master?urlpath=lab/tree/Welcome.ipynb
[binder]: https://mybinder.org/v2/gh/rigetti/forest-notebook/master?urlpath=lab/tree/Welcome.ipynb
[dockerfile]: https://docs.docker.com/engine/reference/builder/
[docker-badge]: https://img.shields.io/docker/pulls/rigetti/forest-notebook.svg
[docker-stacks]: https://github.com/jupyter/docker-stacks
[exeter]: https://github.com/exeter-quantum/senior-project
[forest]: https://hub.docker.com/r/rigetti/forest
[forest-notebook]: https://hub.docker.com/r/rigetti/forest-notebook
Expand All @@ -94,6 +101,6 @@ For some examples of existing Forest-backed Binder repositories, check out the f
[mybinder]: https://mybinder.org
[pyquil]: https://github.com/rigetti/pyquil
[qcs-paper]: https://github.com/rigetti/qcs-paper
[quilc]: https://github.com/rigetti/quilc
[qvm]: https://github.com/rigetti/qvm
[quilc]: https://github.com/quil-lang/quilc
[qvm]: https://github.com/quil-lang/qvm
[stanford-cs269q]: https://github.com/karalekas/stanford-cs269q
1 change: 0 additions & 1 deletion VERSION.txt

This file was deleted.

174 changes: 174 additions & 0 deletions Welcome.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"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
}
Loading