Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ucbepic Docetl MOAR Node

From Leeroopedia


Knowledge Sources
Domains Data_Processing, Optimization, Search_Algorithms
Last Updated 2026-02-08 00:00 GMT

Overview

Concrete tool for representing states in a Monte Carlo Tree Search (MCTS) tree for pipeline optimization provided by DocETL.

Description

The Node class represents a single state in the MCTS search tree used by the MOAR (Multi-Objective Automated Rewriting) optimizer. Each node holds a YAML pipeline configuration, maintains visit counts and accumulated values for UCB (Upper Confidence Bound) selection, and tracks parent-child relationships for tree traversal. Nodes can execute their pipeline plans via DSLRunner, compute UCB scores, and manage a memo of applied directives from root to the current node.

Usage

Use this class when implementing or extending the MOAR search algorithm for DocETL pipeline optimization. Nodes are created during tree expansion and evaluated during simulation phases of MCTS.

Code Reference

Source Location

Signature

class Node:
    _id_counter = 0

    @classmethod
    def get_next_id(cls) -> int: ...

    @classmethod
    def increment_id_counter(cls) -> int: ...

    def __init__(
        self,
        yaml_file_path: str,
        parent: Optional[Node] = None,
        c: float = 1.414,
        message_history=[],
        id: Optional[int] = None,
        is_multi_instance: bool = False,
        console=None,
    ): ...

    def execute_plan(self, max_threads: Optional[int] = None) -> tuple[float, list]: ...
    def best_child(self) -> Node: ...
    def add_child(self, child: Node): ...

Import

from docetl.moar.Node import Node

I/O Contract

Inputs

Name Type Required Description
yaml_file_path str Yes Path to the YAML pipeline configuration file for this node
parent Optional[Node] No Parent node in the search tree (None for root)
c float No Exploration constant for UCB calculation (default: 1.414 = sqrt(2))
message_history list No Accumulated LLM conversation history from root to this node
id Optional[int] No Explicit unique ID (auto-assigned if not provided)
is_multi_instance bool No Whether this node is a multi-instance candidate
console object No Console instance for logging (defaults to DOCETL_CONSOLE)

Outputs

Name Type Description
cost float Total execution cost from running the pipeline (-1 on failure)
sample_result list Sample output data extracted from the pipeline execution
value float Accumulated reward value from backpropagation
visits int Number of times this node has been visited in MCTS

Usage Examples

from docetl.moar.Node import Node

# Create a root node from a YAML pipeline file
root = Node(yaml_file_path="pipeline.yaml", c=1.414)

# Execute the pipeline plan
total_cost = root.execute_plan()

# Select the best child based on UCB score
best = root.best_child()

# Access node properties
print(f"Node {root.id}: visits={root.visits}, value={root.value}, cost={root.cost}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment