ml_switcheroo.core.latex.nodes¶

MIDL Semantic Nodes.

This module defines the data structures representing the primitives of the LaTeX DSL. These nodes act as an intermediate representation between raw LaTeX macros and the compiler’s logical graph.

Classes match the DSL macros:
  • ModelContainer -> \begin{DefModel}

  • MemoryNode -> \Attribute

  • InputNode -> \Input

  • ComputeNode -> \Op

  • StateOpNode -> \StateOp

  • ReturnNode -> \Return

Classes¶

LatexNode

Abstract base class for all MIDL nodes.

MemoryNode

Represents stateful memory allocation (e.g., Weights/Layers).

InputNode

Represents the model input definition.

ComputeNode

Represents a stateless operation call.

StateOpNode

Represents a call to a stateful layer defined in Memory.

ReturnNode

Represents the output return statement.

ModelContainer

Root container representing the Model definition block.

Module Contents¶

class ml_switcheroo.core.latex.nodes.LatexNode[source]¶

Bases: abc.ABC

Abstract base class for all MIDL nodes.

Enforces a to_latex() method for serialization support.

abstractmethod to_latex() → str[source]¶

Serializes the node object back into its LaTeX macro representation.

Returns:

Valid LaTeX code string.

Return type:

str

class ml_switcheroo.core.latex.nodes.MemoryNode[source]¶

Bases: LatexNode

Represents stateful memory allocation (e.g., Weights/Layers). Maps to the \Attribute macro.

Example:

\Attribute{conv}{Conv2d}{in=1, out=32, k=3}
node_id: str¶

The unique identifier for the attribute.

op_type: str¶

The operation type (e.g., ‘Conv2d’).

config: Dict[str, str]¶

Configuration parameters for the layer.

to_latex() → str[source]¶

Render to \Attribute macro.

class ml_switcheroo.core.latex.nodes.InputNode[source]¶

Bases: LatexNode

Represents the model input definition. Maps to the \Input macro.

Example:

\Input{x}{[B, 1, 28, 28]}
name: str¶

Name of the input variable.

shape: str¶

Shape descriptor string.

to_latex() → str[source]¶

Render to \Input macro.

class ml_switcheroo.core.latex.nodes.ComputeNode[source]¶

Bases: LatexNode

Represents a stateless operation call. Maps to the \Op macro.

Example:

\Op{s2}{Flatten}{s1, start=1}{[B, 21632]}
node_id: str¶

The unique identifier to assign the result to.

op_type: str¶

The operation type (e.g., ‘Flatten’).

args: List[str]¶

List of arguments passed to the operation.

shape: str¶

Resulting shape descriptor.

to_latex() → str[source]¶

Render to \Op macro.

class ml_switcheroo.core.latex.nodes.StateOpNode[source]¶

Bases: LatexNode

Represents a call to a stateful layer defined in Memory. Maps to the \StateOp macro.

Example:

\StateOp{s1}{conv}{x}{[B, 32, 26, 26]}
node_id: str¶

The unique identifier to assign the result to.

attribute_id: str¶

The ID of the attribute being called.

args: List[str]¶

List of arguments passed to the call.

shape: str¶

Resulting shape descriptor.

to_latex() → str[source]¶

Render to \StateOp macro.

class ml_switcheroo.core.latex.nodes.ReturnNode[source]¶

Bases: LatexNode

Represents the output return statement. Maps to the \Return macro.

Example:

\Return{s3}
target_id: str¶

The variable ID to return.

to_latex() → str[source]¶

Render to \Return macro.

class ml_switcheroo.core.latex.nodes.ModelContainer[source]¶

Bases: LatexNode

Root container representing the Model definition block. Maps to the DefModel environment.

name: str¶

The model class name.

children: List[LatexNode] = []¶

List of body statements (Memory, Input, Ops, Return).

to_latex() → str[source]¶

Render the full \begin{DefModel}...\end{DefModel} block.