Skip to content

Commit

Permalink
Disable default extraction of min, max, nominal assignments for param…
Browse files Browse the repository at this point in the history
…eters. (#9853)

  - For now, we are disabling extraction/creation of min. max, and nominal
    assignment statements for parameters (globalknownvars).

    This is done because these generated assignments, the way they are now,
    overwrite the binding values for the parameters. For more information
    see #9825.

    The extraction/creation is enabled if we are creating a dynamic optimization
    problem. This was the reason it was added in the first place. See #8030.
  • Loading branch information
mahge committed Dec 5, 2022
1 parent 1d45e82 commit f8a270c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
35 changes: 25 additions & 10 deletions OMCompiler/Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -1414,14 +1414,14 @@ protected
list<SimCode.JacobianMatrix> symJacs, SymbolicJacs, SymbolicJacsNLS, SymbolicJacsTemp, SymbolicJacsStateSelect;
list<SimCode.SimEqSystem> initialEquations;
list<SimCode.SimEqSystem> initialEquations_lambda0;
list<SimCode.SimEqSystem> removedInitialEquations, jacobianEquations;
list<SimCode.SimEqSystem> removedInitialEquations;
list<SimCodeVar.SimVar> jacobianSimvars, seedVars;
list<SimCode.SimEqSystem> startValueEquations; // --> updateBoundStartValues
list<SimCode.SimEqSystem> maxValueEquations; // --> updateBoundMaxValues
list<SimCode.SimEqSystem> minValueEquations; // --> updateBoundMinValues
list<SimCode.SimEqSystem> nominalValueEquations; // --> updateBoundNominalValues
list<SimCode.SimEqSystem> parameterEquations; // --> updateBoundParameters
list<SimCode.SimEqSystem> jacobianEquations;
list<SimCode.SimEqSystem> startValueEquations = {}; // --> updateBoundStartValues
list<SimCode.SimEqSystem> maxValueEquations = {}; // --> updateBoundMaxValues
list<SimCode.SimEqSystem> minValueEquations = {}; // --> updateBoundMinValues
list<SimCode.SimEqSystem> nominalValueEquations = {}; // --> updateBoundNominalValues
list<SimCode.SimEqSystem> parameterEquations = {}; // --> updateBoundParameters
list<SimCode.SimEqSystem> jacobianEquations = {};
algorithm
numCheckpoints:=ErrorExt.getNumCheckpoints();
try
Expand Down Expand Up @@ -1472,13 +1472,28 @@ algorithm
// create parameter equations
((uniqueEqIndex, startValueEquations, _)) := BackendDAEUtil.foldEqSystem(inInitDAE, SimCodeUtil.createStartValueEquations, (uniqueEqIndex, {}, inBackendDAE.shared.globalKnownVars));
if debug then ExecStat.execStat("simCode: createStartValueEquations"); end if;
((uniqueEqIndex, nominalValueEquations)) := SimCodeUtil.createValueEquationsShared(inBackendDAE.shared, SimCodeUtil.createInitialAssignmentsFromNominal, (uniqueEqIndex, {}));

nominalValueEquations := {};
minValueEquations := {};
maxValueEquations := {};
// For now, disable traversal of globalknownvars for creation of nominal, min, and max assignments (if we are not doing
// dynamic optimizations).
// We need to revise how we handle these assignments for parameters with regard to maintaining the binding values
// for those that we end up generating these assignments. See #9825 for discussions.
// If you change these remember to change the coresponding code for ode mode simulation in SimCodeUtil.mo.
if (Config.acceptOptimicaGrammar() or Flags.getConfigBool(Flags.GENERATE_DYN_OPTIMIZATION_PROBLEM)) then
((uniqueEqIndex, nominalValueEquations)) := SimCodeUtil.createValueEquationsShared(inBackendDAE.shared, SimCodeUtil.createInitialAssignmentsFromNominal, (uniqueEqIndex, nominalValueEquations));
if debug then ExecStat.execStat("simCode: createNominalValueEquationsShared"); end if;
((uniqueEqIndex, minValueEquations)) := SimCodeUtil.createValueEquationsShared(inBackendDAE.shared, SimCodeUtil.createInitialAssignmentsFromMin, (uniqueEqIndex, minValueEquations));
if debug then ExecStat.execStat("simCode: createMinValueEquationsShared"); end if;
((uniqueEqIndex, maxValueEquations)) := SimCodeUtil.createValueEquationsShared(inBackendDAE.shared, SimCodeUtil.createInitialAssignmentsFromMax, (uniqueEqIndex, maxValueEquations));
if debug then ExecStat.execStat("simCode: createMaxValueEquationsShared"); end if;
end if;

((uniqueEqIndex, nominalValueEquations)) := BackendDAEUtil.foldEqSystem(inBackendDAE, SimCodeUtil.createNominalValueEquations, (uniqueEqIndex, nominalValueEquations));
if debug then ExecStat.execStat("simCode: createNominalValueEquations"); end if;
((uniqueEqIndex, minValueEquations)) := SimCodeUtil.createValueEquationsShared(inBackendDAE.shared, SimCodeUtil.createInitialAssignmentsFromMin, (uniqueEqIndex, {}));
((uniqueEqIndex, minValueEquations)) := BackendDAEUtil.foldEqSystem(inBackendDAE, SimCodeUtil.createMinValueEquations, (uniqueEqIndex, minValueEquations));
if debug then ExecStat.execStat("simCode: createMinValueEquations"); end if;
((uniqueEqIndex, maxValueEquations)) := SimCodeUtil.createValueEquationsShared(inBackendDAE.shared, SimCodeUtil.createInitialAssignmentsFromMax, (uniqueEqIndex, {}));
((uniqueEqIndex, maxValueEquations)) := BackendDAEUtil.foldEqSystem(inBackendDAE, SimCodeUtil.createMaxValueEquations, (uniqueEqIndex, maxValueEquations));
if debug then ExecStat.execStat("simCode: createMaxValueEquations"); end if;
((uniqueEqIndex, parameterEquations)) := BackendDAEUtil.foldEqSystem(inBackendDAE, SimCodeUtil.createVarNominalAssertFromVars, (uniqueEqIndex, {}));
Expand Down
31 changes: 22 additions & 9 deletions OMCompiler/Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -255,15 +255,15 @@ protected
list<SimCode.SimEqSystem> equationsForZeroCrossings;
list<SimCode.SimEqSystem> initialEquations; // --> initial_equations
list<SimCode.SimEqSystem> initialEquations_lambda0; // --> initial_equations_lambda0
list<SimCode.SimEqSystem> jacobianEquations;
list<SimCode.SimEqSystem> maxValueEquations; // --> updateBoundMaxValues
list<SimCode.SimEqSystem> minValueEquations; // --> updateBoundMinValues
list<SimCode.SimEqSystem> nominalValueEquations; // --> updateBoundNominalValues
list<SimCode.SimEqSystem> jacobianEquations = {};
list<SimCode.SimEqSystem> maxValueEquations = {}; // --> updateBoundMaxValues
list<SimCode.SimEqSystem> minValueEquations = {}; // --> updateBoundMinValues
list<SimCode.SimEqSystem> nominalValueEquations = {}; // --> updateBoundNominalValues
//list<SimCode.SimEqSystem> paramAssertSimEqs;
list<SimCode.SimEqSystem> parameterEquations; // --> updateBoundParameters
list<SimCode.SimEqSystem> parameterEquations = {}; // --> updateBoundParameters
list<SimCode.SimEqSystem> removedEquations;
list<SimCode.SimEqSystem> removedInitialEquations; // -->
list<SimCode.SimEqSystem> startValueEquations; // --> updateBoundStartValues
list<SimCode.SimEqSystem> startValueEquations = {}; // --> updateBoundStartValues
list<SimCode.StateSet> stateSets;
list<SimCodeVar.SimVar> tempvars, jacobianSimvars, seedVars;
list<list<SimCode.SimEqSystem>> algebraicEquations; // --> functionAlgebraics
Expand Down Expand Up @@ -438,15 +438,28 @@ algorithm

// Assertions and crap
// create parameter equations

((uniqueEqIndex, startValueEquations, _)) := BackendDAEUtil.foldEqSystem(dlow, createStartValueEquations, (uniqueEqIndex, {}, globalKnownVars));
if debug then execStat("simCode: createStartValueEquations"); end if;
((uniqueEqIndex, nominalValueEquations)) := createValueEquationsShared(dlow.shared, createInitialAssignmentsFromNominal, (uniqueEqIndex, {}));

// For now, disable traversal of globalknownvars for creation of nominal, min, and max assignments (if we are not doing
// dynamic optimizations).
// We need to revise how we handle these assignments for parameters with regard to maintaining the binding values
// for those that we end up generating these assignments. See #9825 for discussions.
// If you change these remember to change the coresponding code for daemode in SimCodeMain.mo.
if (Config.acceptOptimicaGrammar() or Flags.getConfigBool(Flags.GENERATE_DYN_OPTIMIZATION_PROBLEM)) then
((uniqueEqIndex, nominalValueEquations)) := createValueEquationsShared(dlow.shared, createInitialAssignmentsFromNominal, (uniqueEqIndex, nominalValueEquations));
if debug then execStat("simCode: createNominalValueEquationsShared"); end if;
((uniqueEqIndex, minValueEquations)) := createValueEquationsShared(dlow.shared, createInitialAssignmentsFromMin, (uniqueEqIndex, minValueEquations));
if debug then execStat("simCode: createMinValueEquationsShared"); end if;
((uniqueEqIndex, maxValueEquations)) := createValueEquationsShared(dlow.shared, createInitialAssignmentsFromMax, (uniqueEqIndex, maxValueEquations));
if debug then execStat("simCode: createMaxValueEquationsShared"); end if;
end if;

((uniqueEqIndex, nominalValueEquations)) := BackendDAEUtil.foldEqSystem(dlow, createNominalValueEquations, (uniqueEqIndex, nominalValueEquations));
if debug then execStat("simCode: createNominalValueEquations"); end if;
((uniqueEqIndex, minValueEquations)) := createValueEquationsShared(dlow.shared, createInitialAssignmentsFromMin, (uniqueEqIndex, {}));
((uniqueEqIndex, minValueEquations)) := BackendDAEUtil.foldEqSystem(dlow, createMinValueEquations, (uniqueEqIndex, minValueEquations));
if debug then execStat("simCode: createMinValueEquations"); end if;
((uniqueEqIndex, maxValueEquations)) := createValueEquationsShared(dlow.shared, createInitialAssignmentsFromMax, (uniqueEqIndex, {}));
((uniqueEqIndex, maxValueEquations)) := BackendDAEUtil.foldEqSystem(dlow, createMaxValueEquations, (uniqueEqIndex, maxValueEquations));
if debug then execStat("simCode: createMaxValueEquations"); end if;
((uniqueEqIndex, parameterEquations)) := BackendDAEUtil.foldEqSystem(dlow, createVarNominalAssertFromVars, (uniqueEqIndex, {}));
Expand Down

0 comments on commit f8a270c

Please sign in to comment.