Skip to content

ltm: rel_loop_score normalisation cross-pollutes independent A2A loops #487

Closed

Description

@bpowers

Summary

The LTM partition map keys on element-level stock names (e.g., population[nyc]) because it is built from model_element_cycle_partitions. For pure-dimension A2A loops, however, build_element_level_loops calls var_graph.find_stocks_in_loop(&var_level_nodes) and stores variable-level stock names (e.g., population) in Loop::stocks. partition_for_loop then does find_map(|s| stock_partition.get(s)) and the lookup misses, so every A2A loop returns partition = None.

The behaviour is now formalised in ltm.rs:114-118 as a deliberate design invariant and tests/layout.rs:779-798 documents it, but the underlying normalisation gap remains: compute_rel_loop_scores* normalises against partition denominators, so multiple independent A2A loops all land in the same fictitious "no parent" bucket and their relative scores cross-normalise against unrelated partitions.

Why this matters

  • Models with multiple disconnected A2A feedback subsystems get incorrect rel-scores (cross-normalised together instead of partition-local).
  • Mixed (A2A + scalar) partitions never arise in practice because the engine always assigns A2A loops to None. A latent bug in the layout aggregation for mixed-stride partitions exists but can only be triggered through hand-crafted helper inputs (see codex review on PR ltm: per-element relative loop scores via subscripted IDs #472).

Locations

  • src/simlin-engine/src/ltm.rs::CyclePartitions::partition_for_loop -- the lookup that misses for A2A loops
  • src/simlin-engine/src/db_ltm.rs:2098-2099 -- build_element_level_loops populates variable-level names for A2A loops
  • src/simlin-engine/src/db_ltm.rs:2171-2202 -- cross-element branch correctly uses element-level names
  • src/simlin-engine/src/ltm_post.rs:73-131, 178-179 -- compute_rel_loop_scores and compute_rel_loop_scores_per_element use the broken partition keys
  • src/simlin-engine/tests/layout.rs:779-798, 801 -- test_compute_metadata_importance_series_length_matches_step_count documents the quirk

Suggested fix

Two options trade off:

  • (a) element-level stocks for A2A loops: change Loop::stocks for A2A loops to carry one element-level name per element of the A2A dim (all in the same SCC by construction). Local fix, but changes the Loop struct's semantic; downstream consumers (enumerate_module_pathways and others) may need updates.
  • (b) expansion in partition_for_loop: keep Loop::stocks as variable-level names but extend partition_for_loop to expand each variable-level stock to its element-level instances and look those up. Type-stable, but adds lookup complexity.

Either fix needs to confirm that enumerate_module_pathways and other Loop::stocks consumers still get the names they expect.

Severity

medium (silent correctness for multi-A2A-loop models)

References

Activity

  1. added
    engine
    ltm
    on May 1, 2026
  2. bpowers commented on May 13, 2026

    @bpowers
    OwnerAuthor

    Resolved by 11eb1af, 40bf7d5, f26330f, c3318a2 — Phase 2 of the LTM arrays hardening plan (docs/design-plans/2026-05-11-ltm-arrays-hardening.md). A2A Loop::stocks now carries element-level stock names; loop_partitions is keyed per slot (HashMap<String, Vec<Option<usize>>>); relative loop scores normalise per-(partition, slot), so an independent A2A loop no longer cross-pollutes a sibling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions