pygsti.report.notebook

Defines the Notebook class

Module Contents

Classes

Notebook

Python representation of an IPython notebook

class pygsti.report.notebook.Notebook(cells=None, notebook_text_files=None)

Bases: object

Python representation of an IPython notebook

Parameters

cellslist, optional

List of NotebookCell objects.

notebook_text_fileslist, optional

List of filenames (text files with ‘@@markdown’ or ‘@@code’ designating cells).

Attributes

DefaultTemplatestr

The default template notebook to use (a .ipynb file).

Create an IPython notebook from a list of cells, list of notebook_text_files, or both.

Parameters

cellslist, optional

List of NotebookCell objects

notebook_text_fileslist, optional

List of filenames (text files with ‘@@markdown’ or ‘@@code’ designating cells)

DefaultTemplate = "'Empty.ipynb'"
to_json_dict(template_filename=DefaultTemplate)

Using an existing (usually empty) notebook as a template, generate the json for a new notebook.

Parameters
template_filenamestr, optional

Name of an existing notebook file to build from

Returns

dict

save_to(output_filename, template_filename=DefaultTemplate)

Save this class to a file as a jupyter notebook

Parameters
output_filenamestr

File to save the output jupyter notebook to

template_filenamestr, optional

Name of an existing notebook file to build from

Returns

None

add(cell)

Add a cell to the notebook

Parameters
cellNotebookCell object

Cell to add.

Returns

None

add_block(block, cell_type)

Add a block to the notebook

Parameters
blockstr

block of either code or markdown

cell_typestr

tag for the cell. Either ‘code’ or ‘markdown’

Returns

None

add_file(filename, cell_type)

Read in a cell block from a file

Parameters
filenamestr

filename containing either code or markdown

cell_typestr

tag for the cell. Either ‘code’ or ‘markdown’

Returns

None

add_code(block)

Add code to notebook

Parameters
blockstr

Block of python code

Returns

None

add_markdown(block)

Add markdown to notebook

Parameters
blockstr

Block of markdown (or HTML)

Returns

None

add_code_file(filename)

Add a code file to the notebook

Parameters
filenamestr

name of file containing python code

Returns

None

add_markdown_file(filename)

Add a markdown file to the notebook

Parameters
filenamestr

name of file containing markdown

Returns

None

add_notebook_text(text)

Add custom formatted text to the notebook.

Text contains both python and markdown, with cells differentiated by @@code and @@markdown tags. At least one cell tag must be present for the file to be correctly parsed

Parameters
textstr

notebook formatted text

Returns

None

add_notebook_text_file(filename)

Add a custom formatted text file to the notebook.

Text file contains both python and markdown, with cells differentiated by @@code and @@markdown tags. At least one cell tag must be present for the file to be correctly parsed

Parameters
filenamestr

name of file containing notebook formatted text

Returns

None

add_notebook_text_files(filenames)

Add multiple notebook text files to the notebook, in order

Parameters
filenameslist(str)

names of file containing notebook formatted text

Returns

None

add_notebook_file(filename)

Append an .ipynb file to this notebook

Parameters
filenamestr

ipynb file to append

Returns

None

add_notebook_files(filenames)

Add multiple notebook files to the notebook, in order

Parameters
filenameslist(str)

names of file containing ipynb json

Returns

None

launch_new(output_filename, template_filename=DefaultTemplate)

Save and then launch this notebook with a new Jupyter server.

Note that this function waits to return until the notebook server exists, and so is difficult to work with.

Parameters
output_filenamestr

filename to save this notebook to

template_filenamestr, optional

filename to build this notebook from (see save_to)

Returns

None

launch(output_filename, template_filename=DefaultTemplate, port='auto')

Save and then launch this notebook

Parameters
output_filenamestr

filename to save this notebook to

template_filenamestr, optional

filename to build this notebook from (see save_to)

portint, optional

Port to launch server on.

Returns

None