Speeding up critical system dynamics through optimized evolution