Advanced Report Creation

Pygsti can now create jupyter notebooks from python, using a custom Notebook object, which has convenience methods built around a json representation of a jupyter notebook.

Hello World

The simplest functions for manipulating the Notebook object are add_markdown and add_code, which can be used to put python strings into notebook cells:

In [1]:
from import Notebook
from  import timed_block

with timed_block('Hello world notebook creation and launch'):
    nb = Notebook()
# Hello World Notebook
This notebook prints "Hello, World":''')
    nb.add_code('''print('Hello, World')''')
Launching notebook, assuming port=8888
Hello world notebook creation and launch took 0.005967 seconds

File loading

However, hard-coding strings in python can be a pain, especially as the size of the report increases.
Also, docstrings are easily messed up by indentation (see cell above).
To get around this, code and markdown can also be loaded from file. For the purposes of this tutorial, two files have been created in this directory: and

In [2]:
with timed_block('Simple notebook file loading'):
    nb = Notebook()
Launching notebook, assuming port=8888
Simple notebook file loading took 0.008859 seconds

Advanced File Loading

Notebook objects can also load formatted text, or other notebooks. "Formatted text" is a file that contains both python code and markdown, separated by the special tags "@@code" and "@@markdown"

In [3]:
with timed_block('Advanced file loading'):
    nb = Notebook()
Launching notebook, assuming port=8888
Advanced file loading took 0.010221 seconds

Full Advanced Report Creation

Below, we create a full pygsti advanced report, mimicking the existing create_general_report webpage

In [4]:
import time

with timed_block('Full Advanced Report'):
    nb = Notebook()
    nb.add_markdown('# Pygsti report\n(Created on {})'.format(time.strftime("%B %d, %Y")))
Launching notebook, assuming port=8888
Full Advanced Report took 0.018344 seconds

In [ ]: