Skip to content

ltm: non-Euler (#486) guard over-rejects models whose stocks are in no feedback loop #663

Closed

Description

@bpowers

Problem

The GH #486 non-Euler guard in assemble_simulation (src/simlin-engine/src/db/assemble.rs, around lines 1577-1590) rejects an RK2/RK4 + LTM compile whenever any instantiated model has stocks:

if project.ltm_enabled(db)
    && let Some(root_model) = project_models.get(main_model_canonical.as_ref())
    && let Some(method) = ltm::effective_non_euler_method(db, *root_model, project)
{
    let any_stocks = module_instances.keys().any(|name| {
        let canonical = canonicalize(name.as_str());
        project_models
            .get(canonical.as_ref())
            .is_some_and(|sm| !model_causal_edges(db, *sm, project).stocks.is_empty())
    });
    if any_stocks {
        return Err(ltm::ltm_non_euler_diagnostic_message(method));
    }
}

The guard exists because the LTM flow-to-stock link-score formula assumes Euler integration and is mathematically meaningless under RK2/RK4 -- but it only matters when LTM actually emits flow-to-stock scores. A model whose stocks are in no feedback loop produces zero LTM synthetic vars in exhaustive mode (verified empirically), so for such a model the rejection is a false positive: there is no flow-to-stock score for the non-Euler method to corrupt.

The guard tests "has stocks," but the precondition that actually matters is "has a stock in a feedback loop" (i.e. LTM emits at least one flow-to-stock link score). Presence of a stock != stock participating in a loop.

Why it matters

A perfectly valid RK4 model with stocks but no feedback (e.g. an open-loop accumulation with LTM enabled for inspecting auxiliary-to-auxiliary links) is rejected at compile time even though LTM would produce nothing that the non-Euler method could make wrong. The current behavior is defensible conservatism (inherited from the first #486 commit) but is strictly over-broad.

Components affected

  • src/simlin-engine/src/db/assemble.rs (assemble_simulation, the non-Euler stocks gate)

Possible approaches

Gate the rejection on whether the assembled LTM actually emits any flow-to-stock link score (e.g. consult model_ltm_variables / the loop set for the instantiated models) rather than on the mere presence of a stock. Reject only when a stock participates in a feedback loop that produces a flow-to-stock score.

Severity

Low (over-conservative rejection of a valid edge-case model; never produces wrong numbers -- it errors instead).

Relationship to #486

#486 is the original "emit the non-Euler guard" issue (the guard now exists). This is a follow-up refinement narrowing the guard's precondition so it stops firing on loop-free models.

Discovery context

Identified during an LTM-hardening session while reviewing the #486 guard's precondition.

Part of epic #488.

Activity

  1. added
    engine
    ltm
    on Jun 2, 2026
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