[NB] Fix symbolic differentiation losing derivative function bodies (#15834)
differentiateFunction installed the differentiated algorithm section by creating a new class pointer, but the "fake" function node created earlier for recursive differentiation still held the old pointer. Its cached function is what Function.getDerivative/addDiffInfo put back into the function tree when the same call is differentiated again, so codegen received the original (underived) body: the generated derivative never assigned its outputs and e.g. function_diff.mos crashed with a stack overflow whenever the uninitialized return slot happened to be NaN. Update the class pointer in place instead so every node copy sees the differentiated body.
Also add a use-before-assign check for backend-generated functions (the frontend check only runs in typeFunctionBody, which generated functions never pass through): provably unassigned outputs or uses are reported as errors, and variables that cannot be proven to always be assigned are explicitly initialized to zero with a warning, as recommended by the specification.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
[SimRT] More helpful message when an initialization NLS fails (#15433)
When a nonlinear system fails during initialization, the runtime hint "proper start-values for some of the following iteration variables might help" was too terse to be actionable. Some models (e.g. the parallel-cable models in ticket #15433, FourCablesHoldingPlatform) fail to initialize under the default tearing because the iteration variables OpenModelica selects have no suitable start values: the model was developed with another tool that tears differently, so the model's start values apply to a different set of iteration variables.
Reword the hint to explain this and point to remedies (give start values to the listed iteration variables, or select a different tearing method, e.g. --tearingMethod=omcTearing). The per-variable list that follows already prints each iteration variable's start/nominal values, which now makes the "start=0" (unset) culprits obvious. Fires only when an initialization system actually fails, so no healthy model is affected.
[NB] Fix symbolic differentiation losing derivative function bodies (#15834)
differentiateFunction installed the differentiated algorithm section by creating a new class pointer, but the "fake" function node created earlier for recursive differentiation still held the old pointer. Its cached function is what Function.getDerivative/addDiffInfo put back into the function tree when the same call is differentiated again, so codegen received the original (underived) body: the generated derivative never assigned its outputs and e.g. function_diff.mos crashed with a stack overflow whenever the uninitialized return slot happened to be NaN. Update the class pointer in place instead so every node copy sees the differentiated body.
Also add a use-before-assign check for backend-generated functions (the frontend check only runs in typeFunctionBody, which generated functions never pass through): provably unassigned outputs or uses are reported as errors, and variables that cannot be proven to always be assigned are explicitly initialized to zero with a warning, as recommended by the specification.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
[SimRT] More helpful message when an initialization NLS fails (#15433)
When a nonlinear system fails during initialization, the runtime hint "proper start-values for some of the following iteration variables might help" was too terse to be actionable. Some models (e.g. the parallel-cable models in ticket #15433, FourCablesHoldingPlatform) fail to initialize under the default tearing because the iteration variables OpenModelica selects have no suitable start values: the model was developed with another tool that tears differently, so the model's start values apply to a different set of iteration variables.
Reword the hint to explain this and point to remedies (give start values to the listed iteration variables, or select a different tearing method, e.g. --tearingMethod=omcTearing). The per-variable list that follows already prints each iteration variable's start/nominal values, which now makes the "start=0" (unset) culprits obvious. Fires only when an initialization system actually fails, so no healthy model is affected.
[NB] Fix symbolic differentiation losing derivative function bodies (#15834)
differentiateFunction installed the differentiated algorithm section by creating a new class pointer, but the "fake" function node created earlier for recursive differentiation still held the old pointer. Its cached function is what Function.getDerivative/addDiffInfo put back into the function tree when the same call is differentiated again, so codegen received the original (underived) body: the generated derivative never assigned its outputs and e.g. function_diff.mos crashed with a stack overflow whenever the uninitialized return slot happened to be NaN. Update the class pointer in place instead so every node copy sees the differentiated body.
Also add a use-before-assign check for backend-generated functions (the frontend check only runs in typeFunctionBody, which generated functions never pass through): provably unassigned outputs or uses are reported as errors, and variables that cannot be proven to always be assigned are explicitly initialized to zero with a warning, as recommended by the specification.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
[SimRT] More helpful message when an initialization NLS fails (#15433)
When a nonlinear system fails during initialization, the runtime hint "proper start-values for some of the following iteration variables might help" was too terse to be actionable. Some models (e.g. the parallel-cable models in ticket #15433, FourCablesHoldingPlatform) fail to initialize under the default tearing because the iteration variables OpenModelica selects have no suitable start values: the model was developed with another tool that tears differently, so the model's start values apply to a different set of iteration variables.
Reword the hint to explain this and point to remedies (give start values to the listed iteration variables, or select a different tearing method, e.g. --tearingMethod=omcTearing). The per-variable list that follows already prints each iteration variable's start/nominal values, which now makes the "start=0" (unset) culprits obvious. Fires only when an initialization system actually fails, so no healthy model is affected.
[NB] Fix symbolic differentiation losing derivative function bodies (#15834)
differentiateFunction installed the differentiated algorithm section by creating a new class pointer, but the "fake" function node created earlier for recursive differentiation still held the old pointer. Its cached function is what Function.getDerivative/addDiffInfo put back into the function tree when the same call is differentiated again, so codegen received the original (underived) body: the generated derivative never assigned its outputs and e.g. function_diff.mos crashed with a stack overflow whenever the uninitialized return slot happened to be NaN. Update the class pointer in place instead so every node copy sees the differentiated body.
Also add a use-before-assign check for backend-generated functions (the frontend check only runs in typeFunctionBody, which generated functions never pass through): provably unassigned outputs or uses are reported as errors, and variables that cannot be proven to always be assigned are explicitly initialized to zero with a warning, as recommended by the specification.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
[SimRT] More helpful message when an initialization NLS fails (#15433)
When a nonlinear system fails during initialization, the runtime hint "proper start-values for some of the following iteration variables might help" was too terse to be actionable. Some models (e.g. the parallel-cable models in ticket #15433, FourCablesHoldingPlatform) fail to initialize under the default tearing because the iteration variables OpenModelica selects have no suitable start values: the model was developed with another tool that tears differently, so the model's start values apply to a different set of iteration variables.
Reword the hint to explain this and point to remedies (give start values to the listed iteration variables, or select a different tearing method, e.g. --tearingMethod=omcTearing). The per-variable list that follows already prints each iteration variable's start/nominal values, which now makes the "start=0" (unset) culprits obvious. Fires only when an initialization system actually fails, so no healthy model is affected.
[NB] Fix symbolic differentiation losing derivative function bodies (#15834)
differentiateFunction installed the differentiated algorithm section by creating a new class pointer, but the "fake" function node created earlier for recursive differentiation still held the old pointer. Its cached function is what Function.getDerivative/addDiffInfo put back into the function tree when the same call is differentiated again, so codegen received the original (underived) body: the generated derivative never assigned its outputs and e.g. function_diff.mos crashed with a stack overflow whenever the uninitialized return slot happened to be NaN. Update the class pointer in place instead so every node copy sees the differentiated body.
Also add a use-before-assign check for backend-generated functions (the frontend check only runs in typeFunctionBody, which generated functions never pass through): provably unassigned outputs or uses are reported as errors, and variables that cannot be proven to always be assigned are explicitly initialized to zero with a warning, as recommended by the specification.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
[SimRT] More helpful message when an initialization NLS fails (#15433)
When a nonlinear system fails during initialization, the runtime hint "proper start-values for some of the following iteration variables might help" was too terse to be actionable. Some models (e.g. the parallel-cable models in ticket #15433, FourCablesHoldingPlatform) fail to initialize under the default tearing because the iteration variables OpenModelica selects have no suitable start values: the model was developed with another tool that tears differently, so the model's start values apply to a different set of iteration variables.
Reword the hint to explain this and point to remedies (give start values to the listed iteration variables, or select a different tearing method, e.g. --tearingMethod=omcTearing). The per-variable list that follows already prints each iteration variable's start/nominal values, which now makes the "start=0" (unset) culprits obvious. Fires only when an initialization system actually fails, so no healthy model is affected.
[NB] Fix symbolic differentiation losing derivative function bodies (#15834)
differentiateFunction installed the differentiated algorithm section by creating a new class pointer, but the "fake" function node created earlier for recursive differentiation still held the old pointer. Its cached function is what Function.getDerivative/addDiffInfo put back into the function tree when the same call is differentiated again, so codegen received the original (underived) body: the generated derivative never assigned its outputs and e.g. function_diff.mos crashed with a stack overflow whenever the uninitialized return slot happened to be NaN. Update the class pointer in place instead so every node copy sees the differentiated body.
Also add a use-before-assign check for backend-generated functions (the frontend check only runs in typeFunctionBody, which generated functions never pass through): provably unassigned outputs or uses are reported as errors, and variables that cannot be proven to always be assigned are explicitly initialized to zero with a warning, as recommended by the specification.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
[SimRT] More helpful message when an initialization NLS fails (#15433)
When a nonlinear system fails during initialization, the runtime hint "proper start-values for some of the following iteration variables might help" was too terse to be actionable. Some models (e.g. the parallel-cable models in ticket #15433, FourCablesHoldingPlatform) fail to initialize under the default tearing because the iteration variables OpenModelica selects have no suitable start values: the model was developed with another tool that tears differently, so the model's start values apply to a different set of iteration variables.
Reword the hint to explain this and point to remedies (give start values to the listed iteration variables, or select a different tearing method, e.g. --tearingMethod=omcTearing). The per-variable list that follows already prints each iteration variable's start/nominal values, which now makes the "start=0" (unset) culprits obvious. Fires only when an initialization system actually fails, so no healthy model is affected.
[NB] Fix symbolic differentiation losing derivative function bodies (#15834)
differentiateFunction installed the differentiated algorithm section by creating a new class pointer, but the "fake" function node created earlier for recursive differentiation still held the old pointer. Its cached function is what Function.getDerivative/addDiffInfo put back into the function tree when the same call is differentiated again, so codegen received the original (underived) body: the generated derivative never assigned its outputs and e.g. function_diff.mos crashed with a stack overflow whenever the uninitialized return slot happened to be NaN. Update the class pointer in place instead so every node copy sees the differentiated body.
Also add a use-before-assign check for backend-generated functions (the frontend check only runs in typeFunctionBody, which generated functions never pass through): provably unassigned outputs or uses are reported as errors, and variables that cannot be proven to always be assigned are explicitly initialized to zero with a warning, as recommended by the specification.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
[SimRT] More helpful message when an initialization NLS fails (#15433)
When a nonlinear system fails during initialization, the runtime hint "proper start-values for some of the following iteration variables might help" was too terse to be actionable. Some models (e.g. the parallel-cable models in ticket #15433, FourCablesHoldingPlatform) fail to initialize under the default tearing because the iteration variables OpenModelica selects have no suitable start values: the model was developed with another tool that tears differently, so the model's start values apply to a different set of iteration variables.
Reword the hint to explain this and point to remedies (give start values to the listed iteration variables, or select a different tearing method, e.g. --tearingMethod=omcTearing). The per-variable list that follows already prints each iteration variable's start/nominal values, which now makes the "start=0" (unset) culprits obvious. Fires only when an initialization system actually fails, so no healthy model is affected.
[NB] Fix symbolic differentiation losing derivative function bodies (#15834)
differentiateFunction installed the differentiated algorithm section by creating a new class pointer, but the "fake" function node created earlier for recursive differentiation still held the old pointer. Its cached function is what Function.getDerivative/addDiffInfo put back into the function tree when the same call is differentiated again, so codegen received the original (underived) body: the generated derivative never assigned its outputs and e.g. function_diff.mos crashed with a stack overflow whenever the uninitialized return slot happened to be NaN. Update the class pointer in place instead so every node copy sees the differentiated body.
Also add a use-before-assign check for backend-generated functions (the frontend check only runs in typeFunctionBody, which generated functions never pass through): provably unassigned outputs or uses are reported as errors, and variables that cannot be proven to always be assigned are explicitly initialized to zero with a warning, as recommended by the specification.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
[SimRT] More helpful message when an initialization NLS fails (#15433)
When a nonlinear system fails during initialization, the runtime hint "proper start-values for some of the following iteration variables might help" was too terse to be actionable. Some models (e.g. the parallel-cable models in ticket #15433, FourCablesHoldingPlatform) fail to initialize under the default tearing because the iteration variables OpenModelica selects have no suitable start values: the model was developed with another tool that tears differently, so the model's start values apply to a different set of iteration variables.
Reword the hint to explain this and point to remedies (give start values to the listed iteration variables, or select a different tearing method, e.g. --tearingMethod=omcTearing). The per-variable list that follows already prints each iteration variable's start/nominal values, which now makes the "start=0" (unset) culprits obvious. Fires only when an initialization system actually fails, so no healthy model is affected.