I’m trying to write the code for transforming bilevel optimization problem to one level using KKT conditions. And I need to pass as a constraint a condition that gradient of Lagrangian of lower level problem with respect to decision variables equals to 0.