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.
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 variablet”, never “time”. Say “Runge-Kutta” only for the four Runge-Kutta methods. Code names such asmesh_trackersormax_split_depthkeep their names; this rule is about prose.The summary line is one sentence saying what the object does.
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.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.Formulas use
:math:`...`or double-backtick literals. Bare|x|,*argsand_name_in prose break the documentation build.Types come from the docstring (
name : type), because the site does not print annotations. Writetorch.Tensor or Nonerather thantorch.Tensor | Nonein public docstrings.Citations use
:cite:p:`key`with a key ofdocs/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.Examples sections run as doctests. They pass
device="cpu", an explicitmax_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.
User-guide labels for links from docstrings#
Label |
Page and section |
|---|---|
|
Concepts: the integrand contract and the shape letters |
|
Error control: tolerances, error ratios and the rounding floor |
|
Error control: vector-valued integrands ( |
|
Error control: absolute and cumulative tolerance, |
|
How it works: the starting mesh ( |
|
How it works: the optimal mesh and the merge rule ( |
|
Repeated calls: warm starts with |
|
Gradients: |
|
Devices and memory: the memory benchmark, |
|
Troubleshooting: |
|
Repeated calls: tracked variables |