Repository navigation
Description
DELAY N and SMOOTH N (DELAYN/SMTHN) only compile when the order argument is the literal 1 or 3.
Any other order, including another literal and an expression of constants, is refused with UnknownBuiltin.
They should support any whole-number order that is fixed for the run.
Example
Output Second Order Delay = DELAY N(Input, Fractional Delay Time, Initial Value, 2)
Refused: "delayn of order 2 is not supported; use order 1 or 3".
A non-literal order is refused too, even when it can only be a constant.
thyroid-2008-d.mdl defines :MACRO: DELAYN(Input,DelayTime,Init,Order) with body DELAY N(Input,DelayTime,Init,Order) and calls it as DELAYN(TSH, tau, TSH, MAX(1, Delay Order)), where Delay Order is a constant slider (0-10).
The macro body is refused because Order is not a literal.
Why it matters
Seen in real models and in fixtures with Vensim output:
test/test-models/tests/delay_pipeline/test_pipeline_delays.mdluses order 2 and has a Vensim DSSoutput.tab.test/test-models/samples/Population/Subscripted Population Model.mdluses order 8.test/metasd/thyroid-dynamics/thyroid-2008-d.mdl, above.
Thyroid also needsDELAY MATERIAL(itsPIPELINEmacro), a pipeline delay the engine does not have; see engine: DELAY FIXED is refused instead of simulated #346.
Fix
Fold the order argument to a constant at compile time (it may reference only constants), and build an N-stage delay or smooth for that N instead of choosing between the order-1 and order-3 stdlib models.
Thyroid is the hard case: a macro expands as a module, so inside the body Order is a module input, not a constant, and the fold would have to see through the macro call.
Leaving thyroid refused is acceptable if that turns out messy.
An order that varies during the run is refused with a clear error, not supported: whether Vensim even allows one is unverified (vensim.com/documentation/fn_delay_n.html says only that Vensim lowers the order when delay time < order * TIME STEP).
Alternative: per-order stdlib models (delay2, ..., delay10).
Simpler to wire but caps the order and grows the stdlib.
Pointers
src/simlin-engine/src/builtins_visitor.rs:parse_module_order_arg,rewrite_alias_module_callsrc/simlin-engine/tests/integration/metasd_macros.rs: thyroid's entry- engine: DELAY FIXED is refused instead of simulated #346 (pipeline delays:
DELAY FIXED,DELAY MATERIAL)
Activity
[-]engine: DELAY N / SMOOTH N require a compile-time-constant order -- non-constant/parameterized order -> UnknownBuiltin (blocks full simulation of thyroid-2008-d and any dynamic-order delay/smooth)[/-][+]engine: DELAY N and SMOOTH N reject any order other than literal 1 or 3[/+]