Skip to content

Commit

Permalink
[NB] Use simplifyDump everywhere (#12012)
Browse files Browse the repository at this point in the history
  • Loading branch information
phannebohm committed Feb 20, 2024
1 parent da36889 commit 65207b6
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo
Expand Up @@ -548,7 +548,7 @@ public
Expression.INTEGER(1)},
inv_arguments = {},
operator = Operator.makeAdd(ty));
sub_exp := SimplifyExp.simplify(sub_exp, true);
sub_exp := SimplifyExp.simplifyDump(sub_exp, true, getInstanceName());
sub_exp := Expression.CALL(Call.makeTypedCall(NFBuiltinFuncs.INTEGER_REAL, {sub_exp}, Variability.DISCRETE, Purity.PURE));
end if;
then Subscript.INDEX(sub_exp);
Expand Down Expand Up @@ -1518,7 +1518,7 @@ public
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed for:\n" + toString(eqn)});
then fail();
end match;
exp := SimplifyExp.simplify(exp, true);
exp := SimplifyExp.simplifyDump(exp, true, getInstanceName());
end getResidualExp;

function getType
Expand Down Expand Up @@ -2054,7 +2054,7 @@ public
equality_exp := Expression.RELATION(
exp1 = Expression.fromCref(cref),
operator = Operator.OPERATOR(ComponentRef.nodeType(cref), NFOperator.Op.NEQUAL),
exp2 = SimplifyExp.simplify(exp, true)
exp2 = SimplifyExp.simplifyDump(exp, true, getInstanceName())
);
end makeInequality;

Expand Down
Expand Up @@ -274,7 +274,7 @@ protected
else
// one or less algebraic variables > differentiate the expression
(returnExp, oDiffArgs) := Differentiate.differentiateExpression(arg, diffArgs);
returnExp := SimplifyExp.simplify(returnExp, true);
returnExp := SimplifyExp.simplifyDump(returnExp, true, getInstanceName());
if listLength(oDiffArgs.new_vars) == 1 then
der_var := List.first(oDiffArgs.new_vars);
Pointer.update(acc_derivatives, der_var :: Pointer.access(acc_derivatives));
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NBackEnd/Modules/3_Post/NBSolve.mo
Expand Up @@ -527,7 +527,7 @@ public
scalarized = false
);
(derivative, diffArgs) := Differentiate.differentiateExpressionDump(residual, diffArgs, getInstanceName());
derivative := SimplifyExp.simplify(derivative, true);
derivative := SimplifyExp.simplifyDump(derivative, true, getInstanceName());

if Expression.isZero(derivative) then
invertRelation := false;
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NBackEnd/Util/NBDifferentiate.mo
Expand Up @@ -858,7 +858,7 @@ public
// d delta/dz
(ret2, diffArguments) := differentiateExpression(arg2, diffArguments);
// dt/dz - d delta/dz
ret2 := SimplifyExp.simplify(Expression.MULTARY({ret1}, {ret2}, addOp));
ret2 := SimplifyExp.simplifyDump(Expression.MULTARY({ret1}, {ret2}, addOp), true, getInstanceName());
if Expression.isZero(ret2) then
ret := Expression.makeZero(Expression.typeOf(arg1));
else
Expand Down Expand Up @@ -1376,7 +1376,7 @@ public
(lhs, diffArguments) := differentiateExpression(diff_stmt.lhs, diffArguments);
(rhs, diffArguments) := differentiateExpression(diff_stmt.rhs, diffArguments);
diff_stmt.lhs := lhs;
diff_stmt.rhs := SimplifyExp.simplify(rhs, true);
diff_stmt.rhs := SimplifyExp.simplifyDump(rhs, true, getInstanceName());
then {diff_stmt, stmt};

// II. delegate differentiation to body and only return differentiated statement
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NBackEnd/Util/NBReplacements.mo
Expand Up @@ -124,7 +124,7 @@ public
replace_exp := Equation.getRHS(solvedEq);
replace_exp := Expression.map(replace_exp, function applySimpleExp(replacements = replacements));
// add the new replacement rule
UnorderedMap.add(varName, SimplifyExp.simplify(replace_exp, true), replacements);
UnorderedMap.add(varName, SimplifyExp.simplifyDump(replace_exp, true, getInstanceName()), replacements);
else
Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed because strong component cannot be solved explicitely: " + StrongComponent.toString(comp)});
fail();
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NBackEnd/Util/NBSlice.mo
Expand Up @@ -1097,7 +1097,7 @@ protected
list<Integer> values;
algorithm
replaced := list(Expression.map(sub, function Replacements.applySimpleExp(replacements = replacements)) for sub in subs);
values := list(Expression.integerValue(SimplifyExp.simplify(rep, true)) for rep in replaced);
values := list(Expression.integerValue(SimplifyExp.simplifyDump(rep, true, getInstanceName())) for rep in replaced);
ranges := List.zip(sizes, values);
end resolveDimensionsSubscripts;

Expand Down
12 changes: 6 additions & 6 deletions OMCompiler/Compiler/NFFrontEnd/NFSimplifyExp.mo
Expand Up @@ -62,12 +62,12 @@ public
function simplifyDump
"wrapper function for simplification to allow dumping before and afterwards"
input Expression exp;
input Boolean backend;
input Boolean includeScope;
output Expression res;
input String name = "";
input String indent = "";
algorithm
res := simplify(exp, backend);
res := simplify(exp, includeScope);
if Flags.isSet(Flags.DUMP_SIMPLIFY) and not Expression.isEqual(exp, res) then
print(indent + "### dumpSimplify | " + name + " ###\n");
print(indent + "[BEFORE] " + Expression.toString(exp) + "\n");
Expand All @@ -77,20 +77,20 @@ end simplifyDump;

function simplify
input output Expression exp;
input Boolean backend = false;
input Boolean includeScope = false;
algorithm
exp := match exp
case Expression.CREF()
algorithm
exp.cref := ComponentRef.simplifySubscripts(exp.cref);
exp.ty := ComponentRef.getSubscriptedType(exp.cref, backend);
exp.ty := ComponentRef.getSubscriptedType(exp.cref, includeScope);
then
exp;

case Expression.ARRAY()
guard not exp.literal
algorithm
exp.elements := Array.map(exp.elements, function simplify(backend = false));
exp.elements := Array.map(exp.elements, function simplify(includeScope = false));
then
exp;

Expand Down Expand Up @@ -636,7 +636,7 @@ algorithm
end for;

outExp := Expression.foldReduction(simplify(exp), listReverseInPlace(iters),
default_exp, function simplify(backend = false), function simplifyBinaryOp(op = op));
default_exp, function simplify(includeScope = false), function simplifyBinaryOp(op = op));
end simplifyReduction2;

function simplifySize
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFSimplifyModel.mo
Expand Up @@ -603,7 +603,7 @@ protected
algorithm
if not Function.isSimplified(func) then
Function.markSimplified(func);
Function.mapExp(func, function SimplifyExp.simplify(backend = false), mapBody = false);
Function.mapExp(func, function SimplifyExp.simplify(includeScope = false), mapBody = false);

cls := InstNode.getClass(func.node);
() := match cls
Expand Down

0 comments on commit 65207b6

Please sign in to comment.