Energy minimization and ac demagnetization in a nanomagnet array.