The origin of complexity remains one of the most important and, at the same time, the most controversial scientific problems. Earlier attempts were based on theory of dynamical systems but did not lead to a satisfactory solution of the problem. I believe that a deeper understanding is possible based on a recent development of statistical physics, combining it with relevant ideas from evolutionary biology and machine learning.
Using patterns in magnetic materials as the main example, I discuss some general problems such as (a) a formal definition of pattern complexity ; (b) self-induced spin glassiness due to competing interactions as a way to interpret chaotic patterns ; (c) multi-well states intermediate between glasses and ordinary ordered states and their relevance for the problem of long-term memory in complicated systems ; and (d) complexity of frustrated quantum spin systems . I will also review a very recent experimental observation of self-induced spin-glass state in elemental neodymium .
 A. A. Bagrov, I. A. Iakovlev, A. A. Iliasov, M. I. Katsnelson, and V. V. Mazurenko, Multi-scale structural complexity of natural patterns, PNAS 117, 30241 (2020).
 A. Principi and M. I. Katsnelson, Spin glasses in ferromagnetic thin films, Phys. Rev. B 93, 054410 (2016); Self-induced glassiness and pattern formation in spin systems due to long-range interactions, Phys. Rev. Lett. 117, 137201 (2016).
 A. Kolmus, M. I. Katsnelson, A. A. Khajetoorians, and H. J. Kappen, Atom-by-atom construction of attractors in a tunable finite size spin array, New J. Phys. 22, 023038 (2020).
 T. Westerhout, N. Astrakhantsev, K. S. Tikhonov, M. I. Katsnelson, and A. A. Bagrov, Generalization properties of neural network approximations to frustrated magnet ground states, Nature Commun. 11, 1 (2020).
 U. Kamber et al, Self-induced spin glass state in elemental and crystalline neodymium, Science 368, eaay6757 (2020).