stepup.notebook.api
Application programming interface for StepUp Notebook.
convert_jupyter(path_nb, dest=None, *, inp=(), out=(), step_info=None, execute=True, parameters=None, timeout=None, optional=False, resources=None, duration=None)
¶
Convert a Jupyter notebook, by default to HTML with execution of cells.
The cells are executed with the directory of the notebook as the current directory. When a cell raises an exception or exceeds the timeout, the step fails, but the output is still written, with the outputs up to that cell and the error. Output formats that cannot embed figures, such as Markdown and LaTeX, get them as separate files, which are declared as outputs automatically. See the usage page for examples and the location of these files.
Parameters:
-
path_nb(StrPath) –The input Jupyter notebook.
-
dest(StrPath | None, default:None) –Output destination:
None, a directory (with a trailing slash) or a file. The output is an HTML file, unlessdestis a file with extension.ipynb,.py,.md,.texor.pdf, which selects the output format. See Output Formats for a description of each format. -
inp(StrPath | Collection[StrPath], default:()) –One or more input files used by the notebook. You can also declare inputs with
amend(inp=...)in the notebook, but specifying them here will make the scheduling more efficient. -
out(StrPath | Collection[StrPath], default:()) –One or more output files produced by the notebook. You can also declare outputs with
amend(out=...)in the notebook, but you can specify them here if you want to make the notebook execution optional, i.e. dependent on whether the outputs are used in other steps. -
step_info(StrPath | None, default:None) –A JSON file to which all inputs and outputs of the step are written when the step succeeds, in the format of
dump_step_info()of StepUp Core. It includes the dependencies amended by the notebook, the local modules imported by the notebook, and the figures written to separate files for the Markdown and LaTeX formats. The file is an output of the step, but it does not list itself. Pass it tomake_inventory()of StepUp Data to archive these files, e.g. to share a notebook together with the data and modules it uses. -
execute(bool, default:True) –If
True, the notebook is executed before conversion. -
parameters(dict | None, default:None) –Arguments to pass to the notebook as a JSON-serializable dictionary, whose keys are valid Python identifiers and not keywords. NaN and infinity are not supported as values. The items are assigned in a new cell after the one tagged
parameters. Theparameterscell should contain the defaults, which may then be overridden by the values inparameters. When the notebook has no cell taggedparameters, the new cell is inserted at the top of the notebook and a warning is printed. -
timeout(int | None, default:None) –The timeout in seconds for the execution of a single cell.
0disables the timeout. Defaults to${STEPUP_NOTEBOOK_CELL_TIMEOUT}or no timeout if the variable is unset. ChangingSTEPUP_NOTEBOOK_CELL_TIMEOUTdoes not cause notebooks to be executed again. Cells taggedstepup-no-timeoutnever time out. Ignored whenexecuteisFalse. -
optional(bool, default:False) –If
True, the step is only executed when needed by other steps. -
resources(dict[str, int] | str | None, default:None) –Named resources required to run this step, e.g.
{"gpu": 1}. Seestepup.core.api.step()for details. -
duration(float | None, default:None) –An initial estimate of the step’s wall time in seconds. See
stepup.core.api.step()for details. This estimate is only used for scheduling and is unrelated totimeout.
Returns:
-
step_info–Holds relevant information of the step, useful for defining follow-up steps.
Source code in stepup/notebook/api.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |