Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve header hierarchy for utils documentation #11923

Merged
merged 7 commits into from
Mar 1, 2024

Conversation

Eric-Arellano
Copy link
Collaborator

Groups functions into sections

Screenshot 2024-02-29 at 10 58 06 AM

This provides better structure for users rather than being a flat list. Each section header corresponds to a specific module.

Using these h2 headers also improves the accessibility of the docs with IQP. In qiskit/documentation, functions have an h3 generated for them like this:

Screenshot 2024-02-29 at 11 00 45 AM

We generate this h3 so that

a) it shows up in the right page table of contents, and
b) the app automatically generates an anchor link buton
Screenshot 2024-02-29 at 11 01 28 AM

But accessibility guidelines say that you should avoid jumping from an h1 to h3 because it makes screen readers work worse.

Fixes Optional Dependency Checkers to be h2

It was being set as an h3 because of using === as the header rather than ---. Note that Sphinx doesn't have any predetermined heading value for === vs ---. It determines what it corresponds to based on what shows up first in the document. Here, --- shows up first, so it was an h2, whereas === was an h3.

This issue was causing all subheaders to be one heading level lower than they should be.

@Eric-Arellano Eric-Arellano added documentation Something is not clear or an error documentation stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: None Do not include in changelog labels Feb 29, 2024
@Eric-Arellano Eric-Arellano requested a review from a team as a code owner February 29, 2024 16:03
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@Eric-Arellano Eric-Arellano changed the title [wip] Improve header hierarchy for utils documentation Improve header hierarchy for utils documentation Feb 29, 2024
A helper function for calling a custom function with python
:class:`~concurrent.futures.ProcessPoolExecutor`. Tasks can be executed in parallel using this function.

.. autofunction:: parallel_map

Optional Dependency Checkers (:mod:`qiskit.utils.optionals`)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code snippet makes this header unnecessarily long in the page table of contents. The table will already show the full import path, and I also tweaked the opening paragraph below to say the module name.

Screenshot 2024-02-29 at 11 04 43 AM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A potential alternative is to give qiskit.utils.optionals its own rst file and entry in the toc, so it appears as a separate page? Our other module headers (that are standalone pages) all include this :mod:`qiskit.module` but in the title, so it's good for consistency.

That said, I don't feel strongly, and if this does stay in line, I'm fine to remove the bit from the title. It was originally included for consistency, and because I think the theme at the time didn't document things with fully qualified names.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For it to be its own page in IQP, it will either need to be at the same level as utils, i.e. top-level like qiskit.utils.optionals in the left side bar; or qiskit.utils becomes like a folder that you have to click to expand and it has an Overview page and second page for optionals. Neither of those are very appealing. So let's stick with inline.

Screenshot 2024-02-29 at 12 41 46 PM

I'll make your tweaks though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm fine either inline or separate page. I think I originally made this documentation, and I went inline in the original form too.

@coveralls
Copy link

coveralls commented Feb 29, 2024

Pull Request Test Coverage Report for Build 8111735140

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.03%) to 89.308%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.81%
crates/qasm2/src/lex.rs 5 91.94%
Totals Coverage Status
Change from base Build 8104544265: 0.03%
Covered Lines: 59129
Relevant Lines: 66208

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle this looks good to me, thanks for looking at the structure.

Qiskit has several features that are enabled only
if certain *optional* dependencies are satisfied. This module is a collection of objects that can
Qiskit has several features that are enabled only if certain *optional* dependencies
are satisfied. The ``qiskit.utils.optionals`` module has a collection of objects that can
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
are satisfied. The ``qiskit.utils.optionals`` module has a collection of objects that can
are satisfied. This module, :mod:`qiskit.utils.optionals`, has a collection of objects that can

or something? - I'm not tied to the wording, I just want to make it clearer that this section specifically documents one module, and so the module name is a hyperlink anchor to the same place to drive the point home.

(This comment is predicated on the :mod:`qiskit.utils.optionals` link being removed from the title - if that's reinstated, I think the original wording of the docs are probably fine.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and so the module name is a hyperlink anchor to the same place to drive the point home.

I thought this was confusing? I can add it back, but it seemed weird to me to click a link and it take you back to the exact spot you're reading.

The header will alreadyhave the little button to show it can be an anchor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If nothing else, not having the :mod: will mean that it gets styled very differently to most things documented objects - it's probably best to have it even if it's not all that useful. We have loads of examples of classes referring to themselves already, and all the :mod: tags that appear in titles will also be hyperlinking to themselves.

(Personally I don't find it confusing - I quite like it when things like the Python docs do it (e.g. https://docs.python.org/3/library/unittest.html)).

A helper function for calling a custom function with python
:class:`~concurrent.futures.ProcessPoolExecutor`. Tasks can be executed in parallel using this function.

.. autofunction:: parallel_map

Optional Dependency Checkers (:mod:`qiskit.utils.optionals`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A potential alternative is to give qiskit.utils.optionals its own rst file and entry in the toc, so it appears as a separate page? Our other module headers (that are standalone pages) all include this :mod:`qiskit.module` but in the title, so it's good for consistency.

That said, I don't feel strongly, and if this does stay in line, I'm fine to remove the bit from the title. It was originally included for consistency, and because I think the theme at the time didn't document things with fully qualified names.

Comment on lines 41 to 48
Multiprocessing
---------------

.. autofunction:: local_hardware_info
.. autofunction:: is_main_process

Parallel Routines
-----------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can maybe stick these "Multiprocessing" functions under "Parallel Routines" with parallel_map, or vice versa? I think they're all sufficiently related to avoid an extra section heading.

Comment on lines 41 to 56
============================================================
Optional Dependency Checkers
----------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To stop this mistake happening again, we maybe want to make all the level-2 headings ===== underlines rather than ----- - that's the standard convention in Qiskit docstrings, and possibly how this mistake happened in the first place.

@jakelishman
Copy link
Member

Oh dear, that test error is #11676, except it just happened on Python 3.8 / Numpy 1.24.4, which we thought couldn't happen.

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thanks for the changes.

Just for clarity if anyone else sees this - rST doesn't actually prescribe the syntax for h1/h2/h3 or anything, it just defines something like 12 ways you can make a header, then it infers which one refers to which level by the order they appear. We switched to ====== underlines here "for h2" not because that enforces h2, but just because conventionally in Qiskit documentation that's the one we use for the second heading level in a file.

@jakelishman jakelishman added this pull request to the merge queue Mar 1, 2024
@Eric-Arellano
Copy link
Collaborator Author

Thanks, Jake. FYI I opened up Qiskit/documentation#942 to track auditing all the other module pages.

Merged via the queue into Qiskit:main with commit 44e348a Mar 1, 2024
12 checks passed
mergify bot pushed a commit that referenced this pull request Mar 1, 2024
* Improve header hierarchy for utils documentation

* Fix pylint

* Review feedback

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

* Use mod cross-reference to self

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
(cherry picked from commit 44e348a)
@Eric-Arellano Eric-Arellano deleted the EA/improve-utils-headers branch March 1, 2024 18:25
github-merge-queue bot pushed a commit that referenced this pull request Mar 1, 2024
* Improve header hierarchy for utils documentation

* Fix pylint

* Review feedback

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

* Use mod cross-reference to self

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
(cherry picked from commit 44e348a)

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
IsmaelCesar pushed a commit to comp-quantica/qiskit-terra that referenced this pull request Mar 13, 2024
* Improve header hierarchy for utils documentation

* Fix pylint

* Review feedback

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

* Use mod cross-reference to self

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog documentation Something is not clear or an error documentation stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants