Skip to content

Commit cfd7ab6

Browse files
authored
More sphinx docs (#65)
* Allow sphinx building of docs The primary mechanism will be the `docs/` folder and associated tensorflow-like build system. However, for the interim we'll support building with sphinx since there's little overhead. In particular, sphinx will copy files from `docs/` to `dev_tools/docs/sphinx`. This PR also makes the following changes: - change copyright notice to bold from `<h6>`. `nbsphinx` was getting confused. - only install `recirq` in the notebook if it's not already installed. It's not nice to overwrite a user's environment! * Fix notebook dependency code * Intercept header at the source * conf.py imports to the top * Build the rest of stuff using Sphinx * Rest of the notebooks - optional recirq installation - save outputs (for now) in long-running notebooks * re-run nbfomt; remove private_outputs
1 parent bf53bef commit cfd7ab6

File tree

9 files changed

+1398
-82
lines changed

9 files changed

+1398
-82
lines changed

dev_tools/docs/sphinx/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
tutorials/
2+
qaoa/*.ipynb
3+
qaoa/images
4+
25
_static/g3618.png
36
_static/recirq_logo_notext.png
7+
best_practices.md
8+
data_collection_idioms.md

dev_tools/docs/sphinx/conf.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
'sphinx.ext.mathjax',
2626
'sphinx.ext.autodoc',
2727
'sphinx.ext.autosummary',
28-
'sphinx.ext.napoleon'
28+
'sphinx.ext.napoleon',
29+
'recommonmark',
2930
]
3031

3132
nbsphinx_allow_errors = False
@@ -107,7 +108,7 @@ def _order(docname):
107108
# must come before others
108109
return -1
109110

110-
if docname == 'qaoa/Tasks-Tutorial':
111+
if docname == 'qaoa/tasks':
111112
# must come before others
112113
return -1
113114
return 0
@@ -123,13 +124,13 @@ def _order(docname):
123124
"also re-running tutorials/data_analysis")
124125
docnames.append('tutorials/data_analysis')
125126

126-
if 'qaoa/Tasks-Tutorial' in docnames:
127-
if 'qaoa/Precomputed-Analysis' not in docnames:
127+
if 'qaoa/tasks' in docnames:
128+
if 'qaoa/precomputed_analysis' not in docnames:
128129
# Mark the analysis notebook as changed
129-
docnames.append('qaoa/Precomputed-Analysis')
130-
if 'qaoa/Landscape-Analysis' not in docnames:
130+
docnames.append('qaoa/precomputed_analysis')
131+
if 'qaoa/landscape_analysis' not in docnames:
131132
# Mark the analysis notebook as changed
132-
docnames.append('qaoa/Landscape-Analysis')
133+
docnames.append('qaoa/landscape_analysis')
133134

134135
print(docnames)
135136

@@ -139,7 +140,7 @@ def _order(docname):
139140
from recirq.readout_scan import tasks as rs_tasks
140141
_rmtree_if_exists(f'{rs_tasks.DEFAULT_BASE_DIR}/2020-02-tutorial')
141142

142-
if 'qaoa/Tasks-Tutorial' in docnames and nbsphinx_execute == 'always':
143+
if 'qaoa/tasks' in docnames and nbsphinx_execute == 'always':
143144
# Clear data that's already been collected, but only if we're actually
144145
# executing this notebook. This notebook is saved pre-executed, so
145146
# set environment variable NBSPHINX_EXECUTE_NOTEBOOKS to 'auto' to
@@ -166,10 +167,15 @@ def source_read(app, docname, source):
166167
def setup(app):
167168
FROM = f'{REPO_DIR}/docs'
168169
TO = f'{REPO_DIR}/dev_tools/docs/sphinx'
169-
from distutils.dir_util import copy_tree # allows overwriting
170-
copy_tree(f'{FROM}/tutorials', f'{TO}/tutorials')
171170
shutil.copy(f'{FROM}/images/g3618.png', f'{TO}/_static/')
172171
shutil.copy(f'{FROM}/images/recirq_logo_notext.png', f'{TO}/_static/')
173172

173+
shutil.copy(f'{FROM}/data_collection_idioms.md', f'{TO}/')
174+
shutil.copy(f'{FROM}/best_practices.md', f'{TO}/')
175+
176+
from distutils.dir_util import copy_tree # allows overwriting
177+
copy_tree(f'{FROM}/tutorials', f'{TO}/tutorials')
178+
copy_tree(f'{FROM}/qaoa', f'{TO}/qaoa')
179+
174180
app.connect('env-before-read-docs', env_before_read_docs)
175181
app.connect('source-read', source_read)

dev_tools/docs/sphinx/index.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ navigation.
4242
:caption: QAOA
4343
:hidden:
4444

45-
qaoa/Example-Problems
46-
qaoa/Tasks-Tutorial
47-
qaoa/Precomputed-Analysis
48-
qaoa/Landscape-Analysis
49-
qaoa/hardware-grid-qaoa-circuits
45+
qaoa/example_problems
46+
qaoa/tasks
47+
qaoa/precomputed_analysis
48+
qaoa/landscape_analysis
49+
qaoa/hardware_grid_circuits
5050
qaoa/problem_generation_tasks
5151
qaoa/angle_precomputation_tasks
52-
qaoa/Routing-with-Tket
52+
qaoa/routing_with_tket

docs/qaoa/example_problems.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@
132132
},
133133
"outputs": [],
134134
"source": [
135-
"!pip install git+https://github.com/quantumlib/ReCirq"
135+
"try:\n",
136+
" import recirq\n",
137+
"except ImportError:\n",
138+
" !pip install git+https://github.com/quantumlib/ReCirq"
136139
]
137140
},
138141
{
@@ -311,13 +314,11 @@
311314
"metadata": {
312315
"colab": {
313316
"name": "example_problems.ipynb",
314-
"private_outputs": true,
315317
"provenance": [],
316318
"toc_visible": true
317319
},
318320
"kernelspec": {
319321
"display_name": "Python 3",
320-
"language": "python",
321322
"name": "python3"
322323
}
323324
},

docs/qaoa/hardware_grid_circuits.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@
9999
},
100100
"outputs": [],
101101
"source": [
102-
"!pip install git+https://github.com/quantumlib/ReCirq"
102+
"try:\n",
103+
" import recirq\n",
104+
"except ImportError:\n",
105+
" !pip install git+https://github.com/quantumlib/ReCirq"
103106
]
104107
},
105108
{
@@ -766,13 +769,11 @@
766769
"metadata": {
767770
"colab": {
768771
"name": "hardware_grid_circuits.ipynb",
769-
"private_outputs": true,
770772
"provenance": [],
771773
"toc_visible": true
772774
},
773775
"kernelspec": {
774776
"display_name": "Python 3",
775-
"language": "python",
776777
"name": "python3"
777778
}
778779
},

0 commit comments

Comments
 (0)