While this is a very old question, the current answer has since been outdated as training to build up the "Ace Trainer" medal changed in late 2018.
When the gym system was reworked in mid-2017, the "Ace Trainer" medal was no longer available as you could no longer train in gyms. This was this case until late 2018, when the battle system was implemented. Now, can train by battling against the team leaders in trainer battles.
To begin these battles, tap the "nearby" bar on the bottom right of the screen, and swipe left to choose which leaders you want to battle. Each leader has different Pokemon based on the league you choose. If you win the battle, then your ace medal will increase.
Blanche (Mystic)
- UltraGreat League: Magikarp, Feebas, and Squirtle
- GreatUltra League: Alolan Ninetales, Glalie, & Lapras
- Master League: Lapras, Gliscor, & Articuno
Candela (Valor)
- UltraGreat League: Slugma, Vulpix, and Charmander
- GreatUltra League: Alolan Marowak, Houndoom, & Infernape
- Master League: Infernape, Electivire, & Moltres
Spark (Instinct)
- UltraGreat League: Magnemite, Mareep, and Pikachu
- GreatUltra League: Alolan Raichu, Magneton, & Manectric
- Master League: Manectric, Milotic, & Zapdos