Axion cosmology from lattice QCD