-
Notifications
You must be signed in to change notification settings - Fork 299
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
Implement Base Modelica output #11820
Comments
Adding @mtiller, @mscuttari, @fedetft, @danielecattaneo, @adrpo to the loop. |
We could also at some point implement an online service that gets a .mo file and the name of the class that must be flattened, and returns its BaseModelica output. As long as the code is not confidential and it only depends on open source libraries that are referenced by the uses annotation and included in our Package Manager list, it should work out of the box. |
#11853 encloses everything in a package with the same name as the model. I also moved function and record declarations to outside the model, previously everything was contained in the model but with the package there's no need for that. I also noticed two issues:
|
Sounds good. I though it would be the same, but it isn't, because a function inside a model can still access components of the model via lookup, right?
Are you sure? There is an example in the paper at page 6 with protected variable declarations in functions.
Maybe it's not necessary to do so. We need to check further
Why should it? The Base Modelica does not describe how you lower a Modelica model into Base Modelica, it only describes the grammar and semantics of Base Modelica. As I understand, any legal Modelica classname would be ok, including the quoted full path |
I guess we should also keep a list of known issue with our implementation at the beginning of this ticket, and keep it up to date. |
It says so here, see section "Protected" towards the end of the page.
I didn't see any examples using the fully qualified path, but I guess there's also nothing saying you can't use it. It just seemed a bit weird having to write:
But I guess I'll just leave it as it is for now. |
True. I wrote a comment on the the PR that introduced that part, maybe we get some feedback about it. I guess it was an oversight.
Yes. And the relevant section of the proposal states clearly that it's not needed in function declarations. So, we just remove protected when generating |
It absolutely is, of course 😄 . I hadn't thought about that. Please just use the class name, not the fully qualified one. At the end of the day, the name could also be "X" (Elon would love it), since there is only one package and one model in a Base Modelica model. |
#11874 changes it to use the class name instead of the fully qualified path. Additionally, #11875 renames the existing Also, in your example you used |
@perost I am not sure we should remove flags so lightly or, even worse, keep them with a different meaning. People use them, and their code will be broken as a result. I would suggest to maybe deprecate
Sorry, which example do you refer to? |
As far as I know no one is actually using As for changing it to
You gave two cases, one scalar and one with arrays, in the issue description. |
Could be, but we don't really know what people are doing out there. No reason to make them angry.
I would stick to
Agreed. That was also my idea. As to array preserving, at the moment we have two variants: preserve arrays and collect classes into arrays. |
Sure, but we're talking about a flag whose description makes it clear that it's experimental, and we've changed the output numerous times since adding it without anyone saying a word.
Everyone currently known to use the flag uses the short flag though, I didn't even remember it had a long form myself until I checked the flag definition. The issue is just that the short form of |
Fair enough 😃
Go for |
@perost I prepared a small demo I'd like to show around. It contains all the basic ingredients: models, functions, and record. The --BaseModelica output seems fine for me, except for the protected keyword in the function declaration. Can you please suppress that, as we agreed here? Thanks! |
Fixed in #11931. I also changed the frontend to not check that non-input/output parameters in functions are protected when It's maybe not a good idea to have the same flag for compiling Base Modelica as outputting Base Modelica, it should probably be based on e.g. file extension instead to be more flexible. But until that's standardised I guess this is fine. |
For input, MCP 0031 defines a version header, e.g. @perost I guess you can implement that already, maybe you can ignore the version number for the time being, as it is still not well defined. |
The new Base Modelica standard, presented in this paper at the Aachen Modelica Conference, is currently in draft form within MCP0031.
OpenModelica has supported flat Modelica output for quite some time, via the -f compiler flag. During the last two years, we used this feature to provide a frontend to the MARCO compiler (see paper), adding some more flags that produce an output that is very close to what is required by Base Modelica. Currently, there are two possible setups:
-f -d=printRecordTypes --showStructuralAnnotations
-f -d=nonfScalarize,arrayConnect,combineSubscripts,printRecordTypes,vectorizeBindings --showStructuralAnnotations
Setup 2. is particularly interesting for large models containing huge arrays, as it provides a compact representation that can be used for efficient code generation.
We should finalize BaseModelica output with the following actions:
--baseModelica
compiler flag, with optional arguments such as--baseModelica=preserveArrays
, to provide the same effect as the flag combinations reported aboveThis would give us a first fairly complete implementation of Base Modelica, available as open-source software.
The text was updated successfully, but these errors were encountered: