Skip to content

Commit 3d22ba1

Browse files
Set up infrastructure for qiskit-tutorials migration (Qiskit#10443) (Qiskit#10625)
* Add infrastructure for building tutorials This first commit is a rebase of Eric's initial PR as of db1ce62 onto `main`, fixing up some changes caused by the CI infrastructure changing a bit since the PR was first opened. Co-authored-by: Jake Lishman <jake.lishman@ibm.com> * Harden tutorials Azure job This moves much of the fetch- and process-related code into separate scripts that assert far more about the directory structure, and fail if they do not match the assumptions. We don't want to accidentally get out-of-sync while we're changing things and end up with a tutorials job that isn't really doing its job without us noticing. The tutorials-fetching script can now also be re-used in a separate GitHub Actions workflow that will handle the full tutorials-included documentation build and deployment in the future. The notebook-convertion step is moved into Python space, using `nbconvert` as a library in order to parallelise the build process for the tutorials, and to allow CI and developers calling `tox` directly to specify the output directories for the built tutorials. * Retarget tutorial-conversion utility as executor This reorganises the tutorial "conversion" utility to make it clearer that what it's actually doing is just executing the tutorials. The script itself is changed to default to editing the files inplace, while the `tox` job is updated to write the files into a special directory, making it easier to clean up a dirty build directory and making it so subsequent local executions will not pick up the converted files. * Allow configuration of tutorials execution There was a worry that not being able to configure these would make it more unpleasant to use `tox` for the jobs locally. --------- Co-authored-by: Jake Lishman <jake.lishman@ibm.com> (cherry picked from commit df2ddca) Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
1 parent 04def33 commit 3d22ba1

15 files changed

Lines changed: 403 additions & 35 deletions

.azure/docs-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
python -m pip install --upgrade pip setuptools wheel
2525
python -m pip install -U "tox<4.4.0"
2626
sudo apt-get update
27-
sudo apt-get install -y graphviz
27+
sudo apt-get install -y graphviz pandoc
2828
displayName: 'Install dependencies'
2929
3030
- bash: |

.azure/tutorials-linux.yml

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ jobs:
88
pool: {vmImage: 'ubuntu-latest'}
99

1010
variables:
11-
QISKIT_SUPPRESS_PACKAGING_WARNINGS: Y
1211
PIP_CACHE_DIR: $(Pipeline.Workspace)/.pip
13-
QISKIT_CELL_TIMEOUT: 300
1412

1513
steps:
1614
- task: UsePythonVersion@0
@@ -20,40 +18,33 @@ jobs:
2018

2119
- bash: |
2220
set -e
23-
git clone https://github.com/Qiskit/qiskit-tutorials --depth=1
2421
python -m pip install --upgrade pip setuptools wheel
25-
python -m pip install -U \
26-
-c constraints.txt \
27-
-r requirements.txt \
28-
-r requirements-dev.txt \
29-
-r requirements-optional.txt \
30-
-r requirements-tutorials.txt \
31-
-e .
22+
python -m pip install -U "tox<4.4.0"
3223
sudo apt-get update
3324
sudo apt-get install -y graphviz pandoc
34-
pip check
3525
displayName: 'Install dependencies'
36-
env:
37-
SETUPTOOLS_ENABLE_FEATURES: "legacy-editable"
3826
39-
- bash: |
40-
set -e
41-
cd qiskit-tutorials
42-
sphinx-build -b html . _build/html
27+
- bash: tools/prepare_tutorials.bash algorithms circuits circuits_advanced operators
28+
displayName: 'Download current tutorials'
29+
30+
- bash: tox -e tutorials
31+
displayName: "Execute tutorials"
4332
env:
44-
QISKIT_PARALLEL: False
33+
QISKIT_CELL_TIMEOUT: 300
4534

4635
- task: ArchiveFiles@2
4736
inputs:
48-
rootFolderOrFile: 'qiskit-tutorials/_build/html'
37+
rootFolderOrFile: 'executed_tutorials'
4938
archiveType: tar
50-
archiveFile: '$(Build.ArtifactStagingDirectory)/html_tutorials.tar.gz'
39+
archiveFile: '$(Build.ArtifactStagingDirectory)/executed_tutorials.tar.gz'
5140
verbose: true
41+
condition: succeededOrFailed()
5242

5343
- task: PublishBuildArtifacts@1
54-
displayName: 'Publish docs'
44+
displayName: 'Publish updated tutorials'
5545
inputs:
5646
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
57-
artifactName: 'html_tutorials'
47+
artifactName: 'executed_tutorials'
5848
Parallel: true
5949
ParallelCount: 8
50+
condition: succeededOrFailed()

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ qiskit/transpiler/passes/**/cython/**/*.cpp
143143
qiskit/quantum_info/states/cython/*.cpp
144144

145145
docs/stubs/*
146+
executed_tutorials/
146147

147148
# Notebook testing images
148149
test/visual/mpl/circuit/circuit_results/*.png

docs/conf.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
"""Sphinx documentation builder."""
1616

17-
# -- General configuration ---------------------------------------------------
1817
import datetime
1918
import doctest
19+
import os
2020

2121
project = "Qiskit"
22-
copyright = f"2017-{datetime.date.today().year}, Qiskit Development Team" # pylint: disable=redefined-builtin
22+
project_copyright = f"2017-{datetime.date.today().year}, Qiskit Development Team"
2323
author = "Qiskit Development Team"
2424

2525
# The short X.Y version
@@ -39,7 +39,8 @@
3939
"reno.sphinxext",
4040
"sphinx_design",
4141
"matplotlib.sphinxext.plot_directive",
42-
"sphinx.ext.doctest",
42+
"qiskit_sphinx_theme",
43+
"nbsphinx",
4344
]
4445

4546
templates_path = ["_templates"]
@@ -77,7 +78,9 @@
7778
"matplotlib": ("https://matplotlib.org/stable/", None),
7879
}
7980

80-
# -- Options for HTML output -------------------------------------------------
81+
# ----------------------------------------------------------------------------------
82+
# HTML theme
83+
# ----------------------------------------------------------------------------------
8184

8285
html_theme = "qiskit_sphinx_theme"
8386
html_last_updated_fmt = "%Y/%m/%d"
@@ -88,8 +91,9 @@
8891
"style_external_links": True,
8992
}
9093

91-
92-
# -- Options for Autosummary and Autodoc -------------------------------------
94+
# ----------------------------------------------------------------------------------
95+
# Autodoc
96+
# ----------------------------------------------------------------------------------
9397

9498
# Note that setting autodoc defaults here may not have as much of an effect as you may expect; any
9599
# documentation created by autosummary uses a template file (in autosummary in the templates path),
@@ -131,7 +135,9 @@
131135
napoleon_numpy_docstring = False
132136

133137

134-
# -- Options for Doctest --------------------------------------------------------
138+
# ----------------------------------------------------------------------------------
139+
# Doctest
140+
# ----------------------------------------------------------------------------------
135141

136142
doctest_default_flags = (
137143
doctest.ELLIPSIS
@@ -145,3 +151,27 @@
145151
# >> code
146152
# output
147153
doctest_test_doctest_blocks = ""
154+
155+
# ----------------------------------------------------------------------------------
156+
# Nbsphinx
157+
# ----------------------------------------------------------------------------------
158+
159+
nbsphinx_timeout = int(os.getenv("QISKIT_CELL_TIMEOUT", "300"))
160+
nbsphinx_execute = os.getenv("QISKIT_DOCS_BUILD_TUTORIALS", "never")
161+
nbsphinx_widgets_path = ""
162+
nbsphinx_thumbnails = {"**": "_static/images/logo.png"}
163+
164+
nbsphinx_prolog = """
165+
{% set docname = env.doc2path(env.docname, base=None) %}
166+
167+
.. only:: html
168+
169+
.. role:: raw-html(raw)
170+
:format: html
171+
172+
.. note::
173+
This page was generated from `{{ docname }}`__.
174+
175+
__ https://github.com/Qiskit/qiskit-terra/blob/main/{{ docname }}
176+
177+
"""

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Qiskit Terra documentation
77
:hidden:
88

99
How-to Guides <how_to/index>
10+
tutorials
1011
API References <apidocs/terra>
1112
Explanation <explanation/index>
1213
Migration Guides <migration_guides/index>

docs/tutorials.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. _tutorials:
2+
3+
=========
4+
Tutorials
5+
=========
6+
7+
Quantum circuits
8+
================
9+
10+
.. nbgallery::
11+
:glob:
12+
13+
tutorials/circuits/*
14+
15+
Advanced circuits
16+
=================
17+
18+
.. nbgallery::
19+
:glob:
20+
21+
tutorials/circuits_advanced/*
22+
23+
Algorithms
24+
==========
25+
26+
.. nbgallery::
27+
:glob:
28+
29+
tutorials/algorithms/*
30+
31+
Operators
32+
=========
33+
34+
.. nbgallery::
35+
:glob:
36+
37+
tutorials/operators/*
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Placeholder",
8+
"\n",
9+
"This is only here to test the infrastructure for tutorials. It will be removed with our actual tutorials from qiskit-tutorials once finishing the metapackage migration."
10+
]
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 3",
16+
"language": "python",
17+
"name": "python3"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 3
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython3",
29+
"version": "3.9.16"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 4
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Placeholder",
8+
"\n",
9+
"This is only here to test the infrastructure for tutorials. It will be removed with our actual tutorials from qiskit-tutorials once finishing the metapackage migration."
10+
]
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 3",
16+
"language": "python",
17+
"name": "python3"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 3
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython3",
29+
"version": "3.9.16"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 4
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Placeholder",
8+
"\n",
9+
"This is only here to test the infrastructure for tutorials. It will be removed with our actual tutorials from qiskit-tutorials once finishing the metapackage migration."
10+
]
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 3",
16+
"language": "python",
17+
"name": "python3"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 3
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython3",
29+
"version": "3.9.16"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 4
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Placeholder",
8+
"\n",
9+
"This is only here to test the infrastructure for tutorials. It will be removed with our actual tutorials from qiskit-tutorials once finishing the metapackage migration."
10+
]
11+
}
12+
],
13+
"metadata": {
14+
"kernelspec": {
15+
"display_name": "Python 3",
16+
"language": "python",
17+
"name": "python3"
18+
},
19+
"language_info": {
20+
"codemirror_mode": {
21+
"name": "ipython",
22+
"version": 3
23+
},
24+
"file_extension": ".py",
25+
"mimetype": "text/x-python",
26+
"name": "python",
27+
"nbconvert_exporter": "python",
28+
"pygments_lexer": "ipython3",
29+
"version": "3.9.16"
30+
}
31+
},
32+
"nbformat": 4,
33+
"nbformat_minor": 4
34+
}

0 commit comments

Comments
 (0)