On my end, your script is fully functional as is. Goes through all five cycles without any problem.

Might be a silly question, but since it "pops the plots for the optimizations" are you sure that you're hitting "Test" after "Train"?