Skip to content

Commit

Permalink
Fix CI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
shab5 committed Oct 8, 2024
1 parent d5eca01 commit eb65f0e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
15 changes: 6 additions & 9 deletions dev_tools/autogenerate-bloqs-notebooks-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 -------------------------------------------------------
Expand Down
29 changes: 29 additions & 0 deletions dev_tools/qualtran_dev_tools/notebook_specs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions dev_tools/qualtran_dev_tools/parse_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dev_tools/ui-export.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit eb65f0e

Please sign in to comment.