ml_switcheroo.core.tikz.analyser¶
Static Graph Extractor for TikZ Visualization.
This module implements the analysis logic to convert Python source code (AST) into a language-agnostic Logical Graph. It parses __init__ methods to identify layer definitions (Nodes) and forward/__call__ methods to identify variable data flow (Edges).
The output LogicalGraph is an intermediate representation used by the TikZ emitter to generate visual diagrams.
Classes¶
LibCST Visitor that extracts a LogicalGraph from Python source code. |
Module Contents¶
- class ml_switcheroo.core.tikz.analyser.GraphExtractor[source]¶
Bases:
libcst.CSTVisitorLibCST Visitor that extracts a LogicalGraph from Python source code.
Two-Pass Logic:
Init Pass: Scans __init__ or setup to register named layers assigned to self. Populates the node registry.
Forward Pass: Scans forward or __call__ to trace variable usage. Builds edges between registered nodes based on data flow.
- graph¶
- layer_registry: Dict[str, ml_switcheroo.core.graph.LogicalNode]¶
- provenance: Dict[str, str]¶
- model_name: str = 'GeneratedNet'¶
- leave_Module(original_node: libcst.Module) None[source]¶
Finalize graph construction after visiting the whole module. This ensures nodes are populated even if there is no forward pass.
- visit_FunctionDef(node: libcst.FunctionDef) bool | None[source]¶
Detects entry into lifecycle methods (__init__, forward, etc).
- leave_FunctionDef(node: libcst.FunctionDef) None[source]¶
Resets context flags upon exiting methods.