Quantum Optimal Control Theory of Harmonic Generation