Initial condition and desired solution in Opt control of heat eq

So, as far as I can understand, you are solving the following problem:
Find the source f such that u=0 at t=dt, u=2 at t>dt.
As this is not a continuous heat profile in time, you cannot expect the optimal solution.
Other things that you could check is how many iterations does the optimization algorithm use (are you hitting max number of iterations?), and what is the value of the functional.