# So you want to build the Matrix

If you’ve ever watched the Matrix and thought — what would it take to actually build a simulation that’s accurate down to the atomic scale— then this is the blog post for you.

The point of this isn’t to get things exactly right, but more so to get a sense of scale; most of this is back-of-napkin kind of thinking anyway so please look past the mistakes. So, for fun, let’s try to estimate how much compute it will take to build a Matrix-like simulation inside of a computer. Then, we’ll talk about some of the challenges designers will have to face if, in the far future, they do decide to build it.

**Oh no…**

To start, let’s try to estimate the compute needed to simulate the entire human body. To do this, we really need to ask two questions:

1. At any static moment, how much information is required to encode the state of all atoms in the simulation?

2. How much information is required to encode the dynamics function that describes how the simulation state changes over time?

To begin, we know that there are around 7*10²⁷ atoms in the body [1]. If we only encode the 3D position and velocity of an atom in binary32 floating-point, we’d need 24 bytes, meaning that we need 16.8*10²⁹ bytes, or 168,000 yottabytes of data to describe the position and velocity of each atom. For context, it’s estimated that all Internet traffic is around 2 zettabytes per year [2], so we’d need **more than 80 million times more information than all Internet content consumed by people in a single year **to just describe the static state of the human body.

Next, to describe the dynamics of this system, we need to compute bonded and unbonded forces between atoms. While calculating bonded forces only scales linearly with respect to the number of total bonds, calculating unbonded forces scales quadratically with the number of total atoms, making this computation on order n².

To update the unbonded forces, we’d have to compute (7*10²⁷)² interactions. Assuming each unbonded interaction takes around 100 flops to calculate and we set the timestep of the simulation to 1 femtosecond (1/10¹⁵ seconds), we’d have to perform 100*10¹⁵*(7²⁷)², or 4.3*10⁶² floating-point operations to simulate unbonded forces for a single second of the human body.

That’s… a very big number.

To make things simpler, let’s only calculate unbonded interactions between atoms that are at most one millimeter apart. In this case, the number of atoms we have to check against scales down by a factor of 1.613*10⁸ [3], so we only have to perform 100*(10¹⁵)*(7²⁷)*(7²⁷/1.613*10⁸) = 6.94*10⁵⁴ flops… which is still an ungodly amount of compute. For context, Nvidia’s latest 3070 graphic card hits around 4*10⁶ raytracing flops [4], meaning we’d need to make up a whopping 10⁴⁹ scale difference to make this kind of calculation feasible.

These issues with storage and compute only become more serious as we scale up to trying to simulate something like the entire planet Earth. Because the Earth is around 10²³ times the volume of an average person, we‘d have to scale our compute and storage by that same amount, assuming that we want to accurately simulate all interactions inside of the planet.

Clearly, then, limiting the space of interactions has some impact on reducing the computational challenge of simulating all pairwise interactions, but it does little to reduce the sheer domain over which we have to calculate.

This of course, also assumes that dynamics calculations are perfectly accurate. But, as decades of simulation research has shown, this just isn’t true.

**An even bigger problem: simulation accuracy**

Namely, creating this kind of system would require surmounting multiple barriers: overcoming instability over long timescales, establishing consistency across spatiotemporal scales, and finding efficient approximations for computationally intensive algorithms. To understand how these issues play out, let’s look to computational biologists who’ve spent years working on molecular dynamics (MD) simulation.

To accurately model a molecular system, researchers can’t just develop a single formula for describing interactions between individual atoms. Instead, they develop approximate models called force fields that consist of dozens of experimentally-driven components that describe all sorts of bonded and unbonded terms including charge, angle bend, and Lennard-Jones potential [5]. Historically, force field accuracy has improved over time [6]. However, they’re still error-prone and become numerically unstable over long time periods [7].

Plus, because these forces have to be calculated between all atoms present in a simulation and require a timestep on the femto-scale for accurate simulation [8], even the most successful simulations are limited to the millisecond range [9].

One alternative is to decrease simulation granularity. To do this, simulators use aggregate structures to represent groups of atoms, which reduces computational complexity. However, it’s still not clear how aggregate structures should be chosen. And, though various groups have explored consistent simulation [10][11], it’s unclear how to best enforce spatial consistency between aggregates and the atoms they represent.

Recently, many have turned to machine-learning methods to solve approximation problems. In computational biology alone, the number of groups using ML to approximate physical processes has exploded over the last ten years [12], and work there has been punctuated by the success of techniques like AlphaFold, which uses a deep neural network to predict protein structure [13]. However, because processes are strongly coupled across multiple spatiotemporal scales, more work is required to enforce consistency.

Strong multiscale coupling also shows up in weather modeling. For example, to perform weather prediction, models need to account for turbulence in the atmosphere. To make this tractable, they discretize the atmosphere and perform computational fluid dynamics (CFD) over that grid. However, this ignores the impact of small-scale movements like eddy formation, and simulators have to use sub-grid modeling to correct for these errors [14].

This reflects two important points. On one hand, there will always be some level of simulation inaccuracy on account of modeling tradeoffs we have to make in order to make a simulation tractable — even if we simulate a system to the atomic-scale, sub-atomic issues will still crop up. At the same time, systems can be corrected, but this comes at the cost of model simplicity.

These, of course, are only some of the issues that’ll have to be tackled; we haven’t even touched the surface of problems like analytical vs numerical tradeoffs, quantum interactions, and large-scale modeling. However, I hope that this post served as an adequate introduction to Matrix-type simulation. As always, I’d love to hear your thoughts.

[1] https://www.thoughtco.com/how-many-atoms-are-in-human-body-603872

[3] https://www.syfy.com/syfywire/the-human-cube-the-volume-of-humanity

[4] https://www.engadget.com/nvidia-rtx-3070-review-ray-tracing-130052152.html

[5] https://pubs.acs.org/doi/10.1021/la3038846

[6] https://pubs.acs.org/doi/abs/10.1021/ct2007814

[7] https://pubmed.ncbi.nlm.nih.gov/22577825/

[8] https://pubs.acs.org/doi/10.1021/cr040426m

[9] https://dl.acm.org/doi/10.1109/SC.2014.9

[10] https://pubmed.ncbi.nlm.nih.gov/16416251/

[11] https://journals.aps.org/prl/abstract/10.1103/PhysRevLett.105.237802

[12] https://arxiv.org/abs/1807.00123

[13] https://www.nature.com/articles/s41586-019-1923-7

[14] https://www.sciencedirect.com/science/article/abs/pii/S0167610511000250