Skip to content

Commit

Permalink
Update run_configuration.ipynb to show examples on how to modify conf…
Browse files Browse the repository at this point in the history
…igs.

Also fix a potentially nasty hidden bug of env sizes.

PiperOrigin-RevId: 572503833
  • Loading branch information
oteret authored and Selforg Gardener committed Oct 11, 2023
1 parent 750332c commit 5aaf553
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
7 changes: 2 additions & 5 deletions self_organising_systems/biomakerca/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ class EnvConfig:
Attributes:
agent_state_size: size of the internal states of agents.
etd: the EnvTypeDef defining all cell types and some of their properties.
env_state_size: the total size of each cell. It is:
'number of agent specializations' + agent_state_size
env_state_size: the total size of each cell. It is: 4 + agent_state_size
struct_integrity_cap: the maximum value of structural integrity.
This is what gets propagated by IMMUTABLE materials. Structural integrity
decays the further away it goes from IMMUTABLE mats. If 0, gravity mats
Expand Down Expand Up @@ -438,9 +437,7 @@ def __init__(self,
max_lifetime=int(1e6)):
self.agent_state_size = agent_state_size
self.etd = etd
# this depends on how many specializations are actually there.
n_specs = len(etd.specialization_idxs.values())
self.env_state_size = n_specs + self.agent_state_size
self.env_state_size = 4 + self.agent_state_size
self.struct_integrity_cap = struct_integrity_cap
self.absorbtion_amounts = absorbtion_amounts
self.dissipation_per_step = dissipation_per_step
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,62 @@
" else RandomlyAdaptiveMutator(init_sd=sd, change_perc=0.2))"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "y3p9hXhKuSk2"
},
"source": [
"## Optionally, modify the config for custom configurations"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "cKshhtYDvE81"
},
"outputs": [],
"source": [
"print(\"Current config:\")\n",
"print('\\n'.join(\"%s: %s\" % item for item in vars(config).items()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "H1wR-EQium-X"
},
"outputs": [],
"source": [
"## Examples for modifying the config\n",
"## Uncomment relevant lines or do like them.\n",
"\n",
"## Regardless, to trigger the recomputation of step_env and similar,\n",
"## config needs to be a new object! So, first, we create a new copy.\n",
"import copy\n",
"config = copy.copy(config)\n",
"\n",
"## Change simple isolated parameters (most of them)\n",
"# config.struct_integrity_cap = 100\n",
"# config.max_lifetime = 500\n",
"## Vectors can be modified either by writing new vectors:\n",
"# config.dissipation_per_step = jp.array([0.02, 0.02])\n",
"## Or by multiplying previous values. Note that they are immutable!\n",
"# config.dissipation_per_step = config.dissipation_per_step * 2\n",
"\n",
"## agent_state_size is trickier, because it influences env_state_size.\n",
"## So you can either create a new config:\n",
"## Note that you would have to insert all values that you don't want to take\n",
"## default initializations.\n",
"# config = evm.EnvConfig(agent_state_size=4)\n",
"## Or you can just modify env_state_size as well.\n",
"## (env_state_size = agent_state_size + 4) for now.\n",
"# config.agent_state_size = 4\n",
"# config.env_state_size = config.agent_state_size + 4\n"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -208,7 +264,8 @@
"frame = make_frame(env, step, steps_per_frame)\n",
"\n",
"out_file = \"video.mp4\"\n",
"with media.VideoWriter(out_file, shape=frame.shape[:2], fps=fps) as video:\n",
"with media.VideoWriter(\n",
" out_file, shape=frame.shape[:2], fps=fps, crf=18) as video:\n",
" video.add_image(frame)\n",
" for i in tqdm.trange(n_frames):\n",
" if i in when_to_double_speed:\n",
Expand Down

0 comments on commit 5aaf553

Please sign in to comment.