Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save States Patches + Misc. #153

Merged
merged 24 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8831d67
Fixed duplicates in save_states config bug.
matt-wolff May 22, 2022
3758e46
Simplified ecoli_master_sim.py agent saving.
matt-wolff May 23, 2022
6917a9e
Replaced 'diffusion' w/ 'reaction_diffusion' in ecoli_engine_process.
matt-wolff May 23, 2022
73e13e4
Order save_times.
matt-wolff May 23, 2022
c675f26
Updated the vivarium save states.
matt-wolff May 23, 2022
fce79ed
Fixed colony saving so processes are not serialized.
matt-wolff May 23, 2022
d4f47cb
Regenerated colony_t4000.json
matt-wolff May 23, 2022
d150374
Updated vivarium-core requirements.
matt-wolff May 23, 2022
afac09e
Reverted doc/requirements.
matt-wolff May 23, 2022
665ca39
Include saved state time in random seed
U8NWXD May 24, 2022
d850cf3
Avoid serializing Unum in saved state
U8NWXD May 24, 2022
492dc42
Make sure requesters run when loading saved state
U8NWXD May 24, 2022
3cbdb24
Merge branch 'master' into save_patches
U8NWXD May 24, 2022
8a8a6c0
Initialize Exchange Data when Loading Saved Colony
U8NWXD May 25, 2022
0f29bc5
Avoid copying processes before retrieving inner states
U8NWXD May 28, 2022
da97254
Use Process Commands for Saving States
U8NWXD Jun 13, 2022
d4cab77
Upgrade stochastic-arrow to 0.5.0
U8NWXD Jun 16, 2022
548049d
Update EngineProcess to use pre_send_command()
U8NWXD Jun 17, 2022
e8c1d59
Stop Saving evolvers_ran and Extra Requester Run
U8NWXD Jun 17, 2022
b6a2b9d
Make binomial division deterministic
U8NWXD Jun 17, 2022
5e49cf1
Remove evolvers_ran from saved states
U8NWXD Jun 17, 2022
8976e2b
Fix tests
U8NWXD Jun 20, 2022
d9c4cf8
Upgrade vivarium core dependency
U8NWXD Jun 21, 2022
89a1d53
Merge branch 'master' into save_patches
U8NWXD Jul 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/colony_t4000.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/vivecoli_t10.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/vivecoli_t100.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/vivecoli_t1000.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/vivecoli_t2.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/vivecoli_t2678.json

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions ecoli/composites/ecoli_engine_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

from vivarium.core.composer import Composer
from vivarium.core.engine import Engine
from vivarium.core.process import Process
from vivarium.core.serialize import serialize_value, deserialize_value
from vivarium.core.store import Store
from vivarium.library.dict_utils import deep_merge

from ecoli.experiments.ecoli_master_sim import (
Expand Down Expand Up @@ -103,6 +103,7 @@ def colony_save_states(engine, config):
raise ValueError(
f'Config contains save_time ({time}) > total '
f'time ({config["total_time"]})')

for i in range(len(config["save_times"])):
if i == 0:
time_to_next_save = config["save_times"][i]
Expand All @@ -113,13 +114,19 @@ def colony_save_states(engine, config):
time_elapsed = config["save_times"][i]

# Save the full state of the super-simulation
def not_a_process(value):
return not isinstance(value, Process)
state = engine.state.get_value(condition=not_a_process)
def save_cell_processes(value):
"""
Excludes every process in the state except for the cell processes.
"""
return not (isinstance(value, Store) and value.topology and not isinstance(value.value, EngineProcess))
state = engine.state.get_value(condition=save_cell_processes)
state_to_save = copy.deepcopy(state)

del state_to_save['agents'] # Replace 'agents' with agent states
state_to_save['agents'] = {}

def not_a_process(value):
return not (isinstance(value, Store) and value.topology)
for agent_id in state['agents']:
# Get internal state from the EngineProcess sub-simulation
cell_state = state['agents'][agent_id]['cell_process'][0].sim.state.get_value(condition=not_a_process)
Expand Down Expand Up @@ -160,9 +167,8 @@ def run_simulation():
},
},
)

diffusion_schema = environment_composite.processes[
'diffusion'].get_schema()
'reaction_diffusion'].get_schema()
multibody_schema = environment_composite.processes[
'multibody'].get_schema()
tunnel_out_schemas['fields_tunnel'] = diffusion_schema['fields']
Expand Down
17 changes: 11 additions & 6 deletions ecoli/experiments/ecoli_master_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from typing import Optional, Dict, Any

from vivarium.core.engine import Engine
from vivarium.core.process import Process
from vivarium.core.serialize import deserialize_value
from vivarium.core.store import Store
from vivarium.library.dict_utils import deep_merge, deep_merge_combine_lists
from vivarium.library.topology import assoc_path
from ecoli.library.logging import write_json
Expand Down Expand Up @@ -199,6 +199,9 @@ def merge_config_dicts(d1, d2):
for key in LIST_KEYS_TO_MERGE:
d2.setdefault(key, [])
d2[key].extend(d1.get(key, []))
if key == 'save_times':
d2[key] = list(set(d2[key])) # Ensures there are no duplicates in d2
d2[key].sort()
deep_merge(d1, d2)

def update_from_json(self, path):
Expand Down Expand Up @@ -454,20 +457,22 @@ def save_states(self):
raise ValueError(
f'Config contains save_time ({time}) > total '
f'time ({self.total_time})')

for i in range(len(self.save_times)):
if i == 0:
time_to_next_save = self.save_times[i]
else:
time_to_next_save = self.save_times[i] - self.save_times[i - 1]
self.ecoli_experiment.update(time_to_next_save)
time_elapsed = self.save_times[i]
state = self.ecoli_experiment.state.get_value()

def not_a_process(value):
return not (isinstance(value, Store) and value.topology)
state = self.ecoli_experiment.state.get_value(condition=not_a_process)
if self.divide:
state = state['agents'][self.agent_id]
state_to_save = {key: state[key] for key in state.keys() if
not (isinstance(state[key], tuple) and isinstance(state[key][0], Process))}
write_json('data/vivecoli_t' + str(time_elapsed) + '.json', state_to_save)
print('Finished saving the state at t = ' + str(time_elapsed) + '\n')
write_json('data/vivecoli_t' + str(time_elapsed) + '.json', state)
print('Finished saving the state at t = ' + str(time_elapsed))
time_remaining = self.total_time - self.save_times[-1]
if time_remaining:
self.ecoli_experiment.update(time_remaining)
Expand Down
2 changes: 1 addition & 1 deletion ecoli/processes/environment/multibody_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __init__(self, parameters=None):
'jitter_force': jitter_force,
'bounds': remove_units(self.bounds),
'barriers': self.mother_machine,
'physics_dt': self.parameters['time_step'] / 10,
'physics_dt': self.parameters['timestep'] / 10,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, sorry for changing the parameter name. It's for the greater good!

}
self.physics = PymunkMultibody(multibody_config)

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ typing_extensions==4.0.1
Unum==4.1.4
vivarium-bioscrape==0.0.0.7
vivarium-convenience==0.0.3
vivarium-core==1.2.4
vivarium-core==1.2.8
vivarium-multibody==0.0.16
wcwidth==0.2.5
webencodings==0.5.1
Expand Down