Quantum heat engine beyond the adiabatic approximation