{'fraction_non_alphanumeric': 0.03268265476854434, 'fraction_numerical': 0.005242610150585611, 'mean_word_length': 4.651118815001576, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Flow Lenia: Mass conservation for the study of virtual creatures in continuous cellular automata

Lenia is a family of cellular automata (CA) generalizing Conway's Game of Life to continuous space, time and states. Lenia has attracted a lot of attention because of the wide diversity of self-organizing patterns it can generate. Among those, some spatially localized patterns (SLPs) resemble life-like artificial creatures. However, those creatures are found in only a small subspace of the Lenia parameter space and are not trivial to discover, necessitating advanced search algorithms. We hypothesize that adding a mass conservation constraint could facilitate the emergence of SLPs. We propose here an extension of the Lenia model, called Flow Lenia, which enables mass conservation. We show a few observations demonstrating its effectiveness in generating SLPs with complex behaviors. Furthermore, we show how Flow Lenia enables the integration of the parameters of the CA update rules within the CA dynamics, making them dynamic and localized. This allows for multi-species simulations, with locally coherent update rules that define properties of the emerging creatures, and that can be mixed with neighbouring rules. We argue that this paves the way for the intrinsic evolution of self-organized artificial life forms within continuous CAs.


Introduction
Complex self-organizing systems have been central to Artificial Life (ALife) towards the search of emergent life-reminiscent phenomenons. Among those systems are continuous cellular automata (CAs) like SmoothLife [10] or Lenia [2]. Lenia is a family of CAs generalizing Conway's Game of Life (GoL) to continuous space, time and states [2,3]. Each instance of Lenia is given by a specific configuration of parameters defining its update rule and an initial configuration (see figure 1 (top)). For example, GoL corresponds to a specific parameter configuration in Lenia. Previous studies with Lenia have shown the emergence eplantec@gmail.com arXiv:2212.07906v1 [cs.NE] 14 Dec 2022 of autopoïetic (i.e self-produced) spatially localized patterns (SLPs), also called "creatures", often resembling microscopic life-forms and displaying various behaviors like motility or self-replication. Such observations have made Lenia a particularly interesting system for studying the emergence of life-like phenomenon and even sensori-motor capabilities [5]. More specifically, such creatures are of particular interest in the field of enactive cognition and enactive artificial intelligence as instances of artificial agents endowed with constitutive autonomy [4].
However, those patterns are quite difficult to find, necessitating complex finetuned search algorithms in order to find update rule parameters allowing the emergence of interesting patterns (e.g spatially localized patterns). For instance, complex patterns have been found in [5] using intrinsically motivated goal exploration processes and gradient descent. Furthermore, an important challenge in ALife and artificial intelligence is to design systems displaying open-ended intrinsic evolution (i.e unbounded growth of complexity through intrinsic evolutionary processes) [12]. Such a process is called intrinsic since no final objective (i.e fixed fitness function) is set by the experimenter, the fitness landscape is intrinsic to the system and depends only on its current state, as in natural evolution where there is no final goal [8]. Obtaining such a process in a CA could be achieved by embedding information in the system locally modifying the update rule and so the properties of emerging creatures, enabling multi-species simulations. Such simulations might set the stage for evolution to occur in populations of patterns each with their own update rule. However, achieving it in CAs like Lenia is still an open-problem.
We propose in this work a mass-conservative (i.e the sum of the CA's activations remains constant over time) extension to Lenia called Flow Lenia. We hypothesize that such conservation laws will help in the search for artificial life-forms by constraining emerging patterns to spatially localized ones. Furthermore, we show that this new model allows for the integration of the update rule parameters within the CA dynamics enabling the emergence of creatures with different parameters and so different properties. Such a feature opens up research perspectives towards the achievement of open-ended intrinsic evolution inside continuous CAs.
In section 2, we first briefly describe the Lenia system, then, we describe the Flow Lenia model. In section 3 we show how this new model allows for parameter localization. In section 4 we show a few observations demonstrating the effectiveness of the model in generating SLPs with complex behaviors. Finally, we discuss results and future works in section 5.

Model
Let L be the support of a CA, which is the two-dimensional grid Z 2 in the rest of this work. Let A t : L → [0, 1] C be CA's activations at time t, with A t i (x) the activation in location x ∈ L, channel i and time t. C is the number of channels of the system. We denote [·] b a the clip function between a and b.

Lenia
Flow Lenia The growth U t is computed with kernels K and growth functions G (equation 3) defined by a specific parameter configuration sampled in Lenia's parameter space. A small portion of the growth is then added to activations A t to give the next state A t+dt . Bottom : Flow Lenia update rule. Affinity map U t is computed as in Lenia. The flow F t is given by combining the affinity map and concentration (i.e activations) gradients (equation 5). Finally, the next state is obtained by "moving" matter in the CA space according to the flow F t (equations 6 and 7).

Lenia
An instance of Lenia is defined by a set of convolution kernels K where K i : L → [0, 1] satisfies L K i = 1 and a set of growth functions G with G i : Each pair (K i , G i ) is associated to a source channel c i 0 it senses and a target channel c i 1 it updates. The original Lenia's computation algorithm is as follows [3] (see figure 1 (top) for a schematic version): Apply convolution on A t with kernels K. In the rest of this paper, kernels are defined as a set of normalized concentric rings as in [5] : Where a i , b i , w i and r i are parameters defining kernel i. k is a parameter defining the number of rings per kernel (set to 3 here) and R is a parameter common to all kernels defining the maximum neighborhood radius. 3) Apply growth mappings G defined as Gaussian functions : Where µ i and σ i are parameters of growth function i. This gives the growth U t : With h i a parameter weighting the effect of the pair (K i , G i ) in the growth computation. 4) Add a small portion of U t to A t , and clip the result back to the unit range.

Flow Lenia
We then describe the proposed mass-conservative extension of Lenia (Flow Lenia). The proposed model works by interpreting activations A t as concentrations of matter in each cell (concentrations of different types of matter in the multichannel case), and the potential U t as an affinity map. The basic idea is that matter will move towards higher affinity locations by flowing up the gradient in the space of U . We define the instantaneous speed of matter through a flow F t : L → (R 2 ) C defined as : the total mass in each location p. Here ∇U t i is the affinity gradient for channel i. The negative concentration gradient −∇A t Σ is a diffusion term to avoid concentrating all the matter in very small regions. In practice, gradients are estimated through Sobel filtering. Map α : L → [0, 1] is used to weight the importance of each term such that −∇A t Σ dominates when the total mass at a given location is close to a critical mass θ A ∈ R >0 . Intuitively, the result is that matter is mainly driven by concentration gradients in high concentrations regions and is freer to move along the affinity gradient in less concentrated areas. We typically use n > 1 such that the affinity gradient dominates on a larger range of masses.
Then, we can move matter in space according to flow F giving us the state at the next time step. To do so we use the reintegration tracking method proposed in [9]. Reintegration tracking is a semi-Lagrangian grid based algorithm thought as a reformulation of particle tracking in screen space (i.e grid space) aimed at not losing information (i.e particles) which happens when two particles end up in the same cell. The basic principle is to work with distribution of particles (i.e infinite number of particles) and conserve the total mass by adding up masses going on a same cell. Overall, reintegration tracking can be seen as a grid-based approximation to particle systems with infinite number of particles having the property to conserve total mass. Thus, Flow lenia can be seen as a new kind of model at the frontier between continuous CAs and particle systems. Figure  2 illustrates how reintegration tracking is used in our case. Contrary to the original algorithm, we do not track velocities and instead use the flow as the instantaneous velocity of matter. However we could also track velocities and use the flow as an instantaneous acceleration at the cost of memory space. The resulting update rule is the following : Where I i (p , p) is the proportion of incoming matter in channel i going from cell p ∈ L to cell p ∈ L: With p i = p + dt · F t i (p ) the target location of the flow from p . Ω(p) is the domain of cell at location p, which is a square of side 1. D(m, s) is a distribution defined on L with mean m and variance s satisfying L D(m, s) = 1, which is in practice a uniform square distribution with side length 2s centered at m. This distribution emulates a flow of particles from source area Ω(p ) to target area D(p , s), where the distribution D emulates Brownian motion at the low level. All the elements are depicted in Fig. 2. Since the distribution D integrates to 1, it is clear that a cell cannot send out more mass than it contains nor less and so the system conserves its mass ( L A t i = L A t+dt i , ∀t ∈ R ≥0 , ∀i ∈ {1, .., C}). Mass conservation also implies that cells' states are no longer bound to the unit range but can be any positive real valued number (A t (p) ∈ R C ≥0 ). Flow Lenia pseudo code is shown in algorithm 1 and a schematic representation is shown in figure 1 (bottom). A notebook with the model implementation is available here 5 . Implementation makes use of JAX [1] auto-vectorization and just-in-time compilation to parallelize computation and make it more efficient. Fig. 2: Calculation of incoming matter to cell p ∈ L through reintegration tracking [9]. Mass contained in cell at location p ∈ L is moved to a square distribution D centered on p = p + dt · F t (p ). The proportion of mass from p arriving in p is then given by the integral of D on the cell domain of p, Ω(p), denoted as I(p , p).

Parameter localization
As said in the introduction, Flow Lenia allows to embed the update rule parameters inside the CA. Intuitively, we can "attach" a vector of parameters to the matter locally modifying how it behaves (i.e locally modifying how the affinity map is computed), and let it flow with it. Formally, this comes to defining a parameter map P : L → Θ where Θ is a given parameter set. This map can be used to locally modify the update rule. For instance, we can embed the h ∈ R |K| vector weighting the importance of each kernel in the affinity map computation (see equation 3), giving : Then parameters can be moved along with matter. A problem is how to mix parameters arriving in the same cell. Here we propose two different methods which are respectively average and softmax sampling. The former makes

Algorithm 1: Flow Lenia algorithm
For each cell p, compute the incoming matter from cell p with equations 6 and 7 a weighted average of incoming parameters with respect to the quantities of incoming matter and is formally defined as : Softmax sampling on the other hand samples a parameter in the set of incoming ones following the softmax distribution given by incoming quantities of matter : Note that we could also sample each element of the vector of parameters independently giving some crossover mechanism.

Experimental results
By using random parameter search or evolution algorithm with certain fitness functions, we were able to generate a variety of SLPs. For evolutionary optimization we use the evosax [7] implementation of OpenES strategy [11] with populations of size 16. Here we describe a few common or interesting observed structures and behaviors (Fig. 3). Parameters used for simulations are shown in table 1.
Patterns (a) to (g) and (k) to (n) were found with random search in the parameter space defined in Table 1. Patterns (h) to (j) where found by optimizing a fitness function using evolutionary stategies. Pattern (o) corresponds to a multi-species simulation using the parameter localization method described in section 3.
Moving dots (a) like those in reaction-diffusion systems are common in Flow Lenia. Snake-like segments (b) are also common, with interesting attractionrepulsion dynamics generating complex motion. Time lapse (c) to (e) demonstrates a pattern switching among different scales, from a larger structure "erupting" into smaller ones and also displaying non-trivial motion patterns.
Moving patterns, e.g. gliding (f) and rotating (g), occur naturally from random search, but we were also able to evolve for directional movement (h, i) or angular movement (j) using the linear or angular speed of the mass center as fitness functions, respectively. Note the modular structures in single channel (h), and the intertwined complex structures in multi-channel (i) and (j).
Time lapse (k) to (n) demonstrates the complex development of a pattern, from binary fission (k-m) to fusion (n). The masses in green channel act as propulsion parts, while red provides structural integrity and adhesion points showing some sort of modular structure.
Multi-species simulation (o) shows the parameter localization method. Colors represent parameters locally modifying the update rule. We can observe the coexistence and interaction of different creatures, each one embedding its own set of parameters. We also launched larger scale simulations for much more steps. Figure 4 shows a timelapse of such a simulation in which we can observe "predatory" behaviors where a species take over a large part of the world (bc) and also cooperative behaviors where different species self-organize in stable larger structures (d). Random mutations are also be added in the form of "beams" striking on a randomly sampled connected zone L ⊂ L (e.g a square) and adding Gaussian noise to the parameters in that zone.

Discussions
Due to the mass conservative nature of Flow Lenia, patterns cannot grow indefinitely into spatially global patterns (i.e patterns that diffuse on the entire grid also called Turing-like patterns), therefore SLPs are much more common and easier to find. This is an important difference from the previous versions of Lenia, where one needs to search or evolve for patterns that are both nonvanishing and non-exploding, and to constantly monitor their existential status. During initial exploration, the SLPs found in Flow Lenia tend to be static or slowly "floating" in nearby space, with occasional burst of vigorous movements. When using simple evolutionary algorithms, SLPs with behaviors similar to the original Lenia, like perpetual gliding, rotation, or oscillation, were also found in Flow Lenia. We also showed that parameter localization enabled by the Flow Lenia formulation allows for multi-species simulations which would have been difficult to achieve in Lenia.
There are several possible directions to further extend the Flow Lenia system, or using it as a platform to perform artificial life experiments that would be difficult to design and perform without the mass conservation feature. For We use stochastic sampling as the mixing rule and random mutations every 500 steps.  instance, Flow Lenia easily allows to add environmental features acting as physical opportunities and constraints for the self-organising creatures. In particular, parameter localization allows to define a diversity of environmental elements with their own update rule. Whereas environment design is poorly addressed and quite challenging in cellular automata systems, we believe that it is crucial to study the emergence of agency and cognition in those systems as shown in [5]. For instance, resource consumption mechanisms were currently being studied inside Flow Lenia, such that patterns can be evolved or trained to seek extra resources (matter or energy) from the environment to replenish their own constantly decaying pool of resources (see videos in companion website). Using this system, more experimentation can be done to pursue the emergence of intraor inter-species interactions, like competition, cooperation, predation, or parasitism. Interspecies interactions could be studied using parameter localization ( Fig. 2-o) that is easier to achieve using the flow mechanism as argued in section 3. The stability of persistent structures, coupled with the flexibility of trainable behaviors, may facilitate the emergence of sustainable reproduction, memory, learning, and even intelligence inside continuous CAs. Furthermore, parameter localization is a key step towards achieving open-ended intrinsic evolution inside continuous CAs for which resource consumption mechanism with common pool of ressources could serve as intrinsic selective pressures. Moreover, mass conservation has been shown to increase evolutionary activity in artificial chemistry [6,13]. Such an intrinsic evolutionary process could be key for the growth of complexity inside the system and the emergence of virtual creatures displaying more complex forms of cognition.