Skip to content

Commit

Permalink
Fix type hints in docs for PUBs and improve Sphinx config (#2052)
Browse files Browse the repository at this point in the history
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`.
```
  • Loading branch information
Eric-Arellano authored Nov 25, 2024
1 parent af083a4 commit 7c5e87c
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 26 deletions.
10 changes: 0 additions & 10 deletions docs/_templates/autosummary/base.rst

This file was deleted.

15 changes: 8 additions & 7 deletions docs/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{% if referencefile %}
.. include:: {{ referencefile }}
{% endif %}
{#
We show all the class's methods and attributes on the same page. By default, we document
all methods, including those defined by parent classes.
-#}

{{ objname }}
{{ underline }}
{{ objname | escape | underline }}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
:no-members:
:no-inherited-members:
:no-special-members:
:show-inheritance:

{% block attributes_summary %}
{% if attributes %}
.. rubric:: Attributes
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
.. autoattribute:: {{ name }}.{{ item }}
.. autoattribute:: {{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
Expand All @@ -28,7 +29,7 @@
.. rubric:: Methods
{% for item in all_methods %}
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
.. automethod:: {{ name }}.{{ item }}
.. automethod:: {{ item }}
{%- endif -%}
{%- endfor %}

Expand Down
6 changes: 3 additions & 3 deletions docs/apidocs/index.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.. vale off
********************************
qiskit-ibm-runtime API reference
********************************
************************************
``qiskit-ibm-runtime`` API reference
************************************

.. toctree::
:maxdepth: 1
Expand Down
15 changes: 11 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
# This is used by qiskit/documentation to generate links to github.com.
"sphinx.ext.linkcode",
'jupyter_sphinx',
'sphinx_autodoc_typehints',
'nbsphinx',
'sphinxcontrib.katex',
'matplotlib.sphinxext.plot_directive',
Expand Down Expand Up @@ -83,10 +82,19 @@
# -----------------------------------------------------------------------------

autosummary_generate = True

autosummary_generate_overwrite = False
autoclass_content = "both"
autodoc_typehints = "description"
autodoc_default_options = {
'inherited-members': None,
"inherited-members": None,
"show-inheritance": True,
}
autodoc_type_aliases = {
"EstimatorPubLike": "EstimatorPubLike",
"SamplerPubLike": "SamplerPubLike",
}
napoleon_google_docstring = True
napoleon_numpy_docstring = False


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

html_last_updated_fmt = '%Y/%m/%d'
html_sourcelink_suffix = ''
autoclass_content = 'both'


# ----------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions qiskit_ibm_runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
=======
.. autosummary::
:toctree: ../stubs/
:nosignatures:
QiskitRuntimeService
Estimator
Expand Down
1 change: 1 addition & 0 deletions qiskit_ibm_runtime/debug_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
.. autosummary::
:toctree: ../stubs/
:nosignatures:
Neat
NeatResult
Expand Down
1 change: 1 addition & 0 deletions qiskit_ibm_runtime/execution_span/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
.. autosummary::
:toctree: ../stubs/
:nosignatures:
DoubleSliceSpan
ExecutionSpan
Expand Down
2 changes: 2 additions & 0 deletions qiskit_ibm_runtime/fake_provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
.. autosummary::
:toctree: ../stubs/
:nosignatures:
FakeProviderForBackendV2
Expand All @@ -106,6 +107,7 @@
.. autosummary::
:toctree: ../stubs/
:nosignatures:
FakeAlgiers
FakeAlmadenV2
Expand Down
2 changes: 2 additions & 0 deletions qiskit_ibm_runtime/options/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
.. autosummary::
:toctree: ../stubs/
:nosignatures:
EstimatorOptions
SamplerOptions
Expand All @@ -67,6 +68,7 @@
.. autosummary::
:toctree: ../stubs/
:nosignatures:
NoiseLearnerOptions
DynamicalDecouplingOptions
Expand Down
1 change: 1 addition & 0 deletions qiskit_ibm_runtime/transpiler/passes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
.. autosummary::
:toctree: ../stubs/
:nosignatures:
ConvertIdToDelay
ConvertISAToClifford
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
=======
.. autosummary::
:toctree: ../stubs/
:nosignatures:
BlockBasePadder
ALAPScheduleAnalysis
Expand Down
1 change: 1 addition & 0 deletions qiskit_ibm_runtime/utils/noise_learner_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
.. autosummary::
:toctree: ../stubs/
:nosignatures:
PauliLindbladError
LayerError
Expand Down
1 change: 1 addition & 0 deletions qiskit_ibm_runtime/visualization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
.. autosummary::
:toctree: ../stubs/
:nosignatures:
draw_execution_spans
draw_layer_error_map
Expand Down
2 changes: 0 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ ddt>=1.2.0,!=1.4.0,!=1.4.3
# Documentation
nbsphinx
Sphinx>=6
sphinx-automodapi
sphinx-autodoc-typehints<=1.19.2
jupyter-sphinx
sphinxcontrib-katex==0.9.9
packaging

0 comments on commit 7c5e87c

Please sign in to comment.