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

Cleanup structure of option documentation #1077

Merged

Conversation

nkanazawa1989
Copy link
Collaborator

Summary

close #1076

Details and comments

Note that from end-user perspective subclass option and parent class option don't matter because one gets mixture of all inherited and subclass options when calling analysis.options for example.

@nkanazawa1989 nkanazawa1989 force-pushed the update/analysis-class-doc branch from 4afcec2 to 076a6e9 Compare March 15, 2023 01:02
@nkanazawa1989 nkanazawa1989 marked this pull request as ready for review March 15, 2023 09:13
@nkanazawa1989
Copy link
Collaborator Author

Now option documentation looks like this.
image

@nkanazawa1989 nkanazawa1989 changed the title Remove inherited option description from API doc. Cleanup structure of option documentation Mar 15, 2023
Copy link
Collaborator

@coruscating coruscating left a comment

Choose a reason for hiding this comment

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

This is a great improvement! And thanks for updating docstrings, this also closes #1007.

qiskit_experiments/framework/base_analysis.py Outdated Show resolved Hide resolved
docs/_ext/custom_styles/utils.py Outdated Show resolved Hide resolved
description = "inherited from the parent class"
options_docstring_lines.extend(
[
f"(Options {description} :class:`.{mro_cls.__name__}`)",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the parentheses are necessary. What do you think about f"Options {description} :class:`.{mro_cls.__name__}`:" instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was also thinking of this. However, the structure of sections, i.e. Experiment Options, Transpiler Options, Run Options, became difficult to understand because these section tiles (.. rubric::) and added plain text are the same font size. Do you know better Sphinx directive for these section titles?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, what about changing the .. rubric:: section titles to headings, and changing this line to .. rubric::? Then it would look something like this:
image
I think it's nice to promote the section titles to headings so they can be linked to easily, and in theory the user can also quickly jump to a section using the sidebar.

Also, I wonder if we should move the default option value into the option description and remove the dropdown, would that look cleaner? Something like,

  • max_circuits (Optional[int], default: None) – The maximum number of circuits per job when running an experiment on a backend.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's good idea. Default value can be sometime very long (e.g. ndarray of length 100 to represent scanned value), sometime without pretty printing, and such value make documentation unnecessary long.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just remembered I tried section heading before. The underline of section title breaks build in section of parameters (i.e. Args:) because we are likely mixing up the Google style and Numpy style. As you posted, Parameter formatting is now broken and they are shown like type lengths: in your screen shot.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the info, I was wondering why the parameters were all messed up after I converted the heading. I tried a bunch of things and setting napoleon_use_param = False in conf.py seems to work:

image

Also, for the default values, I agree they can be very long sometimes. There are also examples like plotter := <qiskit_experiments.visualization.plotters.iq_plotter.IQPlotter object at 0x1763b8c70> which is confusing. Maybe we can just show the object type instead of the repr in cases like these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah this is close. I didn't consider the difference of :param: role and single :parameters: role. It indeed worked for parsing parameters under the section, but it broke other documentations with Type Annotations. We usually write type hints in the code, but they won't show up. I guess this is a bug though... For example this is constructor of StandardRB. Note that documentation of raises also looks strange. There is no napoleon_use_raises option. Probably we need to full scratch the documenter.

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Regarding the default value
image
how do we want to show a value like this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I guess there's no easy fix then. We can leave it as possible future work.

For default values, I think showing numpy.linspace(-0.95, 0.95, 51) is a lot more readable than that block. But is there a way to do that besides manually calculating the start end and step size from the array? Or we can add an optional field in the experiment options docstring allowing override of the default display value in cases like this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's likely tough to get args for ndarray factory. I implemented truncation in b1936a3

docs/_ext/custom_styles/styles.py Outdated Show resolved Hide resolved
docs/_ext/custom_styles/styles.py Outdated Show resolved Hide resolved
docs/_ext/custom_styles/styles.py Outdated Show resolved Hide resolved
docs/_ext/custom_styles/styles.py Outdated Show resolved Hide resolved
nkanazawa1989 and others added 4 commits March 16, 2023 04:39
Sphinx parser doesn't support line break during the type hint. Long type hint is not shown properly in the API doc. New logic is added to the Sphinx extension to remove these line feeds.
Co-authored-by: Helena Zhang <[email protected]>
@coruscating coruscating added this to the Release 0.5 milestone Mar 21, 2023
…also injection that references superclasses.
@nkanazawa1989 nkanazawa1989 force-pushed the update/analysis-class-doc branch from b1936a3 to 577ff71 Compare March 21, 2023 15:47
Copy link
Collaborator

@coruscating coruscating left a comment

Choose a reason for hiding this comment

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

I think this is really close! The truncated default values look nice. I noticed that InterleavedRB is showing StandardRB options as coming from itself instead, not sure why that's happening again.

docs/_ext/custom_styles/utils.py Outdated Show resolved Hide resolved
docs/_ext/custom_styles/utils.py Outdated Show resolved Hide resolved
@nkanazawa1989
Copy link
Collaborator Author

I noticed that InterleavedRB is showing StandardRB options as coming from itself instead, not sure why that's happening again.

Thanks for catching this. I fixed this once but 577ff71 reverted the logic by mistake. 99c4fe2 fixed class name.

Copy link
Collaborator

@coruscating coruscating left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@nkanazawa1989 nkanazawa1989 added this pull request to the merge queue Mar 24, 2023
Merged via the queue into qiskit-community:main with commit 670ac82 Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Separate parent class options in experiment and analysis class API docs
2 participants