Skip to content

Commit 7c5e87c

Browse files
Fix type hints in docs for PUBs and improve Sphinx config (#2052)
Closes #1877. We now use `EstimatorPubLike` and `SamplerPubLike` for the type hints, rather than Sphinx fully expanding the types into extremely long values shown in #1877. To fix the type hints, we have to stop using `sphinx-autodoc-typehints` and instead use autodoc's builtin support for type hints. I didn't realize we were still using `sphinx-autodoc-typehints` - the other Qiskit projects migrated off a while ago. This PR also makes some other improvements to align with changes we made in Qiskit Addons & qiskit-ibm-transpiler: * always show inheritance in class pages for the base class * index page should show the PyPI package name in code syntax * don't show signatures in `autosummary` tables, since they're noisy * show type hints for parameters that don't have docstring ## Introduces a regression: type hints for properties Unfortunately, switching off of `sphinx-autodoc-typehints` results in Qiskit/documentation#2346. This is a quirk of autosummary that we cannot easily fix. We have a plan to fix it, although realistically won't get to it until Q1 and possibly Q2. In the meantime, consider repeating some of the type information in the docstring. For example, in ``` <Attribute id="qiskit_ibm_runtime.EstimatorV2.mode"> Return the execution mode used by this primitive. ``` You could rewrite to say ``` <Attribute id="qiskit_ibm_runtime.EstimatorV2.mode"> Return the execution mode used by this primitive, either :class:~`.Session` or ~:class:~`.Batch`. ```
1 parent af083a4 commit 7c5e87c

File tree

14 files changed

+33
-26
lines changed

14 files changed

+33
-26
lines changed

docs/_templates/autosummary/base.rst

-10
This file was deleted.

docs/_templates/autosummary/class.rst

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
{% if referencefile %}
2-
.. include:: {{ referencefile }}
3-
{% endif %}
1+
{#
2+
We show all the class's methods and attributes on the same page. By default, we document
3+
all methods, including those defined by parent classes.
4+
-#}
45

5-
{{ objname }}
6-
{{ underline }}
6+
{{ objname | escape | underline }}
77

88
.. currentmodule:: {{ module }}
99

1010
.. autoclass:: {{ objname }}
1111
:no-members:
1212
:no-inherited-members:
1313
:no-special-members:
14+
:show-inheritance:
1415

1516
{% block attributes_summary %}
1617
{% if attributes %}
1718
.. rubric:: Attributes
1819
{% for item in all_attributes %}
1920
{%- if not item.startswith('_') %}
20-
.. autoattribute:: {{ name }}.{{ item }}
21+
.. autoattribute:: {{ item }}
2122
{%- endif -%}
2223
{%- endfor %}
2324
{% endif %}
@@ -28,7 +29,7 @@
2829
.. rubric:: Methods
2930
{% for item in all_methods %}
3031
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
31-
.. automethod:: {{ name }}.{{ item }}
32+
.. automethod:: {{ item }}
3233
{%- endif -%}
3334
{%- endfor %}
3435

docs/apidocs/index.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. vale off
22
3-
********************************
4-
qiskit-ibm-runtime API reference
5-
********************************
3+
************************************
4+
``qiskit-ibm-runtime`` API reference
5+
************************************
66

77
.. toctree::
88
:maxdepth: 1

docs/conf.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
# This is used by qiskit/documentation to generate links to github.com.
4040
"sphinx.ext.linkcode",
4141
'jupyter_sphinx',
42-
'sphinx_autodoc_typehints',
4342
'nbsphinx',
4443
'sphinxcontrib.katex',
4544
'matplotlib.sphinxext.plot_directive',
@@ -83,10 +82,19 @@
8382
# -----------------------------------------------------------------------------
8483

8584
autosummary_generate = True
86-
85+
autosummary_generate_overwrite = False
86+
autoclass_content = "both"
87+
autodoc_typehints = "description"
8788
autodoc_default_options = {
88-
'inherited-members': None,
89+
"inherited-members": None,
90+
"show-inheritance": True,
91+
}
92+
autodoc_type_aliases = {
93+
"EstimatorPubLike": "EstimatorPubLike",
94+
"SamplerPubLike": "SamplerPubLike",
8995
}
96+
napoleon_google_docstring = True
97+
napoleon_numpy_docstring = False
9098

9199

92100
# If true, figures, tables and code-blocks are automatically numbered if they
@@ -130,7 +138,6 @@
130138

131139
html_last_updated_fmt = '%Y/%m/%d'
132140
html_sourcelink_suffix = ''
133-
autoclass_content = 'both'
134141

135142

136143
# ----------------------------------------------------------------------------------

qiskit_ibm_runtime/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
=======
184184
.. autosummary::
185185
:toctree: ../stubs/
186+
:nosignatures:
186187
187188
QiskitRuntimeService
188189
Estimator

qiskit_ibm_runtime/debug_tools/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2525
.. autosummary::
2626
:toctree: ../stubs/
27+
:nosignatures:
2728
2829
Neat
2930
NeatResult

qiskit_ibm_runtime/execution_span/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
3030
.. autosummary::
3131
:toctree: ../stubs/
32+
:nosignatures:
3233
3334
DoubleSliceSpan
3435
ExecutionSpan

qiskit_ibm_runtime/fake_provider/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
9292
.. autosummary::
9393
:toctree: ../stubs/
94+
:nosignatures:
9495
9596
FakeProviderForBackendV2
9697
@@ -106,6 +107,7 @@
106107
107108
.. autosummary::
108109
:toctree: ../stubs/
110+
:nosignatures:
109111
110112
FakeAlgiers
111113
FakeAlmadenV2

qiskit_ibm_runtime/options/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
5858
.. autosummary::
5959
:toctree: ../stubs/
60+
:nosignatures:
6061
6162
EstimatorOptions
6263
SamplerOptions
@@ -67,6 +68,7 @@
6768
6869
.. autosummary::
6970
:toctree: ../stubs/
71+
:nosignatures:
7072
7173
NoiseLearnerOptions
7274
DynamicalDecouplingOptions

qiskit_ibm_runtime/transpiler/passes/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
2424
.. autosummary::
2525
:toctree: ../stubs/
26+
:nosignatures:
2627
2728
ConvertIdToDelay
2829
ConvertISAToClifford

qiskit_ibm_runtime/transpiler/passes/scheduling/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
=======
3434
.. autosummary::
3535
:toctree: ../stubs/
36+
:nosignatures:
3637
3738
BlockBasePadder
3839
ALAPScheduleAnalysis

qiskit_ibm_runtime/utils/noise_learner_result.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
1818
.. autosummary::
1919
:toctree: ../stubs/
20+
:nosignatures:
2021
2122
PauliLindbladError
2223
LayerError

qiskit_ibm_runtime/visualization/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
2626
.. autosummary::
2727
:toctree: ../stubs/
28+
:nosignatures:
2829
2930
draw_execution_spans
3031
draw_layer_error_map

requirements-dev.txt

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ ddt>=1.2.0,!=1.4.0,!=1.4.3
1919
# Documentation
2020
nbsphinx
2121
Sphinx>=6
22-
sphinx-automodapi
23-
sphinx-autodoc-typehints<=1.19.2
2422
jupyter-sphinx
2523
sphinxcontrib-katex==0.9.9
2624
packaging

0 commit comments

Comments
 (0)