From b5648084503f0d18a0502d7b575721b21808ae4b Mon Sep 17 00:00:00 2001 From: Eran Date: Thu, 1 Aug 2024 11:32:25 -0400 Subject: [PATCH] set up comets demo for profiling --- process_bigraph/experiments/comets.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/process_bigraph/experiments/comets.py b/process_bigraph/experiments/comets.py index 215a9e4..967e201 100644 --- a/process_bigraph/experiments/comets.py +++ b/process_bigraph/experiments/comets.py @@ -30,6 +30,8 @@ def apply_non_negative(schema, current, update, core): # TODO -- check the function signature of the apply method and report missing keys upon registration +MODEL_FOR_TESTING = load_model('textbook') + class DynamicFBA(Process): """ Performs dynamic FBA. @@ -46,6 +48,7 @@ class DynamicFBA(Process): config_schema = { 'model_file': 'string', + 'model': 'Any', 'kinetic_params': 'map[tuple[float,float]]', 'biomass_reaction': { '_type': 'string', @@ -59,11 +62,17 @@ class DynamicFBA(Process): def __init__(self, config, core): super().__init__(config, core) - if not 'xml' in self.config['model_file']: + if self.config['model_file'] == 'TESTING': + self.model = MODEL_FOR_TESTING + elif not 'xml' in self.config['model_file']: # use the textbook model if no model file is provided self.model = load_model(self.config['model_file']) - else: + elif isinstance(self.config['model_file'], str): self.model = cobra.io.read_sbml_model(self.config['model_file']) + else: + # error handling + raise ValueError('Invalid model file') + for reaction_id, bounds in self.config['bounds'].items(): if bounds['lower'] is not None: @@ -385,7 +394,7 @@ def run_diffusion_process(): def run_comets(): - n_bins = (10, 10) + n_bins = (6, 6) initial_glucose = np.random.uniform(low=0, high=20, size=n_bins) initial_acetate = np.random.uniform(low=0, high=0, size=n_bins) @@ -397,7 +406,9 @@ def run_comets(): dfba_processes_dict[f'[{i},{j}]'] = { '_type': 'process', 'address': 'local:DynamicFBA', - 'config': dfba_config(), + 'config': dfba_config( + model_file='TESTING' # load the same model for all processes + ), 'inputs': { 'substrates': { 'glucose': ['..', 'fields', 'glucose', i, j], @@ -471,7 +482,7 @@ def run_comets(): sim = Composite({'state': composite_state}, core=core) - sim.update({}, 10.0) + sim.update({}, 100.0) results = sim.gather_results()