The trace formula for the heat semigroup with polynomial potential