Circuit optimization via adjoint Lagrangians