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
  • cells (list, optional) – List of NotebookCell objects.

  • notebook_text_files (list, optional) – List of filenames (text files with ‘@@markdown’ or ‘@@code’ designating cells).

DefaultTemplate

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

Type

str

DefaultTemplate = Empty.ipynb
to_json_dict(self, template_filename=DefaultTemplate)

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

Parameters

template_filename (str, optional) – Name of an existing notebook file to build from

Returns

dict

save_to(self, output_filename, template_filename=DefaultTemplate)

Save this class to a file as a jupyter notebook

Parameters
  • output_filename (str) – File to save the output jupyter notebook to

  • template_filename (str, optional) – Name of an existing notebook file to build from

Returns

None

add(self, cell)

Add a cell to the notebook

Parameters

cell (NotebookCell object) – Cell to add.

Returns

None

add_block(self, block, cell_type)

Add a block to the notebook

Parameters
  • block (str) – block of either code or markdown

  • cell_type (str) – tag for the cell. Either ‘code’ or ‘markdown’

Returns

None

add_file(self, filename, cell_type)

Read in a cell block from a file

Parameters
  • filename (str) – filename containing either code or markdown

  • cell_type (str) – tag for the cell. Either ‘code’ or ‘markdown’

Returns

None

add_code(self, block)

Add code to notebook

Parameters

block (str) – Block of python code

Returns

None

add_markdown(self, block)

Add markdown to notebook

Parameters

block (str) – Block of markdown (or HTML)

Returns

None

add_code_file(self, filename)

Add a code file to the notebook

Parameters

filename (str) – name of file containing python code

Returns

None

add_markdown_file(self, filename)

Add a markdown file to the notebook

Parameters

filename (str) – name of file containing markdown

Returns

None

add_notebook_text(self, 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

text (str) – notebook formatted text

Returns

None

add_notebook_text_file(self, 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

filename (str) – name of file containing notebook formatted text

Returns

None

add_notebook_text_files(self, filenames)

Add multiple notebook text files to the notebook, in order

Parameters

filenames (list(str)) – names of file containing notebook formatted text

Returns

None

add_notebook_file(self, filename)

Append an .ipynb file to this notebook

Parameters

filename (str) – ipynb file to append

Returns

None

add_notebook_files(self, filenames)

Add multiple notebook files to the notebook, in order

Parameters

filenames (list(str)) – names of file containing ipynb json

Returns

None

launch_new(self, 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_filename (str) – filename to save this notebook to

  • template_filename (str, optional) – filename to build this notebook from (see save_to)

Returns

None

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

Save and then launch this notebook

Parameters
  • output_filename (str) – filename to save this notebook to

  • template_filename (str, optional) – filename to build this notebook from (see save_to)

  • port (int, optional) – Port to launch server on.

Returns

None