Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation #598

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
470f1a2
improve doc
fzimmermann89 Jan 7, 2025
4398a11
update
fzimmermann89 Jan 7, 2025
f3a6e16
update
fzimmermann89 Jan 7, 2025
9f500fb
update
fzimmermann89 Jan 7, 2025
f1e5d1e
update
fzimmermann89 Jan 7, 2025
9d07935
update
fzimmermann89 Jan 8, 2025
466ab3c
update
fzimmermann89 Jan 8, 2025
3420fc6
update
fzimmermann89 Jan 8, 2025
e395218
example
fzimmermann89 Jan 8, 2025
e00b6a7
test
fzimmermann89 Jan 8, 2025
6606672
test
fzimmermann89 Jan 8, 2025
df51ecf
Notebooks updated
github-actions[bot] Jan 8, 2025
eab0395
update
fzimmermann89 Jan 9, 2025
f6f0502
Squashed commit of the following:
fzimmermann89 Jan 9, 2025
a92877b
update
fzimmermann89 Jan 8, 2025
47ad68e
update
fzimmermann89 Jan 10, 2025
31bf097
update
fzimmermann89 Jan 10, 2025
a72d095
Squashed commit of the following:
fzimmermann89 Jan 10, 2025
0af3338
update
fzimmermann89 Jan 10, 2025
a26a559
update
fzimmermann89 Jan 10, 2025
6a5ef6b
test
fzimmermann89 Jan 10, 2025
7a3cf18
update
fzimmermann89 Jan 10, 2025
cfb20b0
update
fzimmermann89 Jan 10, 2025
7caf514
test
fzimmermann89 Jan 10, 2025
e51b7c7
update
fzimmermann89 Jan 10, 2025
2571ae3
update
fzimmermann89 Jan 11, 2025
48e3125
fix
fzimmermann89 Jan 11, 2025
132637c
update
fzimmermann89 Jan 11, 2025
d4f7fb2
update
fzimmermann89 Jan 11, 2025
66a4d4e
update
fzimmermann89 Jan 12, 2025
7cc6587
Squashed commit of the following:
fzimmermann89 Jan 12, 2025
93ad440
fix
fzimmermann89 Jan 12, 2025
f94a177
update
fzimmermann89 Jan 12, 2025
5d21424
update
fzimmermann89 Jan 12, 2025
8453798
update
fzimmermann89 Jan 12, 2025
5311951
update
fzimmermann89 Jan 12, 2025
ba5b484
update
fzimmermann89 Jan 13, 2025
408022b
update
fzimmermann89 Jan 13, 2025
09c6b97
Merge branch 'main' into improvedoc
fzimmermann89 Jan 13, 2025
7684724
update
fzimmermann89 Jan 13, 2025
871cdd2
update
fzimmermann89 Jan 13, 2025
71943e0
update
fzimmermann89 Jan 13, 2025
433649e
update
fzimmermann89 Jan 13, 2025
df16dd9
update
fzimmermann89 Jan 13, 2025
929aa0d
update
fzimmermann89 Jan 13, 2025
3dbd1d6
update
fzimmermann89 Jan 13, 2025
54114aa
update
fzimmermann89 Jan 13, 2025
644cce9
update
fzimmermann89 Jan 13, 2025
4d497e7
update
fzimmermann89 Jan 13, 2025
688a55c
Apply suggestions from code review
fzimmermann89 Jan 14, 2025
457787c
rename
fzimmermann89 Jan 14, 2025
d0baf78
update
fzimmermann89 Jan 14, 2025
75b7633
svg instead of png
fzimmermann89 Jan 14, 2025
2156518
lint
fzimmermann89 Jan 14, 2025
ac37591
update
fzimmermann89 Jan 14, 2025
2b3faf1
update
fzimmermann89 Jan 14, 2025
337a514
update readme
fzimmermann89 Jan 14, 2025
e6ab0db
fix
fzimmermann89 Jan 14, 2025
b8907ca
fix
fzimmermann89 Jan 14, 2025
17b03ea
fix
fzimmermann89 Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 10 additions & 62 deletions .github/workflows/docs.yml
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes here are due to basing upon #537

Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,26 @@ defaults:
shell: bash

jobs:
convert_scripts:
name: Translate scripts to notebooks
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
outputs:
commit_hash: ${{ steps.add-commit-push.outputs.commit_hash }}
container:
image: ghcr.io/ptb-mr/mrpro_py311:latest
options: --user runner
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ secrets.commit }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0

- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[notebook]

- name: Translate scripts to notebooks
run: |
scripts=$(ls ./examples/*.py)
for script in $scripts
do jupytext --set-kernel "python3" --update --output ${script//.py/.ipynb} $script
done

- name: Check if any notebooks have been changed
uses: tj-actions/verify-changed-files@v20
id: verify-changed-notebooks
with:
files: ./examples/*.ipynb

- name: Commit notebooks
if: steps.verify-changed-notebooks.outputs.files_changed == 'true'
uses: actions4git/add-commit-push@v1
with:
commit-message: Notebooks updated

- name: Get hash of last commit
id: add-commit-push
run: echo "commit_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

get_notebooks:
name: Get list of notebooks
needs: convert_scripts
runs-on: ubuntu-latest
steps:
- name: Checkout mrpro repo
uses: actions/checkout@v4
with:
ref: ${{ needs.convert_scripts.outputs.commit_hash }}

- id: set-matrix
run: |
echo "notebooks=$(find examples -type f -name '*.ipynb' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
echo "notebook_paths=$(find examples/notebooks -type f -name '*.ipynb' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT

- name: Notebook overview
run: |
echo "jupyter-notebooks: ${{ steps.set-matrix.outputs.notebooks }}"
echo "jupyter-notebooks: ${{ steps.set-matrix.outputs.notebook_paths }}"
outputs:
notebooks: ${{ steps.set-matrix.outputs.notebooks }}
notebook_paths: ${{ steps.set-matrix.outputs.notebook_paths }}

run_notebook:
name: Run notebook
needs: [convert_scripts, get_notebooks]
needs: get_notebooks
runs-on: ubuntu-latest
permissions:
pull-requests: write
Expand All @@ -92,23 +44,21 @@ jobs:
strategy:
fail-fast: false
matrix:
notebook: ${{ fromJson(needs.get_notebooks.outputs.notebooks) }}
notebook_path: ${{ fromJson(needs.get_notebooks.outputs.notebook_paths) }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ needs.convert_scripts.outputs.commit_hash }}

- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[notebook]

- name: Notebook name
run: |
echo "current jupyter-notebook: ${{ matrix.notebook }}"
echo "current jupyter-notebook: ${{ matrix.notebook_path }}"

- name: Add nb-myst download badge
run: |
notebook=${{ matrix.notebook }}
notebook=${{ matrix.notebook_path }}
notebook_name=$(basename $notebook)
download_badge_md="[![Download notebook](https://img.shields.io/badge/Download-notebook-blue?logo=jupyter)](path:$notebook_name)"
python_command="import nbformat as nbf\n\
Expand All @@ -129,12 +79,12 @@ jobs:
env:
RUNNER: ${{ toJson(runner) }}
with:
notebook: ./${{ matrix.notebook }}
notebook: ${{ matrix.notebook_path }}

- name: Get artifact names
id: artifact_names
run: |
notebook=${{ matrix.notebook }}
notebook=${{ matrix.notebook_path }}
echo "ARTIFACT_NAME=$(basename ${notebook/.ipynb})" >> $GITHUB_OUTPUT
echo "IPYNB_EXECUTED=$(basename $notebook)" >> $GITHUB_OUTPUT

Expand All @@ -149,7 +99,7 @@ jobs:

create_documentation:
name: Build and deploy documentation
needs: [convert_scripts, run_notebook]
needs: run_notebook
runs-on: ubuntu-latest
container:
image: ghcr.io/ptb-mr/mrpro_py311:latest
Expand All @@ -160,8 +110,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.convert_scripts.outputs.commit_hash }}

- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[docs]
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ cython_debug/

# Documentation
**/_autosummary
**/_notebooks

# Ignore Conda environment directories:
.conda
Expand All @@ -192,3 +193,4 @@ cython_debug/
*~
*.swp
*.swo

63 changes: 63 additions & 0 deletions .pre-commit-config.yaml
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes here are due to basing upon #537

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,42 @@ repos:
args: [--double-quotes, --fix]
exclude: ^tests/

- repo: https://github.com/kynan/nbstripout
rev: 0.8.0
hooks:
# cleans the .ipynbs (removes outputs, resets all cell-ids to 0..N, cleans steps)
# also clean any kernel information left after execution
- id: nbstripout
name: clean .ipynb output
args: [--extra-keys, "metadata.language_info"]
files: examples/notebooks

- repo: local
hooks:
- id: jupytext
name: convert .py to .ipynb
language: python

additional_dependencies:
- jupytext
entry: >
jupytext
--update
--pipe
"python .precommit/add_notebook_preamble.py {}"
--to
"../notebooks//ipynb"
--update-metadata
'{
"accelerator": "GPU",
"colab": {"gpuType": "T4","provenance": []},
"kernelspec": {"display_name": "Python 3 (ipykernel)","language": "python","name": "python3"}
}'
always_run: true
pass_filenames: true
files: ^examples/scripts/.*py
types_or: [python]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
hooks:
Expand All @@ -52,6 +88,33 @@ repos:
- "--index-url=https://download.pytorch.org/whl/cpu"
- "--extra-index-url=https://pypi.python.org/simple"

- repo: https://github.com/kynan/nbstripout
rev: 0.8.0
hooks:
# cleans the .ipynbs (removes outputs, resets all cell-ids to 0..N, cleans steps)
# also clean any kernel information left after execution
- id: nbstripout
name: clean .ipynb output
args: [--extra-keys, "metadata.language_info"]
files: examples/notebooks

- repo: https://github.com/mwouts/jupytext
rev: v1.16.6
hooks:
- id: jupytext
name: convert .py to .ipynb
args:
- --update
- --pipe
- "python .precommit/add_notebook_preemble.py {}"
- --to
- "../notebooks//ipynb"
- --update-metadata
- '{"accelerator": "GPU","colab": {"gpuType": "T4","provenance": []},"kernelspec": {"display_name": "Python 3 (ipykernel)","language": "python","name": "python3"}}'
- examples/scripts/*.py
always_run: true
pass_filenames: false

ci:
autofix_commit_msg: |
[pre-commit] auto fixes from pre-commit hooks
Expand Down
36 changes: 36 additions & 0 deletions .precommit/add_notebook_preamble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Add a colab badge and pip install to notebooks."""

import sys
from pathlib import Path

# the filename is the name of temp file created by jupytext, not an original notebook
file = Path(sys.argv[1])
# the temp filename for "iteratitive_sense_reconstruction.py" is like "iterative_sense_reconstruction-42_5f4kv.py"
basename = file.stem.rpartition('-')[0]

badge_svg = 'https://colab.research.google.com/assets/colab-badge.svg'
ipynb_link = f'https://colab.research.google.com/github/PTB-MR/mrpro/blob/main/examples/notebooks/{basename}.ipynb'
badge_markdown = f'[![Open In Colab]({badge_svg})]({ipynb_link})'
badge_pyprocent = f'# %% [markdown]\n# {badge_markdown}\n'
import_python = """# %% tags=["remove-cell"]
import importlib

if not importlib.util.find_spec('mrpro'):
%pip install mrpro[notebook]
"""

# the temp files of jupytext have the header which looks like:
# ---
# jupyter:
# jupytext:
# multiple lines...
# ---
# we need to insert the #markdown cell after the header
# insert the badge_pyprocent string after the second occurrence of '# ---'
split_sequence = '# ---\n'
old = file.read_text()
split_text = old.split(split_sequence)
new = ''.join(
[split_text[0], split_sequence, split_text[1], split_sequence, badge_pyprocent, import_python, *split_text[2:]]
)
file.write_text(new)
1 change: 1 addition & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ help:
# be removed when https://github.com/sphinx-doc/sphinx/issues/1999 is fixed.
clean:
rm -rfv "$(SOURCEDIR)/_autosummary"
rm -rfv "$(SOURCEDIR)/_notebooks"
$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

# Catch-all target: route all unknown targets to Sphinx using the new
Expand Down
11 changes: 11 additions & 0 deletions docs/source/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ html {
.wy-nav-content {
max-width: 75% !important;
}

/* new line after each property */
dl.py.property {
display: block !important;
}

/* example notebooks outputs */
.output>.highlight {
background: #efefef !important;
color: inherit !important;
}
36 changes: 10 additions & 26 deletions docs/source/_static/logo_white.svg
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

white line removed. looks a bit cleaner in the docu

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions docs/source/_templates/class_template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

.. autoclass:: {{ objname }}
:members:
:special-members: '__init__, __matmul__, __add__, __mul__, __or__, __and__, __radd__, __rmul__, __rmatmul__, __ror__, __rand__, __truediv__, __eq__, __pow__'
:inherited-members: Module
:show-inheritance:

{% block methods %}
.. automethod:: __init__
{% endblock %}

Loading
Loading