Controlling earthquake-like instabilities using artificial intelligence