ENH: Add callback to the optimizer