Skip to content

engine: stock/flow unit check uses 'time' instead of the time unit #455

Closed

Description

@bpowers

Stock/flow unit checks compare a flow's units against stock units / time, using the literal unit name time instead of the model's time unit.
A model whose time unit is year then reports every correctly annotated flow as a mismatch.

Example

simlin simulate --no-output test/metasd/WRLD3-03/wrld3-03.mdl (time unit year, read from TIME STEP) printed 20+ lines like:

units error in model 'main' variable 'resource_usage_rate': unit_mismatch -- expected units 'resource_units/year' to match the units expected by the attached stock nonrenewable_resources (resource_units/time)
units error in model 'main' variable 'land_life_multiplier_from_land_yield': unit_mismatch -- expected left and right argument units to match, but 'time' and 'year' don't

Why it matters

The stock/flow check is the most useful unit check in SD, and this made it noise on any model whose time unit is not literally time.
Seen on World3.

Fix

The cause on World3 was upstream of the check: the units context failed to build (World3's footer repeats each 22: equivalence line, which was rejected as a duplicate), and the engine fell back to an empty context.
An empty context has neither the model's time unit nor its unit aliases, so time stood in for year.
The time unit should always come from the model's settings, resolved through unit aliases, even when some unit declarations are bad.
Confirm on World3 that no time vs year mismatch remains.

Pointers

Activity

  1. added
    engine
    on Jun 8, 2026
  2. changed the title [-]engine: unit checker cannot unify 'year' with the implicit 'time' unit of stocks[/-] [+]engine: stock/flow unit check uses 'time' instead of the time unit[/+] on Oct 12, 2026
  3. added
    bug
    on Oct 12, 2026
  4. bpowers commented on Oct 12, 2026

    @bpowers
    OwnerAuthor

    Closing: already fixed on main.

    The empty-context fallback is gone: Context::new cannot fail and always carries sim_specs.time_units (src/simlin-engine/src/units.rs:405-409; db/query.rs:69-83). The stock/flow check and inference both take the time unit from model_time_units/resolve_name, through aliases (units_check.rs:488-495, 582; units_infer.rs:969-979), pinned by aliased_time_unit_does_not_cause_inference_mismatch and context_construction_keeps_valid_units_despite_a_conflict (units.rs:902).

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

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions