The primary goal is to routinely write scripts that read like math and code.
If someone scrolls your script top-to-bottom, the conceptual story should flow:
-
What exists?
-
What are you allowed to call?
-
How does it work?
-
Proof it works.
# src/example.py
"""
Script descriptiion
Author:
Date:
"""
# imports and typing
__future__ import annotations # Type hinting
__all__ = ["public_function"] # Explicitly declare public API
# -----------------------------------------------------------------------------------------------------------
# 0οΈβ£ Typing helpers / protocols / constants (if needed)
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# 1οΈβ£ Core definitions
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# 2οΈβ£ Public API (functions users are meant to call)
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# 3οΈβ£ Private helpers
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# 4οΈβ£ Smoke tests / example usage
# -----------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------
# 5οΈβ£ Entry point
# -----------------------------------------------------------------------------------------------------------
if name == "__main__".
def main() -> None:.
def main() -> None:
_smoke_test()
float | Tensor) when physically meaningul.
omega: float | Final[Tensor] = 1.0
def public_function(x: Tensor) -> Tensor:
"""
Short description.
Parameters
----------
x : Tensor
Description of x.
Returns
-------
Tensor
Description of return value.
"""
pass