Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow calling impure functions in clocked equations/statements #3614

Open
otronarp opened this issue Nov 22, 2024 · 4 comments
Open

Allow calling impure functions in clocked equations/statements #3614

otronarp opened this issue Nov 22, 2024 · 4 comments
Labels
discussion Indicates that there's a discussion; not clear if bug, enhancement, or working as intended

Comments

@otronarp
Copy link
Member

In 12.3 Pure Modelica Functions there is a list of situations where it's allowed to call an impure function, it doesn't mention clocked equations/statements. Shouldn't it be allowed there as well?

model M
  Clock c = Clock(1);
  Real x;
  Real y;
equation
  x = sample(time, c);
  y = impureFunction(x);
end M;

Feels a bit unnecessary to require the y = ... to be wrapped with when Clock() then.

@HansOlsson HansOlsson added the discussion Indicates that there's a discussion; not clear if bug, enhancement, or working as intended label Nov 22, 2024
@HansOlsson
Copy link
Collaborator

HansOlsson commented Nov 22, 2024

On one hand I see that point, but on the other hand I see a problem with usability and diagnostics.

Consider:

model M
  input Real x;
  output Real y;
equation
  y = impureFunction(x);
end M;

model A
  M m(x=sample(time, Clock(1));
end A;

Here the call is ok in A - but in M it would not be legal as it is not clocked. Assuming we want to allow the first model, the question is what to do with M:

  • Say that it is illegal and have some weird rule that it must be clocked in the same model. (Not clear how.)
  • Say that it is legal in A and give diagnostics for M ignoring that possibility. (Users of the feature will complain.)
  • Say that it is legal in A and give diagnostics for M including that possibility, which will mean that every use of impure functions we have to include it.

Based on that I find the idea of explicitly making it clocked

model M
  input Real x;
  output Real y;
equation
  when Clock() then
    y = impureFunction(x);
  end when;
end M;

an acceptable way of writing to avoid all of that.

@HansOlsson
Copy link
Collaborator

As follow-up, having some other way of making models/blocks clocked is also something we could consider, but we would then need to differentiate between a model being clocked, vs. clocked with one clock.

@otronarp
Copy link
Member Author

I your example I would say M is illegal therefore A is also illegal.

@HansOlsson
Copy link
Collaborator

I your example I would say M is illegal therefore A is also illegal.

But if they are illegal, I find it difficult to say that the equations are legal "just" because it is part of the same model (I realize that the discussion would benefit from having different names for the different models :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Indicates that there's a discussion; not clear if bug, enhancement, or working as intended
Projects
None yet
Development

No branches or pull requests

2 participants