Skip to content

ltm: extend composite module scoring beyond implicit stdlib modules #306

Closed

Description

@bpowers

Summary

Simlin classifies user-defined modules with internal stocks as DynamicModule, but composite/pathway LTM instrumentation is only generated for implicit (stdlib) models. As a result, user-defined dynamic modules do not get composite link scores and are analyzed with the black-box fallback.

Why this is a problem

The LTM integration papers treat hidden internal structure (macros/modules) via composite path scores so loop attribution remains faithful to the expanded causal structure. Restricting composites to stdlib modules breaks that equivalence for user-defined modules that are structurally identical to stdlib dynamics (stocks, flows, multiple internal paths).

Concretely, links into user-defined dynamic modules can be scored with the black-box formula instead of per-path composite scores, which can change discovered loop importance and relative loop scores.

Literature / algorithm alignment

  • Reference doc: Section 6 (Handling Macros), especially 6.3 and 6.7.
  • Design doc states the macro handling approach should generalize to modules.

Expected algorithmic behavior: for any dynamic module boundary, compute internal pathway scores and use max-abs composite score at each timestep for boundary link scoring.

Current implementation behavior

  • Dynamic classification includes user modules with stocks:
    • src/simlin-engine/src/ltm.rs (classify_module_for_ltm)
  • Composite port precomputation is limited to model.implicit == true:
    • src/simlin-engine/src/ltm_augment.rs (compute_composite_ports)
  • Internal ilink/path/composite variable generation is also limited to model.implicit == true:
    • src/simlin-engine/src/ltm_augment.rs (generate_ltm_variables_inner)

Impact

  • User-defined dynamic modules can be systematically under-instrumented compared to stdlib modules.
  • Loop dominance results can depend on whether structure is packaged as stdlib macro vs user module.

Success criteria

  1. Composite port detection runs for all DynamicModule models that are instantiated in analyzed models, not only implicit stdlib models.
  2. Internal ilink/path/composite synthetic variables are generated for those dynamic modules as well.
  3. Parent boundary links to those modules use composite references when a valid input-port→output pathway exists.
  4. Add tests showing equivalent LTM loop/link scoring for:
    • a stdlib dynamic module case
    • an isomorphic user-defined dynamic module case
  5. Document any intentional exceptions (if some module classes cannot be instrumented safely).

Notes

This issue is separate from the known flow-to-stock timing shift behavior.

Activity

  1. bpowers commented on Apr 30, 2026

    @bpowers
    OwnerAuthor

    Fixed in commit 01970ba ("engine: unified LTM module composite scoring (#416)").

    The model.implicit == true gate that previously limited composite/pathway generation to stdlib macros has been removed. compute_composite_ports no longer exists; pathway/composite generation now runs for any model (stdlib or user-defined) with detected input ports.

    • The output-port detection that drives this path is now find_model_output_ports_for_module (src/simlin-engine/src/db.rs), which scans parent models for module.internal_var references to detect output ports for any user-defined dynamic module.
    • Composite/pathway emission lives in model_ltm_variables (src/simlin-engine/src/db_ltm.rs:2902-2963); the gate is now has_input_ports = !pathways.is_empty() (db_ltm.rs:2417), independent of stdlib provenance.
    • Confirmed by test_ltm_module_with_non_standard_output_name in db_ltm_module_tests.rs:206, which exercises composite scoring on a user-defined module with a non-standard output name.

    Verified on main at HEAD 630fceb (2026-04-29).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions