For the first time, scientists have used artificial intelligence to create complex, three-dimensional simulations of the Universe. It's called the Deep Density Displacement Model, or D3M, and it's so fast and so accurate that the astrophysicists who designed it don't even know how it does what it does.

What it does is accurately simulate the way gravity shapes the Universe over billions of years. Each simulation takes just 30 milliseconds - compared to the minutes it takes other simulations.

And, even more fascinatingly, D3M learnt from the 8,000 training simulations the team fed it - vastly extrapolating from and outperforming them, able to adjust parameters in which it had not even been trained.

"It's like teaching image recognition software with lots of pictures of cats and dogs, but then it's able to recognise elephants," said astrophysicist Shirley Ho of the Flatiron Institute and Carnegie Mellon University.

"Nobody knows how it does this, and it's a great mystery to be solved."

Observations of the Universe around us can supply a lot of information about its evolution, but there are limits to what we can see. This is why simulations can be so handy.

By running simulations that produce results that match our observations, as well as simulations that don't, scientists can figure out the scenarios most likely to have produced the Universe we live in.

But the complexity of our Universe's history makes such simulations rather computationally taxing, which means they take time to run. A single study could require thousands of simulations in order to obtain useful statistical data.

This is where D3M, developed by an international team of computational astrophysicists, comes in. It calculates how, over 13.8 billion years (the age of the Universe), gravity moves billions of particles in space.

If we were to simulate this particle movement with non-AI-powered software, it could take up to 300 hours of computation for a single, highly accurate simulation; you could also get it done in just a couple minutes, but the accuracy will greatly suffer.

To overcome this problem, the research team decided to develop a neural network for running the simulations, and trained D3M by feeding it with 8,000 different simulations from a model with the highest accuracy produced to date.

Once D3M's training was complete and the AI was running accurately, it was ready to take for a test drive. The researchers asked it to simulate a universe-in-a-box around 600 million light-years per side.

To judge its output, the team also ran the same simulation with the excruciatingly slow hundreds-of-hours method, and the method that takes just a couple minutes. As expected, the slow method produced the most accurate result, while the quick one produced a relative error of 9.3 percent.

D3M has blown all previous quick methods out of the water. It performed its simulation in just 30 milliseconds and, compared to the slow-but-super-accurate model, only had a relative error of 2.8.

Even more impressively, although it had only been trained on a single set of parameters, the neural network could predict the structure formation of the simulated Universe based on other parameters it had not even been trained in - for instance, if the amount of dark matter was varied.

This means the AI could have a flexibility that makes it suited to a range of simulation tasks - although before that happens, the team hopes to figure out how exactly it has managed to do what it does.

"We can be an interesting playground for a machine learner to use to see why this model extrapolates so well, why it extrapolates to elephants instead of just recognising cats and dogs," Ho said.

"It's a two-way street between science and deep learning."

The research has been published in PNAS.