{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to `Workspace` objects\n", "This tutorial briefly explains how pyGSTi visualizes data using `Workspace` objects. Understanding the basics covered here will help demystify the creation of plots and tables in other tutorials.\n", "\n", "PyGSTi prefers to use HTML-based figures (native HTML tables and [Plotly](https://plot.ly/python/) plots) over the perhaps more traditional LaTeX tables and [matplotlib](https://matplotlib.org) plots. There are several reasons for this:\n", "1. Interactivity - HTML allows plots and tables to be interactive; with LaTeX this is impossible and with matplotlib it's painful.\n", "2. HTML's ability to be integrated into web pages (making nicer reports than a many-page PDF) and into Jupyter notebooks.\n", "3. Portability - Plotly figures (HTML and JS) can be more robustly stored and transported (e.g. over the web) than matplotlib `Figure` objects, which are difficult even to pickle with Python.\n", "\n", "The creation of (HTML) figures, both tables and plots, is handled by the `pygsti.report.Workspace` factory object." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pygsti\n", "ws = pygsti.report.Workspace()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Within an IPython notebook like this one, we can create figures in notebook cells by calling (once, usually at the beginning of the notebook):" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ws.init_notebook_mode(autodisplay=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This injects necessary HTML and JavaScript into the notebook so that plots and tables display properly. If everything works properly, you'll see a GREEN \"**Notebook Initialization Complete**\" message. If instead you see a BLUE \"**Loading...**\" message, then 1) check that this notebook is \"Trusted\" in the upper right corner of this window and 2) check that you have a working internet connection. You will need to reload this notebook using your *browser's* reload button after fixing either of these issues.\n", "\n", "Setting `autodisplay=True` means that figures will be displayed as soon as they're created (otherwise we'd have to capture the returned object and call `.display()` on it). By typing `ws.` and then hitting TAB you can see the somewhat-descriptive names of the figures that can be created. Here are a few examples (for more, see the [Workspace examples tutorial](WorkspaceExamples.ipynb)):" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "ws.MatrixPlot( np.array([[1,2],[3,4]],'d'), m=0, M=4 )" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "
\n", "
Gate Superoperator (Pauli-Product basis basis)
Gi
\n", "
\n", "
\n", "
\n", "\n", "
\n", "
Gx
\n", "
\n", "
\n", "
\n", "\n", "
\n", "
Gy
\n", "
\n", "
\n", "
\n", "\n", "
\n", "
\n", "
\n", "\n", "
\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from pygsti.construction import std1Q_XYI\n", "ws.GatesTable( std1Q_XYI.target_model() )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Thats covers the basics! The [Workspace examples tutorial](WorkspaceExamples.ipynb) shows a **gallery** of many of the tables and plots a `Workspace` can create, and the [Workspace switchboard tutorial](advanced/WorkspaceSwitchboards.ipynb) shows how to integrate workspace figures with *switches* (dropdown boxes, buttons, and sliders). `Workspace` objects are used internally when generating HTML reports. The [report generation tutorial](ReportGeneration.ipynb) demonstrates how the automated use of a `Workspace` can lead to a standalone HTML report." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.0" } }, "nbformat": 4, "nbformat_minor": 2 }