Utilities for Jupyter notebooks (tomographer.jpyutil)

Utilities for Jupyter notebooks.

Note that the utilities here have simple fallbacks to make them also work outside of Jupyter notebooks. For example, a SimpleProgressBar would display a graphical progress bar inside a Jupyter notebook, but inside a python script executed on the console, it would simply print out progress information using print(...).

class tomographer.jpyutil.SimpleProgressBar(label_msg_html='Progress: ', displaybox=True)

Bases: tomographer.jpyutil._SimpleProgressBar_ConsoleImpl

A simple progress bar implementation, to be used in a Python with statement:

with SimpleProgressBar("Working very hard ... ") as prg:
    for i in range(10000):
        prg.progress(fraction_done=i/10000.0)
        # do stuff that takes time
        ...

This class works both inside a Jupyter notebook, providing a nice graphical progress bar, as well as in any other context such as a simple python console script, in which case information is simply displayed in the terminal using print(…).

In addition, it is possible to display additional information to simply the fraction done. You can do this by specifying the argument add_info to the progress() callback. Inside a Jupyter notebook, the information is displayed below the progress bar and is constantly updated at each call of progress(). In the console version, the information is simply displayed each time using print(...).

Note: When we are inside a Jupyter notebook, there is an additional attribute which is exposed called addinfo. It is an IPython.display.HTML widget which serves to display the additional info. By testing for this attribute you can display custom stuff in there, e.g. a final report after the work has finished.

progress(fraction_done[, add_info=None])

The callback function to update the progress bar (or to display new information on the console).

Parameters:
  • fraction_done – is the fraction of the job done, a real number between zero and one.
  • add_info – any additional information (formatted as plain text) which should be displayed alongside the progress bar. If None (or not specified), then no additional information is displayed.
class tomographer.jpyutil.RandWalkProgressBar(label_msg_html='Random Walk Progress: ')

Bases: tomographer.jpyutil.SimpleProgressBar

A progress bar suitable for displaying the status of random walk tasks (as for tomographer.tomorun.tomorun(), for example).

This class automatically provides a callback function progress_fn() which accepts a tomographer.multiproc.FullStatusReport, and is capable of displaying meaningful additional information alongside the progress bar. The callback progress_fn() is suitable to be specified directly to, e.g., tomographer.tomorun.tomorun().

Example:

result = None
with RandWalkProgressBar() as prg:
    result = tomographer.tomorun.tomorun(..., progress_fn=prg.progress_fn)
    prg.displayFinalInfo(result['final_report_runs'])

This class works both inside a Jupyter notebook as well as in other contexts such as a console for a simple Python script.

Note

The callback method which should be called regularly is progress_fn(), and not progress().

displayFinalInfo(report_str)

Display some text in the “additional information” area of the progress bar.

This is useful if you want to display some final report after the random walks have completed.

This method works both within a Jupyter notebook as well as in a console.

progress(*args, **kwargs)

Do not call this method. It will raise a RuntimeError.

progress_fn(report)

Update the progress bar and additional info to display the current status of the random walk specified in report, provided as a FullStatusReport object.

This method is suitable to be specified as a callback to, e.g., tomographer.tomorun.tomorun().