Skip to content

Constrain use of 'delay' with zero delay time#3724

Open
henrikt-ma wants to merge 3 commits intomodelica:masterfrom
henrikt-ma:restrict-zero-delay-time
Open

Constrain use of 'delay' with zero delay time#3724
henrikt-ma wants to merge 3 commits intomodelica:masterfrom
henrikt-ma:restrict-zero-delay-time

Conversation

@henrikt-ma
Copy link
Collaborator

@henrikt-ma henrikt-ma commented Aug 27, 2025

This is a new take on #3245, picking up where it was left with the comment #3245 (comment). (I am revisiting this now because of my ongoing test implementation of delay with event generation.)

I think this solves the issue with an acceptable tradeoff between backwards compatibility and feasibility of actually implementing according to specification:

  • As @MarkusOlssonModelon seems to have suggested in phone meeting, delayTime = 0 is forbidden for time-varying delayTime.
  • In the two argument form delay(u, delayTime), the "new" evaluable variability is used to constrain delayTime, making it possible for tools to determine at translation time whether delayTime has been set to zero, but not forcing tools to evaluate.
  • By allowing delayTime = 0 in the two argument form, we avoid the need to give complicated rules for when it is an error to have delayTime = 0 in guarded expressions such as if tau > 0 then delay(u, tau) else u.
  • In principle, the funky technique of only evaluating delayTime when the value would be zero can be avoided by generating different equation systems for the two cases, and make an initialization time decision of which case to use. (Not expecting any tool to actually do it this way.)

Copy link
Collaborator

@HansOlsson HansOlsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hans:

  • Should add QoI for run-time check.
  • Would prefer that if parameter delayTime is non-evaluable it is still valid, but does not support delayTime=0.

@henrikt-ma
Copy link
Collaborator Author

Hans:

  • Should add QoI for run-time check.
  • Would prefer that if parameter delayTime is non-evaluable it is still valid, but does not support delayTime=0.

I have updated the text accordingly.

I think it would be good, though, to have a migration path for avoiding semantics depending on whether an expression is evaluable. It could be achieved with two deprecations:

  • Deprecate the two argument form with non-evaluable delayTime.
  • Deprecate allowing delayTime = 0 with the three argument form.

@HansOlsson HansOlsson added this to the 2025-October milestone Oct 1, 2025
@HansOlsson HansOlsson modified the milestones: 2025-October, 2025-December Dec 3, 2025
@HansOlsson
Copy link
Collaborator

Language meeting:
Seems an improvement to current work-around: if dt>0 then delay(x, dt) else x.

Has an implication for whether delay breaks algebraic loops; so decision must be made early (slightly complicated to not evaluate it if non-zero).

(Some people strongly want delay to be able to handle delay-time=0.)

@HansOlsson
Copy link
Collaborator

(Some people strongly want delay to be able to handle delay-time=0.)

I realized something: I only have second-hand reports that some people really want delay-time=0 and understand that it will not break algebraic loops (but instead be treated as if they delay wasn't present).

It would be good to have a confirmation of that, @casella

@HansOlsson
Copy link
Collaborator

I realized something: I only have second-hand reports that some people really want delay-time=0 and understand that it will not break algebraic loops (but instead be treated as if they delay wasn't present).

It would be good to have a confirmation of that, @casella

Pinging @casella (and others) in order to confirm the above, i.e., wanting delay-time=0 and not breaking algebraic loops.

@HansOlsson
Copy link
Collaborator

I realized something: I only have second-hand reports that some people really want delay-time=0 and understand that it will not break algebraic loops (but instead be treated as if they delay wasn't present).
It would be good to have a confirmation of that, @casella

Pinging @casella (and others) in order to confirm the above, i.e., wanting delay-time=0 and not breaking algebraic loops.

To me it is important to get confirmation for this; and not only 2nd hand reports.

The reason for stressing "not breaking algebraic loops" is that various forms of loop-breakers are common, and if the intent were to break algebraic loops, it doesn't make sense to add (somewhat complicated) semantics that doesn't handle that.

@HansOlsson
Copy link
Collaborator

Language group: the request is currently unclear - waiting for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants