The evolution of the cosmic molecular gas density