ml_switcheroo.core.tikz.analyser ================================ .. py:module:: ml_switcheroo.core.tikz.analyser .. autoapi-nested-parse:: 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 ------- .. autoapisummary:: ml_switcheroo.core.tikz.analyser.GraphExtractor Module Contents --------------- .. py:class:: GraphExtractor Bases: :py:obj:`libcst.CSTVisitor` LibCST Visitor that extracts a LogicalGraph from Python source code. Two-Pass Logic: 1. **Init Pass**: Scans `__init__` or `setup` to register named layers assigned to `self`. Populates the node registry. 2. **Forward Pass**: Scans `forward` or `__call__` to trace variable usage. Builds edges between registered nodes based on data flow. .. py:attribute:: graph .. py:attribute:: layer_registry :type: Dict[str, ml_switcheroo.core.graph.LogicalNode] .. py:attribute:: provenance :type: Dict[str, str] .. py:attribute:: model_name :type: str :value: 'GeneratedNet' .. py:method:: visit_ClassDef(node: libcst.ClassDef) -> Optional[bool] Capture the model class name. .. py:method:: leave_Module(original_node: libcst.Module) -> None Finalize graph construction after visiting the whole module. This ensures nodes are populated even if there is no forward pass. .. py:method:: visit_FunctionDef(node: libcst.FunctionDef) -> Optional[bool] Detects entry into lifecycle methods (__init__, forward, etc). .. py:method:: leave_FunctionDef(node: libcst.FunctionDef) -> None Resets context flags upon exiting methods. .. py:method:: visit_Assign(node: libcst.Assign) -> Optional[bool] Handles assignment logic for both layer definition and data flow. .. py:method:: visit_Return(node: libcst.Return) -> Optional[bool] Handles return statements in forward pass to create Output nodes. Also handles case where return contains a functional call directly.