-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
228 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
artifacts | ||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
jupyterlab | ||
papermill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
from pathlib import Path | ||
import logging | ||
import papermill | ||
from papermill.log import logger | ||
from papermill.engines import NBClientEngine, papermill_engines, NotebookExecutionManager, PapermillNotebookClient | ||
from papermill.utils import merge_kwargs, remove_args | ||
from nbconvert import HTMLExporter | ||
|
||
logging.basicConfig(level=logging.INFO, format="%(message)s") | ||
logger.setLevel(logging.INFO) | ||
|
||
class HTMLExecutionManager(NotebookExecutionManager): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.html_exporter = HTMLExporter() | ||
self.html_output_path = Path(self.output_path).with_suffix(".html") | ||
|
||
def save(self, **kwargs): | ||
super().save(**kwargs) | ||
html_output, _ = self.html_exporter.from_notebook_node(self.nb) | ||
with self.html_output_path.open("w", encoding ="utf-8") as f: | ||
f.write(html_output) | ||
|
||
class HTMLEngine(NBClientEngine): | ||
@classmethod | ||
def execute_notebook( | ||
cls, | ||
nb, | ||
kernel_name, | ||
output_path=None, | ||
progress_bar=True, | ||
log_output=False, | ||
autosave_cell_every=5, | ||
**kwargs, | ||
): | ||
""" | ||
A wrapper to handle notebook execution tasks. | ||
Wraps the notebook object in a `NotebookExecutionManager` in order to track | ||
execution state in a uniform manner. This is meant to help simplify | ||
engine implementations. This allows a developer to just focus on | ||
iterating and executing the cell contents. | ||
""" | ||
nb_man = HTMLExecutionManager( | ||
nb, | ||
output_path=output_path, | ||
progress_bar=progress_bar, | ||
log_output=log_output, | ||
autosave_cell_every=autosave_cell_every, | ||
) | ||
|
||
nb_man.notebook_start() | ||
try: | ||
cls.execute_managed_notebook(nb_man, kernel_name, log_output=log_output, **kwargs) | ||
finally: | ||
nb_man.cleanup_pbar() | ||
nb_man.notebook_complete() | ||
|
||
return nb_man.nb | ||
|
||
|
||
papermill_engines.register('htmlengine', HTMLEngine) | ||
papermill_engines.register_entry_points() | ||
|
||
|
||
# Execute the notebook with papermill as usual | ||
papermill.execute_notebook( | ||
sys.argv[1], | ||
sys.argv[2], | ||
log_output=True, | ||
engine_name="htmlengine", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
if [[ -z "$NOTEBOOK" ]]; then | ||
for nb in /content/*.ipynb; do | ||
[ -e "$nb" ] || continue | ||
echo "Executing notebook $nb" | ||
run-notebook.py "$nb" "/content/artifacts/$(basename ${nb})" | ||
# jupyter nbconvert --to html /content/artifacts/$(basename "$nb") | ||
done | ||
for nb in /content/src/*.ipynb; do | ||
[ -e "$nb" ] || continue | ||
mkdir -p /content/artifacts/src | ||
echo "Executing notebook $nb" | ||
run-notebook.py "$nb" "/content/artifacts/src/$(basename ${nb})" | ||
# jupyter nbconvert --to html /content/artifacts//src/$(basename "$nb") | ||
done | ||
else | ||
for nb in $NOTEBOOK; do | ||
[ -e "$nb" ] || continue | ||
echo "Executing notebook $nb" | ||
run-notebook.py "$nb" "/content/artifacts/$(basename ${nb})" | ||
# jupyter nbconvert --to html /content/artifacts/$(basename "$nb") | ||
done | ||
fi |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"print(\"test\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"testing a notebook 0\n", | ||
"testing a notebook 1\n", | ||
"testing a notebook 2\n", | ||
"testing a notebook 3\n" | ||
] | ||
}, | ||
{ | ||
"ename": "KeyboardInterrupt", | ||
"evalue": "", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[0;32mIn[1], line 5\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39m1000\u001b[39m):\n\u001b[1;32m 4\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mtesting a notebook \u001b[39m\u001b[39m{\u001b[39;00mi\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m)\n\u001b[0;32m----> 5\u001b[0m time\u001b[39m.\u001b[39;49msleep(\u001b[39m1.0\u001b[39;49m)\n", | ||
"\u001b[0;31mKeyboardInterrupt\u001b[0m: " | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import time\n", | ||
"\n", | ||
"for i in range(10):\n", | ||
" print(f\"testing a notebook {i}\")\n", | ||
" time.sleep(1.0)\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.3" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
ARG BASE_IMAGE=substratusai/base:latest | ||
FROM ${BASE_IMAGE} | ||
|
||
|
||
RUN mkdir -p /content/src /content/data | ||
WORKDIR /content | ||
|
||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
ENV PATH="$PATH:/content/bin" | ||
|
||
# Copy in build dependencies only since the build will take a while. | ||
COPY ./scripts/ ./scripts | ||
COPY ./src/ ./src | ||
|
||
CMD load.sh | ||
COPY load.ipynb . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.