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

#362: add basic rst template for api documentation #385

Merged
merged 9 commits into from
Aug 15, 2023

Conversation

nmm0
Copy link
Contributor

@nmm0 nmm0 commented May 22, 2023

Closes #362

@nmm0 nmm0 changed the title #362: add basic rst template for api documentation Draft: #362: add basic rst template for api documentation May 22, 2023
@nmm0 nmm0 marked this pull request as draft May 22, 2023 23:31
@vlkale vlkale marked this pull request as ready for review May 22, 2023 23:38
- for subsections

^ for subsubsections

Copy link
Contributor

@ajpowelsnl ajpowelsnl May 23, 2023

Choose a reason for hiding this comment

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

There are often several ways for doing basic things (e.g., creating subsections). Is there a reason to prefer one way over another?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is what's recommended, I just copy and pasted from https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#sections

Copy link
Contributor

@ajpowelsnl ajpowelsnl 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 really good Nic. Many thanks for your help with this!

Use the following convention for headings:

# with overline, for parts

Copy link
Contributor

@ajpowelsnl ajpowelsnl May 23, 2023

Choose a reason for hiding this comment

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

A general comment: I'm not familiar with some of the "Sphinx-isms," and other might not be, either.
For example, what is a "part" vs. a "chapter" (operationally speaking), and what does "overline" mean in both contexts?

Would it help either in the README or here to point people to the Sphinx Style Guide: https://documentation-style-guide-sphinx.readthedocs.io/en/latest/style-guide.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, this isn't exactly official and has some things like saying to use .txt extensions that I don't agree with

templates/api.rst Outdated Show resolved Hide resolved
..
It may be useful to also have examples for individual functions above.

Prefer examples to usage.
Copy link
Contributor

@ajpowelsnl ajpowelsnl May 23, 2023

Choose a reason for hiding this comment

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

Maybe put this idea ("Prefer examples to usage") up top, as a point of general guidance. A possible re-work of this sentence for clarity: "Prefer working, compile-able code to human-language description."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to make it clearer, but I think it should go further down rather at the top. Maybe we could have a more "general guidelines" page?


#include<Kokkos_Core.hpp>
#include<cstdio>

Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: Amy, Nic + Francesco figure out Sphinx feature for correct rendering of C++ include statements

Copy link
Contributor

Choose a reason for hiding this comment

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

@fnrizzi -- can you help w/ this rendering question?

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 we have a way around, the include is inside the code block

}

Kokkos::finalize();
}
Copy link
Contributor

@ajpowelsnl ajpowelsnl May 23, 2023

Choose a reason for hiding this comment

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

Meeting comments:

  • In the general example, add all possible "Kokkos-isms" so everyone can understand the available customizations and how to use them

  • Add template for classes to facilitate copy / paste

  • Fix header rendering

  • Create compiled version (Daniel A.)

  • Add Kokkos to Compiler Explorer, and make examples work interactively with it (Cezary S.)

  • Submit issue to Compiler Explorer to add Kokkos (done)

  • Submit an issue to Compiler Explorer

  • From Compiler Explorer site:

    ```
    “To add a library, search for one you want and select the version in the dropdown. Or if you have favorited it before, just click the library name in the Favorites section. Libraries are installed |using the conan.io package manager, except for Microsoft compilers, where vcpkg is used.”
    ```
    

Copy link
Contributor

@ajpowelsnl ajpowelsnl left a comment

Choose a reason for hiding this comment

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

Hey Nic -- It generally looks good, but a few changes might help (see embedded comments).

}

Kokkos::finalize();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

WHOOPSIE! I missed this TODO:

  • Add example to "Contributing" pages as a compiled example
  • "Contributing"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the template to "Contributing". I actually made a folder that we can add more templates to


#include<Kokkos_Core.hpp>
#include<cstdio>

Copy link
Contributor

Choose a reason for hiding this comment

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

@fnrizzi -- can you help w/ this rendering question?

templates/api.rst Outdated Show resolved Hide resolved
@nmm0
Copy link
Contributor Author

nmm0 commented Jul 24, 2023

I rebased and updated with some extra useful comments.

@nmm0 nmm0 changed the title Draft: #362: add basic rst template for api documentation #362: add basic rst template for api documentation Jul 24, 2023
Copy link
Collaborator

@fnrizzi fnrizzi left a comment

Choose a reason for hiding this comment

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

@nmm0 can you please post also in the PR a screenshot of what this looks like?

templates/api.rst Outdated Show resolved Hide resolved

#include<Kokkos_Core.hpp>
#include<cstdio>

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 we have a way around, the include is inside the code block

..
Use the following convention for headings:

# with overline, for parts
Copy link
Collaborator

Choose a reason for hiding this comment

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

what are "parts"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I clarified this

docs/source/templates/class_api.rst Show resolved Hide resolved
docs/source/templates/class_api.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@ajpowelsnl ajpowelsnl left a comment

Choose a reason for hiding this comment

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

Hi Nic, Apologies for the late-in-the-day turn around, but there are a few things that are not clear to me. I'll be happy to work through these together.


..
Template parameters (if applicable)
Omit template parameters that are just used for specialization/is deduced/ and/or should not be exposed to the user.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change "is deduced" to "are deduced" for subject - verb agreement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!


.. rubric:: Template Parameters

:tparam Foo: Description of the Foo template parameter
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make "Foo" capitalization consistent with "bar" ...either way is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here it's just our coding convention of capitalizing template parameters and having parameters/locals lowercase. So the documentation just follows the main core Kokkos coding convention

If you have related info

.. seealso::

Copy link
Contributor

Choose a reason for hiding this comment

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

With this, is your idea to link within or among other documentation entries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both -- cross referencing works across files. They can even be namespaced which is nice


.. cppkokkos:function:: ~CoolerView()

Document what special effect the destructor has.
Copy link
Contributor

Choose a reason for hiding this comment

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

This directive, "Document what special ..." is a bit conflict-y with the comment above. A few questions:

  1. The special effects you mention are in cases apart from the usual business of normal destructor housekeeping ?
  2. Are there common, canonical examples of special destructor effects? If so, maybe mention some of those to firm up guidance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the comment -- special effects include things like releasing resources, etc. I mention in the comments


.. versionchanged:: 3.7.1

Only takes one parameter for foo-style operations instead of two.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite understand line 116. Is this phrase in relation to .. versionchanged:: 3.7.1, or something else? Either way, I don't understand what you're telling me here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, rst is a little bit annoying to read but if you have a directive (.. directive:: where directive is the name of the directive). After the two colons are the arguments to the directives, so in this case the version in which it was changed (3.7.1). Some directives have "options" (not this one) and "contents". The "options" and "contents" are tabbed (tabbing is important!) and an empty line must be before the "contents". So in this case the string Only takes one parameter for foo-style operations instead of two. is the contents of the directive because it's tabbed over one and represents the blurb that gets rendered by sphinx.

Annoyingly, the definition for a comment is similar (there is just no double colon). To make it less confusing it's commonly recommended to put the comment on the next line after the ..

..
  This is a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deprecated types need special handling, both for the badge displayed beforehand and the deprecated version directive.
Note, there is not currently any functionality for other deprecated entities.

.. cppkokkos:deprecated-type:: 4.0.1 foobar
Copy link
Contributor

Choose a reason for hiding this comment

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

In your comment, maybe note key points of our discussion this morning about deprecation syntax in .rst files, and (parser) rendering in html.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Though I did move to the c++ style [[deprecated("reason")]]


..
These should only be listed here if they are closely related. E.g. friend operators. However,
something like view_alloc shouldn't be here for view
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we readily identify those "friends?" Is there a Sphinx cpp customization to flag "friend" methods, operators, etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No sadly, but at least having them logically grouped in the same documentation makes sense.

something like view_alloc shouldn't be here for view

.. cppkokkos:function:: template<class ViewSrc> bool operator==(CoolerView, ViewSrc);

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an actual comparator? i.e., something testing that CoolerView is the same as ViewSrc, or is this just your example of an "allied" or "friend" operator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just an example

:tparam ViewDst: the other

:return: true if :cppkokkos:type:`~View::value_type`, :cppkokkos:type:`~View::array_layout`, :cppkokkos:any:`~View::memory_space`, :cppkokkos:any:`~View::rank`, :cppkokkos:any:`~View::data()` and :cppkokkos:any:`~View::extent` (r), for :code:`0<=r<rank`, match.

Copy link
Contributor

Choose a reason for hiding this comment

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

For lines 146 - 148, a few questions:

  • what is ViewDst the template parameter for? I don't see it in any near-by functions that use it.
  • what do the ~ represent in line 148?
  • is everything in lines 146 - 148 meant to be used in the operator in line 144? I'm having trouble seeing the flow of events : )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just an example. I mostly copied it from the view documentation.

The ~ is a typo, it shouldn't be in there, I removed now. These are all supposed to be cross-references, but right now we don't document View as a class so they won't work. Yes, this is all the documentation for the operator.

It may be useful to also have examples for individual functions above.

Prefer working and compilable examples to prose descriptions (such as "Usage").

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll check to make sure this code compiles in Compiler Explorer.

@ajpowelsnl ajpowelsnl requested a review from dalg24 July 31, 2023 15:48
@nmm0 nmm0 requested review from fnrizzi and ajpowelsnl July 31, 2023 18:21
for free functions that are callable, preserve the naming convention, `view_alloc()`

``CoolerView``
=====================
Copy link
Collaborator

Choose a reason for hiding this comment

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

the length of === should be fixed to match the word otherwise this is misleading since sphinx would raise an exception for this



Non-Member Functions
----------------------
Copy link
Collaborator

@fnrizzi fnrizzi Aug 1, 2023

Choose a reason for hiding this comment

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

length of ---- should end under s of Functions

:hidden:

templates/index

We are open and try to encourage contributions from external developers.
To do so please first open an issue describing the contribution and then
issue a pull request against the develop branch.
Copy link
Collaborator

@fnrizzi fnrizzi Aug 1, 2023

Choose a reason for hiding this comment

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

there is no develop branch, ah nevermind this is for actual code in core

Copy link
Collaborator

@fnrizzi fnrizzi left a comment

Choose a reason for hiding this comment

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

just a few minor ones

docs/source/templates/class_api.rst Outdated Show resolved Hide resolved
docs/source/templates/class_api.rst Outdated Show resolved Hide resolved
@nmm0 nmm0 force-pushed the add-documentation-template branch from 4972691 to b87a5eb Compare August 15, 2023 15:25
@nmm0
Copy link
Contributor Author

nmm0 commented Aug 15, 2023

I don't know why the build is failing but main is not. I haven't touched the failing file (keywords.rst)

@nmm0 nmm0 force-pushed the add-documentation-template branch from b87a5eb to fd37482 Compare August 15, 2023 15:42
@nmm0 nmm0 requested review from crtrott and fnrizzi August 15, 2023 15:49
@crtrott crtrott merged commit 52443dd into kokkos:main Aug 15, 2023
1 check passed
:language: cppkokkos

..
The (pulic header) file the user will include in their code
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The (pulic header) file the user will include in their code
The (public header) file the user will include in their code

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.

add rst templates for adding documentation
5 participants