Skip to content

ltm: dedup by node set merges distinct directed loops #308

Closed

Description

@bpowers

Summary

Loop deduplication is currently done by sorted node set, which merges distinct directed loops that traverse the same variables in different orders/directions.

Why this is a problem

In feedback analysis, loop identity is defined by directed causal structure (ordered links), not just the set of participating variables. Collapsing by node set can remove structurally distinct loops and alter loop counts, reported polarity composition, and score attribution.

Literature / algorithm alignment

The LTM literature discusses distinct loops in directed graphs and evaluates discovery completeness against exhaustive directed-loop enumeration. Treating two different directed cycles as one because they share nodes is not equivalent to elementary circuit identity.

Current implementation behavior

  • Exhaustive path dedup (ltm.rs) key = sorted from node names.
  • Discovery dedup (ltm_finding.rs) key = sorted node names from DFS stack.
  • Integration test notes this explicitly in arms-race expectations (7 instead of 8 due reverse three-way loop collapse).

Locations:

  • src/simlin-engine/src/ltm.rs (deduplicate_loops)
  • src/simlin-engine/src/ltm_finding.rs (add_loop_if_unique)
  • src/simlin-engine/tests/simulate_ltm.rs (discovery_arms_race_3party comments)

Impact

  • Distinct loops can be lost, especially in symmetric systems where opposite-direction cycles exist over same node set.
  • Discovery-vs-exhaustive comparisons may look better/worse for the wrong reason (identity mismatch).

Success criteria

  1. Define loop identity using directed edges (canonicalized by rotation, but preserving orientation/order), not node-set membership.
  2. Apply the same identity rule in both exhaustive and discovery paths.
  3. Update tests to validate that opposite-direction cycles on the same node set are represented as distinct loops when structurally distinct.
  4. Revisit affected expected loop counts (e.g., arms race fixtures) under the corrected identity.
  5. Ensure deterministic IDs still remain stable across runs with the new identity rule.

Notes

This issue does not request any change to the known flow-to-stock time alignment decision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions