Skip to content

ltm: emit compile-time error when ltm_enabled is true and integration is non-Euler #486

Closed

Description

@bpowers

Summary

The 2023 flow-to-stock link-score formula assumes Euler integration: PREVIOUS(flow) - PREVIOUS(PREVIOUS(flow)) aligns the numerator to the causal interval that drove the stock change from t-1 to t. Under RK2/RK4 this alignment breaks and link scores become mathematically nonsensical. Nothing currently prevents a user from setting integration_method = RK4 and ltm_enabled = true; they get numbers that look plausible but are wrong.

Verification

RK4, Rk4, RungeKutta4, and integration_method appear nowhere in ltm_augment.rs, db_ltm.rs, or the LTM path through db.rs. There is no compile-time or runtime guard.

Locations

  • src/simlin-engine/src/ltm_augment.rs:762-784 -- the Euler-only flow-to-stock formula
  • src/simlin-engine/src/db.rs -- SourceProject carries ltm_enabled and ltm_discovery_mode but no integration_method awareness in the LTM path

Suggested fix

Emit a hard compile-time diagnostic (Error severity) when:

  • project.ltm_enabled(db) == true
  • AND the model's sim specs select a non-Euler integrator

The error message should reference the Euler assumption explicitly so users understand why the combination is rejected. This is a correctness guardrail; LTM scores under RK2/RK4 should not silently mislead.

Severity

medium (silent correctness when both options are enabled)

References

Activity

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

    @bpowers
    OwnerAuthor

    Fixed in PR #668 (merged as f9f850d). assemble_simulation now rejects LTM on non-Euler models with an Euler-assumption message, resolving the effective method exactly as the VM does (main model's sim_specs override, else project specs) and only when the assembled sim (root + transitively instantiated submodules) has stocks. Surfaces through simlin_sim_new, the wasm compile (WasmGenError::Unsupported), and pysimlin. Pinned by test_ltm_main_rk4_submodel_stock_is_rejected / test_ltm_submodel_rk4_override_main_euler_is_accepted (both red-verified) among others. The over-rejection of loop-free-stock models is tracked separately as #663.

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