diff --git a/dev_tools/autogenerate-bloqs-notebooks-v2.py b/dev_tools/autogenerate-bloqs-notebooks-v2.py index e77bee4d6..92e68c5ba 100644 --- a/dev_tools/autogenerate-bloqs-notebooks-v2.py +++ b/dev_tools/autogenerate-bloqs-notebooks-v2.py @@ -14,18 +14,15 @@ """Autogeneration of Jupyter notebooks. -For each notebook spec listed in the various global variables (in this file) -we write a notebook with a title, module docstring, -standard imports, and information on each bloq listed in the +For each notebook spec listed in the various global variables imported from +`qualtran_dev_tools.notebook_specs` we write a notebook with a title, module +docstring, standard imports, and information on each bloq listed in the `bloq_specs` field. For each bloq, we render a docstring and diagrams. ## Adding a new bloq. - 1. Create a qualtran.BloqExample perhaps using the `@bloq_example` decorator. Wrap it in a - `qualtran.BloqDocSpec`. This code should live alongside the bloq. - 2. If this is a new module: add a new entry to the appropriate notebook spec global variable - in this file (according to its category/organization). - 3. Update the `NotebookSpec` `bloq_specs` field to include the `BloqDocSpec` for your new bloq. +Follow the instructions in `dev_tools/qualtran_dev_tools/notebook_specs.py` to +add a new bloq. ## Autogen behavior. @@ -50,7 +47,7 @@ from qualtran_dev_tools.bloq_finder import get_bloqdocspecs from qualtran_dev_tools.jupyter_autogen import NotebookSpecV2, render_notebook -from qualtran_dev_tools.notebook_specs import GIT_ROOT, SOURCE_DIR, NB_BY_SECTION +from qualtran_dev_tools.notebook_specs import GIT_ROOT, NB_BY_SECTION, SOURCE_DIR # -------------------------------------------------------------------------- # ----- Concepts ------------------------------------------------------- diff --git a/dev_tools/qualtran_dev_tools/notebook_specs.py b/dev_tools/qualtran_dev_tools/notebook_specs.py index 442b7e499..f96b511e4 100644 --- a/dev_tools/qualtran_dev_tools/notebook_specs.py +++ b/dev_tools/qualtran_dev_tools/notebook_specs.py @@ -1,3 +1,32 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""List of Jupyter notebooks. + +The notebooks listed in this file are used to generate Jupyter notebooks that +document and provide examples for each of the bloqs. This list is also used to +generate the static exports for the Qualtran web UI. + +## Adding a new bloq. + + 1. Create a qualtran.BloqExample perhaps using the `@bloq_example` decorator. Wrap it in a + `qualtran.BloqDocSpec`. This code should live alongside the bloq. + 2. If this is a new module: add a new entry to the appropriate notebook spec global variable + in this file (according to its category/organization). + 3. Update the `NotebookSpec` `bloq_specs` field to include the `BloqDocSpec` for your new bloq. +""" + from typing import List from qualtran_dev_tools.git_tools import get_git_root diff --git a/dev_tools/qualtran_dev_tools/parse_docstrings.py b/dev_tools/qualtran_dev_tools/parse_docstrings.py index c30f9e2b1..36321bece 100644 --- a/dev_tools/qualtran_dev_tools/parse_docstrings.py +++ b/dev_tools/qualtran_dev_tools/parse_docstrings.py @@ -109,7 +109,7 @@ def _template(name, desc_lines): ] -def get_markdown_docstring_lines(cls: Type) -> List[str]: +def get_markdown_docstring(cls: Type) -> List[str]: """From a class `cls`, return its docstring as Markdown lines.""" # 1. Sphinx incantation @@ -123,11 +123,11 @@ def get_markdown_docstring_lines(cls: Type) -> List[str]: return lines -def get_markdown_docstring(cls: Type) -> List[str]: +def get_markdown_docstring_lines(cls: Type) -> List[str]: """From a class `cls`, return its docstring as Markdown lines with a header.""" # 1. Get documentation lines - lines = get_markdown_docstring_lines(cls) + lines = get_markdown_docstring(cls) # 2. Pre-pend a header. lines = [f'## `{cls.__name__}`'] + lines diff --git a/dev_tools/ui-export.ipynb b/dev_tools/ui-export.ipynb index 51aaa617c..c1d9d416f 100644 --- a/dev_tools/ui-export.ipynb +++ b/dev_tools/ui-export.ipynb @@ -117,7 +117,7 @@ "from pathlib import Path\n", "\n", "from qualtran_dev_tools.notebook_specs import NB_BY_SECTION\n", - "from qualtran_dev_tools.parse_docstrings import get_markdown_docstring_lines\n", + "from qualtran_dev_tools.parse_docstrings import get_markdown_docstring\n", "from qualtran.drawing.musical_score import get_musical_score_data\n", "\n", "def bloq_score(bloq):\n", @@ -137,7 +137,7 @@ " doc_name = f'ui_export/{bloq.__class__.__name__}/docs.txt'\n", " if not os.path.isfile(doc_name):\n", " with open(doc_name, 'w') as doc_file:\n", - " doc_file.write('\\n'.join(get_markdown_docstring_lines(bloq.__class__)))\n", + " doc_file.write('\\n'.join(get_markdown_docstring(bloq.__class__)))\n", "\n", " file_name = f'ui_export/{bloq.__class__.__name__}/{bloq_filename(bloq)}'\n", " if not os.path.isfile(file_name):\n",