- As per Kelly's paper in SIAM: "A function is **consistent** if it performs the exact same sequence of arithmetic operations on each call. This is essentially like saying that the function must: 1. have no logical branches, 2. be deterministic, and 3. have outputs that vary smoothly with the inputs." - Most NLP solvers require objectives and constraints to be defined to have such consistency. - In the below slide of his YT video (explaining the paper), Kelly identifies various sources of inconsistency. ## The first source of inconsistent functions emerge from defining discontinuous dynamics that violate the rules of non-linear programming solvers - If-else statements (the bigger red box above) are a way to add discontinuous dynamics while formulating Trajectory Optimisation problems but are not allowed in direct transcription solutions as it leads to **inconsistent** functions. - Other examples of discontinuous functions that are inconsistent ```abs```, ```max``` and ```min``` as these are also implemented with 'if' statements. - His paper also states that a "trick to allow various inconsistent functions (such as ```abs```, ```max``` and ```min```) to be implemented consistently is using extra decision variables (aka [[slack variables]]) and constraints into the problem. An example is given in section 8, showing how to correctly implement the abs() function." ![[Pasted image 20221029172754.png]] - Another way to manage such inconsistent functions "is to use smoothing, which is also demonstrated in the block-moving example in section 8". ## A second source of inconsistency "is when a function has an internal iteration loop, such as in root finding or in a variable-step integration method". The solution here are: 1. implement a root-finding method with a fixed number of iterations inside an optimization. 2. replace a variable-step integration method with a fixed-step method. ## A third source of inconsistency is when one applies linear interpolation to compute dynamics or constraints with table-look up values - "Linear interpolation of a table has a discontinuous derivative when switching between two different table entries". - The solution here is "to switch to an interpolation scheme with continuous derivatives". a. "Continuous first derivatives are required by most solvers when computing gradients (first partial derivatives)". b. "Solvers that compute both gradients and Hessians (second partial derivatives) will require continuous second derivatives". ## A fourth source of inconsistency emerges when one computes system dynamics with time-stepping simulators. - Bullet or Box2d are examples of such simulators. - "The contact solvers in these simulators are inconsistent, which then leads to poor convergence in the nonlinear program." - To solve for "this source of inconsistency is to rewrite the system dynamics. If the sequence of contacts is known and the dynamics can be described as a simple hybrid system, then you can use multiphase trajectory optimization to compute the solution (see section 9.9)." - "For more complex systems where the contact sequence is unknown, you can use through-contact trajectory optimization to compute the solution [40, 48] (see section 9.10)." - "If you need to use the time-stepping simulator, then you can use some of the methods developed by the computer graphics community [60, 61, 1, 34]."