Skip to content

Commit

Permalink
Fix pytests and reduce warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
thalassemia committed Aug 31, 2023
1 parent 882416d commit 8aa9814
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
7 changes: 4 additions & 3 deletions ecoli/processes/environment/derive_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def get_default_global_state():
'mmol_to_counts': mmol_to_counts.to('L/mmol')}}


def test_deriver(total_time=10):
def test_deriver(total_time=10, return_data=False):

growth_rate = 6e-3

Expand Down Expand Up @@ -183,9 +183,10 @@ def test_deriver(total_time=10):
# save state
saved_state[time] = copy.deepcopy(state)

return saved_state
if return_data:
return saved_state


if __name__ == '__main__':
saved_data = test_deriver(100)
saved_data = test_deriver(100, return_data=True)
print(saved_data)
8 changes: 6 additions & 2 deletions ecoli/processes/environment/lysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ def test_lysis(
emit_step=1,
bounds=[25, 25] * units.um,
n_bins=[5, 5],
uptake_rate_max=25
uptake_rate_max=25,
return_data=False
):
from ecoli.composites.environment.lattice import Lattice

Expand Down Expand Up @@ -360,7 +361,9 @@ def test_lysis(
emit_step=emit_step)
sim.update(total_time)
data = sim.emitter.get_data_unitless()
return data

if return_data:
return data


def main():
Expand All @@ -377,6 +380,7 @@ def main():
emit_step=10,
bounds=bounds,
n_bins=[11, 11],
return_data=True
)

# format the data for plot_snapshots
Expand Down
13 changes: 9 additions & 4 deletions ecoli/processes/environment/multibody_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def get(self, timeout=0):
return self.update

# tests and simulations
def test_multibody(n_agents=1, time=10):
def test_multibody(n_agents=1, time=10, return_data=False):
agent_ids = [
str(agent_id)
for agent_id in range(n_agents)]
Expand All @@ -369,7 +369,9 @@ def test_multibody(n_agents=1, time=10):
'timestep': 1,
'total_time': time,
'return_raw_data': True}
return simulate_experiment(experiment, settings)
data = simulate_experiment(experiment, settings)
if return_data:
return data


def test_growth_division(
Expand All @@ -380,6 +382,7 @@ def test_growth_division(
total_time=10,
timestep=1,
experiment_settings=None,
return_data=False
):
if not experiment_settings:
experiment_settings = {}
Expand Down Expand Up @@ -460,7 +463,8 @@ def test_growth_division(
experiment._send_updates(invoked_update)

experiment.end()
return experiment.emitter.get_data_unitless()
if return_data:
return experiment.emitter.get_data_unitless()


def run_growth_division(
Expand Down Expand Up @@ -495,7 +499,8 @@ def run_growth_division(
growth_rate_noise=0.001,
division_volume=volume_from_length(4, 1) * units.fL,
total_time=100,
experiment_settings=experiment_settings)
experiment_settings=experiment_settings,
return_data=True)

agents, fields = format_snapshot_data(gd_data)
return plot_snapshots(
Expand Down
8 changes: 5 additions & 3 deletions ecoli/processes/membrane/membrane_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def next_update(self, timestep, states):
'PMF': PMF}}


def test_mem_potential():
def test_mem_potential(return_data=False):
"""
test :module: ecoli.processes.membrane.membrane_potential.MembranePotential
by running it with changing external Na concentrations.
Expand All @@ -219,15 +219,17 @@ def test_mem_potential():

PMF_timeseries = timeseries['membrane']['PMF']
assert PMF_timeseries[-1] > PMF_timeseries[2]
return timeseries

if return_data:
return timeseries


def main():
out_dir = os.path.join(PROCESS_OUT_DIR, NAME)
if not os.path.exists(out_dir):
os.makedirs(out_dir)

timeseries = test_mem_potential()
timeseries = test_mem_potential(return_data=True)
settings = {
'remove_first_timestep': True
}
Expand Down
3 changes: 2 additions & 1 deletion ecoli/processes/metabolism_redux.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,8 @@ def solve(self,
constr.append(v[self.maintenance_idx] >= ngam_target)
# If enzymes not present, constrain rxn flux to 0
if binary_kinetic_idx is not None:
constr.append(v[binary_kinetic_idx] == 0)
if len(binary_kinetic_idx) > 0:
constr.append(v[binary_kinetic_idx] == 0)
# TODO (Cyrus) - make this a parameter
constr.extend([v >= 0, v <= upper_flux_bound, e >= 0, e <= upper_flux_bound])

Expand Down
7 changes: 4 additions & 3 deletions ecoli/processes/spatiality/spatial_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def run_spatial_geometry_process():
return output


def test_spatial_geometry_process():
def test_spatial_geometry_process(return_data=False):
"""
Test that the process runs correctly.
Expand All @@ -189,7 +189,8 @@ def test_spatial_geometry_process():
output = run_spatial_geometry_process()
# TODO(vivarium): Add assert statements to ensure correct performance.

return output
if return_data:
return output


def main():
Expand All @@ -199,7 +200,7 @@ def main():
if not os.path.exists(out_dir):
os.makedirs(out_dir)

output = test_spatial_geometry_process()
output = test_spatial_geometry_process(return_data=True)



Expand Down
4 changes: 3 additions & 1 deletion ecoli/states/wcecoli_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def numpy_molecules(states):
if 'environment' in states:
if 'exchange_data' in states['environment']:
states['environment']['exchange_data']['constrained'
] *= units.mmol / (units. g * units.h)
] = {mol: units.mmol / (units. g * units.h) * rate
for mol, rate in states['environment']['exchange_data'][
'constrained']}
else:
# Load aerobic minimal media exchange data by default
states['environment']['exchange_data'] = {
Expand Down

0 comments on commit 8aa9814

Please sign in to comment.