Skip to content

mdl: saving rewrites a + b * Time as TIME BASE(a, b) #848

Open

Description

@bpowers

Saving to MDL rewrites any equation of the form a + b * Time as TIME BASE(a, b).
The two mean the same thing, but the modeler's equation comes back in a function they never wrote and may not recognize.

Example

test/test-models/tests/allocate_available/test_allocate_available.mdl has

priority1 sep[Boston,ppriority] = 5+0.1*Time

and saving it as MDL writes the element's equation as TIME BASE(5, 0.1).

Why it matters

Cosmetic but confusing: a user opening the saved file in Vensim sees an obscure function in place of their own arithmetic.
The rewrite exists only to undo the importer, which expands TIME BASE(t, dt) into t + (dt) * TIME; once expanded, the two spellings are the same expression and the writer cannot tell them apart.
No .mdl in test/ calls TIME BASE.

The other problems this issue listed (a model with no time units gaining one on save, the settings section reading a macro's sim specs) are fixed, and a second save of any corpus file is now byte-identical to the first (writer_output_idempotence_ratchet).

Fix

Remove the TIME BASE recognizer and write the expression as arithmetic.
A model that did use TIME BASE then saves as t + dt * Time, which Vensim reads the same (vensim.com/documentation/fn_time_base.html: "equivalent to (START + Time*SLOPE)").

Alternative: have the importer keep TIME BASE as a call the engine knows, so the writer has something to recognize.
That is more code for a function no corpus model uses.

Pointers

  • src/simlin-engine/src/mdl/writer.rs: recognize_time_base and its caller
  • src/simlin-engine/src/mdl/xmile_compat.rs: the "time base" expansion
  • src/simlin-engine/src/mdl/writer_tests.rs: pattern_time_base; writer_fixpoint_tests.rs has a time base row

Activity

  1. changed the title [-]engine: MDL writer round-trip is not idempotent (time_units gain, TIME BASE rewrite, NaN emission, wrong sim_specs model)[/-] [+]mdl: saving rewrites a + b * Time as TIME BASE(a, b)[/+] on Oct 12, 2026
  2. added
    engine
    bug
    on Oct 12, 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

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions