Automatic optimization strategy for the design of circular multipolar magnets