Writing docstrings#

padaquad’s docstrings follow the numpydoc format and these rules. The documentation site is built from them, so they are written for users first.

  1. One word per concept. Use the words of the glossary: subinterval (never “step” or “panel” for a piece of the domain), mesh (never “barrier”), node, method (never “rule”), weights, degree, order. Call t “the integration variable t”, never “time”. Say “Runge-Kutta” only for the four Runge-Kutta methods. Code names such as mesh_trackers or max_split_depth keep their names; this rule is about prose.

  2. The summary line is one sentence saying what the object does.

  3. Each parameter gets at most three lines: what it controls, its shape or units, and its default behavior. A longer explanation goes in the user guide, and the docstring links to it with :ref:`label` . The labels are listed below.

  4. Public docstrings do not mention bug IDs (“B4”), “Phase N”, “historical”, names of private functions or attributes (anything starting with _), or removed features. Private docstrings may name private code.

  5. Formulas use :math:`...` or double-backtick literals. Bare |x|, *args and _name_ in prose break the documentation build.

  6. Types come from the docstring (name : type), because the site does not print annotations. Write torch.Tensor or None rather than torch.Tensor | None in public docstrings.

  7. Citations use :cite:p:`key` with a key of docs/references.bib. A source is added there only after it has been opened and the cited number, table or equation found in it. A formula that is padaquad’s own is labeled “(padaquad’s own derivation)” and derived where it is used.

  8. Examples sections run as doctests. They pass device="cpu", an explicit max_batch (this skips the memory benchmark) and float64 bounds, print rounded Python floats rather than tensors, and never print a mesh size, because the starting mesh is random.