Spec 4: Python package architecture¶
This page describes the target layout of the pops Python package introduced in
Spec 4. The restructure replaces the previous flat module layout (pops/dsl.py,
pops/physics.py, pops/time.py, pops/lib.py, …) with seven sub-packages that
form a strictly acyclic import graph.
Note
The old flat modules (pops.dsl, pops.physics at the top level, etc.) are deleted.
No backward-compatibility shims are shipped. Callers must update their imports to
the sub-packages listed here.
The seven sub-packages¶
Package |
Responsibility |
|---|---|
|
Symbolic IR: expression nodes, ops, values, lowering passes, and visitors. Imports nothing inside |
|
Operator-first typed model core: |
|
Math and physics authoring facade. |
|
Temporal language: |
|
Descriptors, time schemes, moment closures, and provided standard models. Imports |
|
The only C++ emitter. Holds |
|
Thin facade over the |
Acyclic import graph¶
The graph has a single direction: lower packages never import upper ones.
pops.codegen is the exclusive C++ emission point; authoring packages
(pops.physics, pops.time, pops.lib) never import it or _pops.
Package |
May import (inside pops) |
|---|---|
|
(nothing) |
|
|
|
|
|
|
|
|
|
|
|
|
Codegen as free functions: the key design decision¶
The emit_cpp_* helpers and module_codegen live in pops.codegen as ordinary
free functions that accept a model object. They do NOT live on pops.physics.Model
as methods (no m.compile(), no m.emit_cpp_source()).
Why: keeping C++ emission out of the authoring packages prevents a cycle. If
pops.physics.Model.compile() existed, pops.physics would have to import
pops.codegen, which imports pops.lib, which imports pops.physics – a cycle.
As free functions, pops.codegen may import everything above it while authoring
packages import nothing from pops.codegen. Callers that need to compile call
pops.compile_problem(model=m) (the top-level convenience that delegates to
pops.codegen), while authoring workflows that only need to inspect or lower a
model never pay the cost of loading the C++ toolchain.
Public API surface¶
The entries below are the stable public surface as of Spec 4. The top-level
pops namespace re-exports the most commonly used symbols.
Symbol |
Package |
|---|---|
|
|
|
|
|
top-level (delegates to |
|
|
|
|
|
|
|
|
Migration from the old flat API¶
The table below maps every old symbol to its new location. The old flat modules are deleted; no shims exist.
Old (flat) |
New (Spec 4) |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Module file-size rule¶
Each module file must stay at or below 500 lines. Files that would exceed this limit are split into mixins or sub-modules within the package.