This branch implements a new efficient routing tree structure for floweaver, transforming from a pull-based O(rows × edges) model to a push-based O(rows × tree_depth) model.
- ✅
TreeNode: Decision tree nodes with branches and leaf states (Assigned/Unclaimed/Blocked) - ✅
RoutingTree: Complete routing structure with bundle tree and edge mapping - ✅
route_row(): Routes a single row through the tree to find matching edges - ✅
route_flows(): Routes all flows and returns edge-to-rows mapping
- ✅ Step 1: Expand ProcessGroups to explicit process ID sets
- ✅ Step 2: Collect explicit branch point values
- ✅ Step 3: Build bundle tree with two-pass algorithm (non-Elsewhere, then Elsewhere)
- ✅ Step 4: Generate edges and map bundles to edges
⚠️ Partial: Basic edge generation (waypoints not fully handled)⚠️ Partial: Basic partition tree generation (needs refinement)
- ✅ Updated
execute_weave()to use routing tree when available - ✅ Backward compatibility with old filter-based specs
- ✅ Proper flow routing and aggregation
- ✅ Added
idfield toEdgeSpec - ✅ Added
routing_treefield toWeaverSpec - ✅ Updated JSON serialization
Equivalence Tests: 7 of 16 passing (43.75%)
TestBasicEquivalence::test_simple_two_nodesTestBasicEquivalence::test_accepts_dataframeTestElsewhereEquivalence::test_implicit_elsewhere_bundlesTestMeasureEquivalence::test_default_measureTestMeasureEquivalence::test_multiple_measuresTestOrderingEquivalence::test_ordering_with_bandsTestLinkWidthEquivalence::test_link_width_matches_value
- All
TestPartitionEquivalencetests (waypoint partitions not expanded) TestFlowPartitionEquivalence(flow partition handling incomplete)TestColorScaleEquivalence(depends on correct partitioning)TestGroupEquivalence(depends on correct partitioning)TestDirectionEquivalence(minor issue)TestOriginalFlowsEquivalence(minor issue)TestComplexRealWorldEquivalence(depends on waypoints/partitions)
-
Proper Waypoint Expansion: The
_generate_edges_for_bundle()function needs to traverse the view graph properly to expand waypoints into intermediate nodes. Currently it only generates direct source→target edges. -
Partition Tree Building: The
_build_partition_tree_for_bundle()function needs proper implementation for:- Flow partitions (material, etc.)
- Process partitions
- Multiple partition dimensions
- Catch-all groups
-
Flow Partition Handling: Flow partitions need to be properly integrated into the routing tree.
-
Edge Generation Details: Handle sequential edges, time partitions, and other edge attributes properly.
-
Test Updates: Update
test/test_compile.pyto match new compiled spec structure.
-
Optimization: The tree building could be optimized further.
-
Documentation: Add comprehensive documentation for the new system.
from floweaver import SankeyDefinition, ProcessGroup, Bundle, compile
from floweaver.execute import execute_weave
# Define diagram
nodes = {
'a': ProcessGroup(selection=['a1', 'a2']),
'b': ProcessGroup(selection=['b1']),
}
bundles = [Bundle('a', 'b')]
ordering = [['a'], ['b']]
sdd = SankeyDefinition(nodes, bundles, ordering)
# Compile (generates routing tree)
spec = compile(sdd)
# Execute against data
result = execute_weave(spec, dataset)-
Two-Pass Bundle Insertion: Non-Elsewhere bundles are inserted first, then Elsewhere bundles. This ensures proper priority and prevents internal flow leakage.
-
Pre-Populated Branches: All branch points are pre-populated during tree construction based on explicit values collected from all bundles. This ensures consistent tree structure.
-
Source Rechecks: Elsewhere bundles use source/target rechecks to block internal flows (e.g., when source=Elsewhere target=T, block flows where source is also in T).
-
Immutable Tree Nodes: Tree nodes use attrs without frozen=True, allowing in-place modification during construction while still being serializable.
-
Bundle-to-Edges Mapping: The routing tree maps bundle IDs to lists of edge IDs, supporting both simple (1 bundle → 1 edge) and complex (1 bundle → many edges) scenarios.
src/floweaver/router.py(new)src/floweaver/compile.py(rewritten)src/floweaver/spec.py(updated)src/floweaver/execute.py(updated)src/floweaver/compile_old.py(backup of original)
The highest priority is completing waypoint expansion in _generate_edges_for_bundle(). This requires:
- Understanding the view graph structure
- Traversing waypoints to create intermediate edges
- Handling partition expansion at waypoints
- Building appropriate partition trees for each bundle
Once waypoint handling is complete, most remaining tests should pass.