notebook Module (stx.notebook)
SciTeX Notebook — Jupyter notebook verification and compilation.
Provides tools to verify, compile, convert, and check Jupyter notebooks for reproducibility using the Clew verification system.
Key Concept: Notebooks can be executed in any cell order. SciTeX records actual execution order via timestamps, then reconstructs the dependency DAG afterward (“do what you want, organize later”).
Examples
>>> from scitex_notebook import verify_notebook, compile_notebook
>>> results = verify_notebook("experiment.ipynb")
>>> compiled = compile_notebook("experiment.ipynb")
>>> print(compiled.to_mermaid()) # DAG visualization
>>> print(compiled.to_script()) # DAG-ordered .py
- scitex.notebook.get_notebook_name(path)[source]
Return the notebook stem name without extension.
- Return type:
- scitex.notebook.verify(path, *, db=None, verify_run_fn=None)
Verify all clew sessions associated with a notebook.
Finds all runs in the clew DB whose metadata contains this notebook’s path, then runs L1 (cache) verification on each.
- Parameters:
db (optional) – Pre-resolved clew DB handle. If omitted, the default DB from
scitex_clew.get_db()is used. Exposed for testability so tests can inject a hand-rolled fake without patching internals.verify_run_fn (optional) – Callable
(session_id) -> Verification. If omitted,scitex_clew.verify_runis used. Exposed for testability.
- Returns:
Verification results per session.
- Return type:
- scitex.notebook.check(path)
Find cells with scitex.io calls not wrapped in @scitex.session.
- scitex.notebook.compile(path, *, db=None)
Compile a notebook’s execution history into a DAG.
Queries the clew DB for all sessions associated with this notebook, sorts by timestamp, and builds a dependency DAG based on shared input/output files.
- Parameters:
- Returns:
Compiled execution history with DAG and execution order.
- Return type:
- scitex.notebook.convert(path, output=None, order='cell', mode='per_cell', *, db=None)
Convert a .ipynb notebook to a .py script with @stx.session.
- Parameters:
output (
Union[str,Path,None]) – Output .py file path. If None, returns string only.order (
str) – Cell ordering: “cell” (notebook order) or “dag” (execution order from clew DB timestamps).mode (
str) –Conversion mode:
”per_cell”: Each code cell becomes a separate @stx.session function (default).
”unified”: All cells merged into a single @stx.session main() function. Markdown cells become comments, imports are hoisted, and common notebook patterns (plt.show, pd.read_csv, etc.) are converted to SciTeX equivalents (stx.io.save/load).
db (optional) – Pre-resolved clew DB handle, used only when
order='dag'. Exposed for testability so tests can inject a hand-rolled fake without patching internals.
- Returns:
The generated Python script content.
- Return type: