Skip to content

Commit

Permalink
Add colab to reproduce the *upcoming* video of Biomaker CA.
Browse files Browse the repository at this point in the history
Add default methods for stringifying classes. Useful for storing metadata.
Add utility functions for saving and loading dnas.
Add a successful dna for the experiment performed in the colab.

PiperOrigin-RevId: 575125094
  • Loading branch information
oteret authored and Selforg Gardener committed Oct 20, 2023
1 parent 5aaf553 commit cfa6441
Show file tree
Hide file tree
Showing 7 changed files with 1,737 additions and 0 deletions.
7 changes: 7 additions & 0 deletions self_organising_systems/biomakerca/agent_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from self_organising_systems.biomakerca.env_logic import SpawnOpData
from self_organising_systems.biomakerca.env_logic import ParallelInterface
from self_organising_systems.biomakerca.environments import EnvConfig
from self_organising_systems.biomakerca.utils import stringify_class


class AgentLogic(ABC):
Expand Down Expand Up @@ -93,6 +94,9 @@ def repr_f(self, key: KeyType, perc: PerceivedData, params: AgentProgramType
"""
pass

def __str__(self):
return stringify_class(self)


def clip_residual(s, ds, clip_val):
"""Correct ds so that the final value of s + ds is within [-clip_val,clip_val].
Expand Down Expand Up @@ -190,6 +194,9 @@ def __init__(self, config: EnvConfig, perceive_ids=True, minimal_net=False):
axis=-1,
)

def __str__(self):
return stringify_class(self, include_list=["perceive_ids", "minimal_net"])

def split_params_f(
self, params: AgentProgramType
) -> tuple[AgentProgramType, AgentProgramType, AgentProgramType]:
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dna: persistence_1697720583799231923
EnvConfig: {agent_state_size: 2, etd: DefaultTypeDef: {materials_list: ['VOID', 'AIR', 'EARTH', 'IMMOVABLE', 'SUN', 'OUT_OF_BOUNDS'], types: {'VOID': 0, 'AIR': 1, 'EARTH': 2, 'IMMOVABLE': 3, 'SUN': 4, 'OUT_OF_BOUNDS': 5, 'AGENT_UNSPECIALIZED': 6, 'AGENT_ROOT': 7, 'AGENT_LEAF': 8, 'AGENT_FLOWER': 9}, specialization_idxs: {'AGENT_UNSPECIALIZED': 0, 'AGENT_ROOT': 1, 'AGENT_LEAF': 2, 'AGENT_FLOWER': 3}, agent_types: [6 7 8 9], intangible_mats: [0 1], gravity_mats: [2 6 7 8 9], structural_mats: [6 7 8 9], propagate_structure_mats: [2 3 6 7 8 9], agent_spawnable_mats: [0 1 2], structure_decay_mats: [-1 -1 1 0 -1 -1 5 5 5 5], aging_mats: [6 7 8 9], dissipation_rate_per_spec: [[0.5 0.5], [1. 1. ], [1. 1. ], [1.2 1.2]]}, env_state_size: 6, struct_integrity_cap: 200, absorbtion_amounts: [0.25 0.25], dissipation_per_step: [0.01 0.01], spawn_cost: [0.75 0.75], reproduce_cost: [1. 1.], specialize_cost: [0.02 0.02], reproduce_min_dist: 15, reproduce_max_dist: 35, n_reproduce_per_step: 2, nutrient_cap: [10. 10.], material_nutrient_cap: [10. 10.], max_lifetime: 10000}
BasicAgentLogic: {perceive_ids: True, minimal_net: False}
BasicMutator: {sd: 0.0001, change_perc: 0.2}
env_h: 16
env_w: 28
author: oteret
notes: This dna was trained with petri meta evolution. So, no mutator was used. But I tested and it definitely works with BasicMutators and sd of 1e-4. In some cases, 1e-3. See the notebook evolving_in_small_worlds.ipynb for more context.
6 changes: 6 additions & 0 deletions self_organising_systems/biomakerca/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from self_organising_systems.biomakerca.utils import dotdict
from self_organising_systems.biomakerca.utils import vmap2
from self_organising_systems.biomakerca.utils import stringify_class

### Environment
# This is the state of any given environment. It is made of 3 grids:
Expand Down Expand Up @@ -210,6 +211,9 @@ def is_agent_fn(self, env_type):
"""Return true if the cell is an agent. Works for any input dimensionality.
"""
return (env_type[..., None] == self.agent_types).any(axis=-1)

def __str__(self):
return stringify_class(self, exclude_list=["type_color_map"])


DEFAULT_MATERIALS = [
Expand Down Expand Up @@ -451,6 +455,8 @@ def __init__(self,
self.material_nutrient_cap = material_nutrient_cap
self.max_lifetime = max_lifetime

def __str__(self):
return stringify_class(self)


### Helpers for making environments.
Expand Down
Loading

0 comments on commit cfa6441

Please sign in to comment.