Skip to content

Commit

Permalink
DX: freeze slowest TR notebooks (#21)
Browse files Browse the repository at this point in the history
* DOC: add more icons to navigation bar
* DX: add `pixi.lock` to `.gitignore`
* DX: detect doctests again in VS Code
* DX: export figures to ssubfolders
* DX: merge per-notebook Ruff rules
* DX: recommend VS Code extension for SVG
* FIX: install `mpl-interactions`
* FIX: wrap optional `pip` dependencies in quotation marks
  This is required for zsh

* MAINT: autoupdate Zotero bibliography file
* MAINT: remove `matplotlib` from notebook dependencies
* MAINT: use `plt.cm` instead of `cm`
  • Loading branch information
redeboer committed Oct 7, 2024
1 parent 3742aa5 commit b9eafc2
Show file tree
Hide file tree
Showing 32 changed files with 1,644 additions and 535 deletions.
2 changes: 2 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"ignoreWords": [
"Kutschke",
"Marangotto",
"PINF",
"PYTHONHASHSEED",
"Richman",
"absl",
Expand Down Expand Up @@ -205,6 +206,7 @@
"maxsize",
"meshgrid",
"migrad",
"mkpath",
"mmikhasenko",
"mname",
"msigma",
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ oryx-build-commands.txt
prof/

# Virtual environments
*venv/
.pixi/
.tox/
*venv/
pixi.lock
pyvenv*/

# Settings
Expand Down
13 changes: 12 additions & 1 deletion .pre-commit/pin_nb_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def _format_pip_requirements(
git_requirements = {r for r in requirements if r.startswith("git+")}
pip_requirements = set(requirements) - git_requirements
pip_requirements = {r.lower().replace("_", "-") for r in pip_requirements}
sorted_requirements = sorted(pip_requirements) + sorted(git_requirements)
pip_requirements = [__wrap_quotation_marks(r) for r in pip_requirements]
sorted_requirements = sorted(pip_requirements, key=__key) + sorted(git_requirements)
expected = f"{__EXPECTED_PIP_INSTALL_LINE} {' '.join(sorted_requirements)}"
if install_statement != expected:
notebook["cells"][cell_id]["source"] = expected
Expand All @@ -177,6 +178,16 @@ def _format_pip_requirements(
raise PrecommitError(msg)


def __wrap_quotation_marks(requirement: str) -> str:
if "[" in requirement and not requirement.startswith("'"):
return f"'{requirement}'"
return requirement


def __key(requirement: str) -> str:
return requirement.replace("'", "", 1).lower()


def _update_metadata(filename: str, metadata: dict, notebook: NotebookNode) -> None:
updated_metadata = False
jupyter_metadata = metadata.get("jupyter")
Expand Down
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ms-vscode.live-server",
"ms-vsliveshare.vsliveshare",
"redhat.vscode-yaml",
"simonsiefke.svg-preview",
"soulcode.vscode-unwanted-extensions",
"stkb.rewrap",
"streetsidesoftware.code-spell-checker",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"notebook.gotoSymbols.showAllSymbols": true,
"python.analysis.autoImportCompletions": false,
"python.terminal.activateEnvironment": false,
"python.testing.pytestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"redhat.telemetry.enabled": false,
"rewrap.wrappingColumn": 88,
"ruff.enable": true,
Expand Down
2 changes: 1 addition & 1 deletion docs/001.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"outputs": [],
"source": [
"%pip install -q black==21.5b2 jax==0.4.28 jaxlib==0.4.28 matplotlib==3.4.2 numpy==1.26.4 sympy==1.8"
"%pip install -q black==21.5b2 jax==0.4.28 jaxlib==0.4.28 numpy~=1.26.4 sympy==1.8"
]
},
{
Expand Down
27 changes: 20 additions & 7 deletions docs/002.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"outputs": [],
"source": [
"%pip install -q ampform==0.9.1 numpy==1.19.5 pandas==1.2.4 qrules==0.8.2 sympy==1.8 tensorwaves[jax]==0.2.9 git+https://github.com/zfit/phasespace@7131fbd"
"%pip install -q ampform==0.9.1 numpy==1.19.5 pandas==1.2.4 qrules==0.8.2 sympy==1.8 'tensorwaves[jax]==0.2.9' git+https://github.com/zfit/phasespace@7131fbd"
]
},
{
Expand All @@ -77,6 +77,7 @@
"import timeit\n",
"import warnings\n",
"from collections.abc import Generator, Sequence\n",
"from pathlib import Path\n",
"from typing import Callable\n",
"\n",
"import ampform\n",
Expand Down Expand Up @@ -156,7 +157,9 @@
},
"outputs": [],
"source": [
"graphviz.Source(dot).render(\"002-f0(980)-graph\", format=\"svg\");"
"output_file = Path(\"002/f0(980)-graph\")\n",
"output_file.parent.mkdir(exist_ok=True)\n",
"graphviz.Source(dot).render(output_file, format=\"svg\");"
]
},
{
Expand Down Expand Up @@ -373,7 +376,9 @@
},
"outputs": [],
"source": [
"graphviz.Source(dot).render(\"002-collapsed-expression-tree\", format=\"svg\");"
"output_file = Path(\"002/collapsed-expression-tree\")\n",
"output_file.parent.mkdir(exist_ok=True)\n",
"graphviz.Source(dot).render(output_file, format=\"svg\");"
]
},
{
Expand Down Expand Up @@ -438,7 +443,9 @@
},
"outputs": [],
"source": [
"graphviz.Source(dot).render(\"002-simple-expression-tree\", format=\"svg\");"
"output_file = Path(\"002/simple-expression-tree\")\n",
"output_file.parent.mkdir(exist_ok=True)\n",
"graphviz.Source(dot).render(output_file, format=\"svg\");"
]
},
{
Expand Down Expand Up @@ -850,7 +857,9 @@
},
"outputs": [],
"source": [
"fig.savefig(\"002-histogram-m12.svg\");"
"output_file = Path(\"002/histogram-m12.svg\")\n",
"output_file.parent.mkdir(exist_ok=True)\n",
"fig.savefig(output_file);"
]
},
{
Expand Down Expand Up @@ -1381,7 +1390,9 @@
},
"outputs": [],
"source": [
"fig.savefig(\"002-runtime-vs-operations.svg\");"
"output_file = Path(\"002/runtime-vs-operations.svg\")\n",
"output_file.parent.mkdir(exist_ok=True)\n",
"fig.savefig(output_file);"
]
},
{
Expand Down Expand Up @@ -1856,7 +1867,9 @@
},
"outputs": [],
"source": [
"graphviz.Source(dot).render(\"002-f0-graph\", format=\"svg\");"
"output_file = Path(\"002/f0-graph\")\n",
"output_file.parent.mkdir(exist_ok=True)\n",
"graphviz.Source(dot).render(output_file, format=\"svg\");"
]
},
{
Expand Down
Loading

0 comments on commit b9eafc2

Please sign in to comment.