From faebd5187d2e7cda5b08d951845711c322e53f66 Mon Sep 17 00:00:00 2001 From: Isaac Miller Date: Thu, 24 Oct 2024 00:26:10 +0000 Subject: [PATCH] Add clear_cell_nums --- templates/e2e-dspy-workflow/README.ipynb | 89 ++++++++++--------- templates/e2e-dspy-workflow/README.md | 1 + .../e2e-dspy-workflow/src/clear_cell_nums.py | 23 +++++ 3 files changed, 69 insertions(+), 44 deletions(-) create mode 100644 templates/e2e-dspy-workflow/src/clear_cell_nums.py diff --git a/templates/e2e-dspy-workflow/README.ipynb b/templates/e2e-dspy-workflow/README.ipynb index e2527f28d..b0a4ce1a9 100644 --- a/templates/e2e-dspy-workflow/README.ipynb +++ b/templates/e2e-dspy-workflow/README.ipynb @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -97,7 +97,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -133,7 +133,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -161,7 +161,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -183,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -222,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -259,7 +259,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -302,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -328,7 +328,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -352,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -378,7 +378,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -587,7 +587,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -622,7 +622,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -683,7 +683,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -806,7 +806,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -839,7 +839,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -881,7 +881,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1008,7 +1008,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1256,7 +1256,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1286,7 +1286,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1313,7 +1313,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1326,7 +1326,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1391,7 +1391,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1415,7 +1415,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1463,7 +1463,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1485,7 +1485,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1520,7 +1520,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1561,7 +1561,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1583,7 +1583,7 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1603,7 +1603,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1675,7 +1675,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -1697,7 +1697,7 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1882,7 +1882,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1958,7 +1958,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -1983,7 +1983,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -2020,7 +2020,7 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -2081,7 +2081,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -2119,7 +2119,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -2138,7 +2138,7 @@ }, { "cell_type": "code", - "execution_count": 90, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -2172,7 +2172,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -2183,7 +2183,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -2212,7 +2212,7 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -2222,7 +2222,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -2259,11 +2259,12 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Clean up\n", + "!python src/clear_cell_nums.py\n", "!find . | grep -E \".ipynb_checkpoints\" | xargs rm -rf\n", "!find . | grep -E \"(__pycache__|\\.pyc|\\.pyo)\" | xargs rm -rf\n", "!rm -rf __pycache__ dspy" diff --git a/templates/e2e-dspy-workflow/README.md b/templates/e2e-dspy-workflow/README.md index d6c05f89c..4ca2f786d 100644 --- a/templates/e2e-dspy-workflow/README.md +++ b/templates/e2e-dspy-workflow/README.md @@ -1326,6 +1326,7 @@ else: ```python # Clean up +!python src/clear_cell_nums.py !find . | grep -E ".ipynb_checkpoints" | xargs rm -rf !find . | grep -E "(__pycache__|\.pyc|\.pyo)" | xargs rm -rf !rm -rf __pycache__ dspy diff --git a/templates/e2e-dspy-workflow/src/clear_cell_nums.py b/templates/e2e-dspy-workflow/src/clear_cell_nums.py new file mode 100644 index 000000000..e7147d82e --- /dev/null +++ b/templates/e2e-dspy-workflow/src/clear_cell_nums.py @@ -0,0 +1,23 @@ +from pathlib import Path + +import nbformat + + +def clear_execution_numbers(nb_path): + with open(nb_path, "r", encoding="utf-8") as f: + nb = nbformat.read(f, as_version=4) + for cell in nb["cells"]: + if cell["cell_type"] == "code": + cell["execution_count"] = None + for output in cell["outputs"]: + if "execution_count" in output: + output["execution_count"] = None + with open(nb_path, "w", encoding="utf-8") as f: + nbformat.write(nb, f) + + +if __name__ == "__main__": + ROOT_DIR = Path(__file__).parent.parent + notebook_fps = list(ROOT_DIR.glob("**/*.ipynb")) + for fp in notebook_fps: + clear_execution_numbers(fp)