Skip to content

Commit

Permalink
proper speedup for updateComponent #5620
Browse files Browse the repository at this point in the history
- new API updateComponentStr that can be called directly via Qt API
- use the new Qt API from OMEdit
- fix the differences between NFModelicaBuiltin.mo and ModelicaBuiltin.mo
  • Loading branch information
adrpo committed Sep 24, 2020
1 parent 2a078a0 commit 76de683
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 86 deletions.
16 changes: 14 additions & 2 deletions OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -831,7 +831,7 @@ record SimulationResult
String simulationOptions;
String messages;
end SimulationResult; */
encapsulated package OpenModelica "OpenModelica internal defintions and scripting functions"
encapsulated package OpenModelica "OpenModelica internal definitions and scripting functions"

type $Code "Code quoting is not a uniontype yet because that would require enabling MetaModelica extensions in the regular compiler.
Besides, it has special semantics."
Expand Down Expand Up @@ -2578,7 +2578,7 @@ external "builtin";
annotation(preferredView="text");
end buildModel;

function buildLabel "builds Lable."
function buildLabel "builds Label."
input TypeName className "the class that should be built";
input Real startTime = 0.0 "the start time of the simulation. <default> = 0.0";
input Real stopTime = 1.0 "the stop time of the simulation. <default> = 1.0";
Expand Down Expand Up @@ -3240,6 +3240,18 @@ annotation(preferredView="text",Documentation(info="<html>
</html>"));
end updateConnection;

function updateConnectionStr
input TypeName className;
input String from;
input String to;
input String annotate;
output Boolean result;
external "builtin";
annotation(preferredView="text",Documentation(info="<html>
<p>Updates the connection annotation in the class. See also updateConnectionNames().</p>
</html>"));
end updateConnectionStr;

function updateConnectionNames
input TypeName className;
input String from;
Expand Down
135 changes: 122 additions & 13 deletions OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo
Expand Up @@ -1363,9 +1363,20 @@ external "builtin";
annotation(preferredView="text");
end loadFiles;

function parseEncryptedPackage
input String fileName;
input String workdir = "<default>" "The output directory for imported encrypted files. <default> will put the files to current working directory.";
output TypeName names[:];
external "builtin";
annotation(Documentation(info="<html>
<p>Parses the given encrypted package and returns the names of the parsed classes.</p>
</html>"), preferredView="text");
end parseEncryptedPackage;

function loadEncryptedPackage
input String fileName;
input String workdir = "<default>" "The output directory for imported encrypted files. <default> will put the files to current working directory.";
input Boolean skipUnzip = false "Skips the unzip of .mol if true. In that case we expect the files are already extracted e.g., because of parseEncryptedPackage() call.";
output Boolean success;
external "builtin";
annotation(Documentation(info="<html>
Expand Down Expand Up @@ -1489,6 +1500,13 @@ external "builtin";
annotation(preferredView="text");
end generateHeader;

function generateJuliaHeader
input String fileName;
output Boolean success;
external "builtin";
annotation(preferredView="text");
end generateJuliaHeader;

function generateSeparateCode
input TypeName className;
input Boolean cleanCache = false "If true, the cache is reset between each generated package. This conserves memory at the cost of speed.";
Expand Down Expand Up @@ -1710,6 +1728,18 @@ external "builtin";
annotation(preferredView="text");
end setCompilerFlags;

function enableNewInstantiation
output Boolean success;
external "builtin";
annotation(preferredView="text");
end enableNewInstantiation;

function disableNewInstantiation
output Boolean success;
external "builtin";
annotation(preferredView="text");
end disableNewInstantiation;

function setDebugFlags "example input: failtrace,-noevalfunc"
input String debugFlags;
output Boolean success;
Expand Down Expand Up @@ -2202,6 +2232,14 @@ external "builtin";
annotation(preferredView="text");
end mkdir;

function copy "copies the source file to the destination file. Returns true if the file has been copied."
input String source;
input String destination;
output Boolean success;
external "builtin";
annotation(preferredView="text");
end copy;

function remove "removes a file or directory of given path (which may be either relative or absolute)."
input String path;
output Boolean success "Returns true on success.";
Expand Down Expand Up @@ -2322,7 +2360,7 @@ function saveTotalModel "Save the className model in a single file, together wit
which loads className and all the other needed classes into memory.
This is useful to allow third parties to run a certain model (e.g. for debugging)
without worrying about all the library dependencies.
Please note that SaveTotal file is not a valid Modelica .mo file according to the
Please note that SaveTotal file is not a valid Modelica .mo file according to the
specification, and cannot be loaded in OMEdit - it can only be loaded with loadFile()."
input String fileName;
input TypeName className;
Expand Down Expand Up @@ -2491,6 +2529,7 @@ end list;

function listFile "Lists the contents of the file given by the class."
input TypeName class_;
input Boolean nestedClasses = true;
output String contents;
external "builtin";
annotation(Documentation(info="<html>
Expand Down Expand Up @@ -2681,8 +2720,8 @@ end buildModelFMU;

function buildEncryptedPackage
input TypeName className "the class that should encrypted";
input Boolean encrypt = true;
output Boolean success;
output String commandOutput "Output of the packagetool executable";
external "builtin";
annotation(preferredView="text");
end buildEncryptedPackage;
Expand Down Expand Up @@ -2941,7 +2980,7 @@ annotation(preferredView="text");
end getPackages;

function getAllSubtypeOf
"Returns the list of all classes that extend from class_ given a parentClass where the lookup for class_ should start"
"Returns the list of all classes that extend from className given a parentClass where the lookup for className should start"
input TypeName className;
input TypeName parentClass = $TypeName(AllLoadedClasses);
input Boolean qualified = false;
Expand Down Expand Up @@ -3103,6 +3142,12 @@ external "builtin";
annotation(Documentation(info="<html>
<p>Takes one simulation result and filters out the selected variables only, producing the output file.</p>
<p>If numberOfIntervals<>0, re-sample to that number of intervals, ignoring event points (might be changed in the future).</p>
<p>if removeDescription=true, the description matrix will contain 0-length strings, making the file smaller.</p>
</html>",revisions="<html>
<table>
<tr><th>Revision</th><th>Author</th><th>Comment</th></tr>
<tr><td>1.13.0</td><td>sjoelund.se</td><td>Introduced removeDescription.</td></tr>
</table>
</html>"),preferredView="text");
end filterSimulationResults;

Expand Down Expand Up @@ -3256,7 +3301,7 @@ function getComponentModifierValue
external "builtin";
annotation(
Documentation(info="<html>
<p>Returns the modifier value (only the binding exculding submodifiers) of component.
<p>Returns the modifier value (only the binding excluding submodifiers) of component.
For instance,
model A
B b1(a1(p1=5,p2=4));
Expand Down Expand Up @@ -3300,63 +3345,68 @@ annotation(
end removeComponentModifiers;

function getElementModifierNames
input TypeName class_;
input String componentName;
input TypeName className;
input String elementName;
output String[:] modifiers;
external "builtin";
annotation(
Documentation(info="<html>
Returns the list of class component modifiers.
Returns the list of element (component or short class) modifiers in a class.
</html>"),
preferredView="text");
end getElementModifierNames;

function getElementModifierValue
input TypeName class_;
input TypeName className;
input TypeName modifier;
output String value;
external "builtin";
annotation(
Documentation(info="<html>
<p>Returns the modifier value (only the binding exculding submodifiers) of component.
<p>Returns the modifier value (only the binding excluding submodifiers) of element (component or short class).
For instance,
model A
B b1(a1(p1=5,p2=4));
model X = Y(a1(p1=5,p2=4));
end A;
getElementModifierValue(A,b1.a1.p1) => 5
getElementModifierValue(A,b1.a1.p2) => 4
getElementModifierValue(A,X.a1.p1) => 5
getElementModifierValue(A,X.a1.p2) => 4
See also <a href=\"modelica://OpenModelica.Scripting.getElementModifierValues\">getElementModifierValues()</a>.</p>
</html>"),
preferredView="text");
end getElementModifierValue;

function getElementModifierValues
input TypeName class_;
input TypeName className;
input TypeName modifier;
output String value;
external "builtin";
annotation(
Documentation(info="<html>
<p>Returns the modifier value (including the submodfiers) of component.
<p>Returns the modifier value (including the submodfiers) of element (component or short class).
For instance,
model A
B b1(a1(p1=5,p2=4));
model X = Y(a1(p1=5,p2=4));
end A;
getElementModifierValues(A,b1.a1) => (p1 = 5, p2 = 4)
getElementModifierValues(A,X.a1) => (p1 = 5, p2 = 4)
See also <a href=\"modelica://OpenModelica.Scripting.getElementModifierValue\">getElementModifierValue()</a>.</p>
</html>"),
preferredView="text");
end getElementModifierValues;

function removeElementModifiers
input TypeName class_;
input TypeName className;
input String componentName;
input Boolean keepRedeclares = false;
output Boolean success;
external "builtin";
annotation(
Documentation(info="<html>
Removes the component modifiers.
Removes the element (component or short class) modifiers.
</html>"),
preferredView="text");
end removeElementModifiers;
Expand Down Expand Up @@ -3385,6 +3435,43 @@ annotation(
preferredView="text");
end removeExtendsModifiers;

function updateConnection
input TypeName className;
input String from;
input String to;
input ExpressionOrModification annotate;
output Boolean result;
external "builtin";
annotation(preferredView="text",Documentation(info="<html>
<p>Updates the connection annotation in the class. See also updateConnectionNames().</p>
</html>"));
end updateConnection;

function updateConnectionStr
input TypeName className;
input String from;
input String to;
input String annotate;
output Boolean result;
external "builtin";
annotation(preferredView="text",Documentation(info="<html>
<p>Updates the connection annotation in the class. See also updateConnectionNames().</p>
</html>"));
end updateConnectionStr;

function updateConnectionNames
input TypeName className;
input String from;
input String to;
input String fromNew;
input String toNew;
output Boolean result;
external "builtin";
annotation(preferredView="text",Documentation(info="<html>
<p>Updates the connection connector names in the class. See also updateConnection().</p>
</html>"));
end updateConnectionNames;

function getConnectionCount "Counts the number of connect equation in a class."
input TypeName className;
output Integer count;
Expand Down Expand Up @@ -4102,6 +4189,18 @@ Returns the libraries used by the package {{\"Library1\",\"Version\"},{\"Library
preferredView="text");
end getUses;

function getConversionsFromVersions
input TypeName pack;
output String[:] withoutConversion;
output String[:] withConversion;
external "builtin";
annotation(
Documentation(info="<html>
Returns the versions this library can convert from with and without conversions.
</html>"),
preferredView="text");
end getConversionsFromVersions;

function getDerivedClassModifierNames "Returns the derived class modifier names.
Example command:
type Resistance = Real(final quantity=\"Resistance\",final unit=\"Ohm\");
Expand Down Expand Up @@ -5097,6 +5196,16 @@ annotation(
</html>"), preferredView="text");
end relocateFunctions;

function toJulia
output String res;
external "builtin";
end toJulia;

function interactiveDumpAbsynToJL
output String res;
external "builtin";
end interactiveDumpAbsynToJL;

end Experimental;

end Scripting;
Expand Down
20 changes: 17 additions & 3 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -689,7 +689,6 @@ algorithm
list<String> vars_1,args,strings,strs,strs1,strs2,visvars,postOptModStrings,postOptModStringsOrg,mps,files,dirs,modifiernamelst;
Real timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2,r,r1,r2,linearizeTime,curveWidth,offset,offset1,offset2,scaleFactor,scaleFactor1,scaleFactor2;
GlobalScript.Statements istmts;
list<GlobalScript.Statements> istmtss;
Boolean have_corba, bval, anyCode, b, b1, b2, b3, b4, b5, externalWindow, logX, logY, autoScale, forceOMPlot, gcc_res, omcfound, rm_res, touch_res, uname_res, ifcpp, ifmsvc,sort, builtin, showProtected, inputConnectors, outputConnectors, sanityCheckFailed, keepRedeclares;
FCore.Cache cache;
Absyn.ComponentRef crefCName;
Expand Down Expand Up @@ -1845,7 +1844,7 @@ algorithm
title,xLabel,yLabel,filename2,varNameStr,xml_filename,xml_contents,visvar_str,pwd,omhome,omlib,omcpath,os,
platform,usercflags,senddata,res,workdir,gcc,confcmd,touch_file,uname,filenameprefix,compileDir,libDir,exeDir,configDir,from,to,
gridStr, logXStr, logYStr, x1Str, x2Str, y1Str, y2Str, curveWidthStr, curveStyleStr, legendPosition, footer, autoScaleStr,scriptFile,logFile, simflags2, outputFile,
systemPath, gccVersion, gd, strlinearizeTime, suffix,cname, modeldescriptionfilename, tmpDir, tmpFile;
systemPath, gccVersion, gd, strlinearizeTime, suffix,cname, modeldescriptionfilename, tmpDir, tmpFile, annStr;
list<DAE.Exp> simOptions;
list<Values.Value> vals;
Absyn.Path path,classpath,className,baseClassPath;
Expand Down Expand Up @@ -1881,7 +1880,6 @@ algorithm
list<String> vars_1,args,strings,strs,strs1,strs2,visvars,postOptModStrings,postOptModStringsOrg,mps,files,dirs,modifiernamelst;
Real timeTotal,timeSimulation,timeStamp,val,x1,x2,y1,y2,r,r1,r2,linearizeTime,curveWidth,offset,offset1,offset2,scaleFactor,scaleFactor1,scaleFactor2;
GlobalScript.Statements istmts;
list<GlobalScript.Statements> istmtss;
Boolean have_corba, bval, anyCode, b, b1, b2, b3, b4, b5, externalWindow, logX, logY, autoScale, forceOMPlot, gcc_res, omcfound, rm_res, touch_res, uname_res, ifcpp, ifmsvc,sort, builtin, showProtected, inputConnectors, outputConnectors, sanityCheckFailed, keepRedeclares;
FCore.Cache cache;
Absyn.ComponentRef crefCName;
Expand Down Expand Up @@ -2791,6 +2789,22 @@ algorithm

case (cache,_,"updateConnection",_,_) then (cache,Values.BOOL(false));

case (cache,_,"updateConnectionStr",{Values.CODE(Absyn.C_TYPENAME(classpath)),Values.STRING(str1), Values.STRING(str2),Values.STRING(annStr)},_)
algorithm
istmts := Parser.parsestringexp("__dummy(" + annStr + ");");
GlobalScript.ISTMTS(interactiveStmtLst = {GlobalScript.IEXP(exp = aexp)}) := istmts;
Absyn.CALL(functionArgs = Absyn.FUNCTIONARGS(argNames = nargs)) := aexp;
Absyn.NAMEDARG(argValue = Absyn.CODE(Absyn.C_MODIFICATION(Absyn.CLASSMOD(elementArgLst=eltargs,eqMod=Absyn.NOMOD())))) := listHead(nargs);
p := SymbolTable.getAbsyn();
absynClass := Interactive.getPathedClassInProgram(classpath, p);
absynClass := InteractiveUtil.updateConnectionAnnotationInClass(absynClass, str1, str2, Absyn.ANNOTATION(eltargs));
p := Interactive.updateProgram(Absyn.PROGRAM({absynClass}, if AbsynUtil.pathIsIdent(classpath) then Absyn.TOP() else Absyn.WITHIN(AbsynUtil.stripLast(classpath))), p);
SymbolTable.setAbsyn(p);
then
(cache,Values.BOOL(true));

case (cache,_,"updateConnectionStr",_,_) then (cache,Values.BOOL(false));

case (cache,_,"updateConnectionNames",{Values.CODE(Absyn.C_TYPENAME(classpath)),Values.STRING(str1), Values.STRING(str2),
Values.STRING(str3), Values.STRING(str4)},_)
equation
Expand Down

3 comments on commit 76de683

@adeas31
Copy link
Member

Choose a reason for hiding this comment

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

Its a bit late but shouldn't the new API be called updateConnectionAnnotation instead of updateConnectionStr?
Also why not ExpressionOrModification instead of input String annotate.

@adrpo
Copy link
Member Author

@adrpo adrpo commented on 76de683 Sep 24, 2020

Choose a reason for hiding this comment

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

Because it seem that it didn't want to do a Qt API for a function with weird input types, so i changed that to a string. I don't know how to fix it for other types so I made this hack for now.
You can see I also kept updateConnection and that one doesn't have a Qt API.
Of course, we can update the name to updateConnectionAnnotation (is only used by OMEdit right now, so we can do whatever).

@adeas31
Copy link
Member

Choose a reason for hiding this comment

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

Oh yes Qt API doesn't handle that so then you have to use sendExpression.

I suggest to change the API name updateConnectionAnnotation.

Please sign in to comment.