Variational preparation of finite-temperature states on a quantum computer