We start with a state where the rotor is aligned with the electromagnets, such that attractive force is at maximum, and potential energy is at minimum. The electromagnets are switched to the next state, and now the force is at minimum, and the potential energy is at maximum. As the rotor approaches the next aligned position, potential energy is gradually decreased from the maximum back to the minimum. This repeats itself over and over again. Ok. During each such step, the amount of energy gained is exactly the same as the amount of energy that was lost when switching the electromagnets. But if that's the case, then how is work being produced at all? I know it comes from the external electrical energy source, but how does that work? What energy transitions am I missing here?