revise the NonlinearProgram, such that the objective and constraints only compute the gradient when they have to.