High-dynamic-range imaging of nanoscale magnetic fields using optimal control of a single qubit.