diff --git a/process_bigraph/composite.py b/process_bigraph/composite.py index be99567..739681b 100644 --- a/process_bigraph/composite.py +++ b/process_bigraph/composite.py @@ -618,6 +618,7 @@ class Composite(Process): def load(cls, path, core=None): with open(path) as data: document = json.load(data) + composite = cls( document, core=core) diff --git a/process_bigraph/experiments/comets.py b/process_bigraph/experiments/comets.py index 9fc3511..e405d7d 100644 --- a/process_bigraph/experiments/comets.py +++ b/process_bigraph/experiments/comets.py @@ -8,27 +8,12 @@ from process_bigraph import Process, ProcessTypes, Composite from process_bigraph.experiments.parameter_scan import RunProcess -core = ProcessTypes() - # create new types def apply_non_negative(schema, current, update, core): new_value = current + update return max(0, new_value) -positive_float = { - '_type': 'positive_float', - '_inherit': 'float', - '_apply': apply_non_negative -} -core.register('positive_float', positive_float) - -bounds_type = { - 'lower': 'maybe[float]', - 'upper': 'maybe[float]' -} -core.register_process('bounds', bounds_type) - # TODO -- check the function signature of the apply method and report missing keys upon registration @@ -76,7 +61,6 @@ def __init__(self, config, core): # error handling raise ValueError('Invalid model file') - for reaction_id, bounds in self.config['bounds'].items(): if bounds['lower'] is not None: self.model.reactions.get_by_id(reaction_id).lower_bound = bounds['lower'] @@ -125,9 +109,6 @@ def update(self, state, interval): 'substrates': substrate_update, } -core.register_process('DynamicFBA', DynamicFBA) - - # Laplacian for 2D diffusion LAPLACIAN_2D = np.array([[0, 1, 0], [1, -4, 1], @@ -246,9 +227,6 @@ def diffusion_delta(self, state, interval, diffusion_coeff, advection_coeff): return updated_state - state -core.register_process('DiffusionAdvection', DiffusionAdvection) - - def dfba_config( model_file='textbook', kinetic_params={ @@ -294,6 +272,27 @@ def run_process( return run.update(initial_state) +def register_types(core): + core.register('positive_float', { + '_type': 'positive_float', + '_inherit': 'float', + '_apply': apply_non_negative}) + + core.register('bounds', { + 'lower': 'maybe[float]', + 'upper': 'maybe[float]'}) + + core.register_process( + 'DynamicFBA', + DynamicFBA) + + core.register_process( + 'DiffusionAdvection', + DiffusionAdvection) + + return core + + def run_dfba_spatial(): n_bins = (2, 2) @@ -396,7 +395,7 @@ def run_diffusion_process(): print(data) -def run_comets(): +def run_comets(core): n_bins = (6, 6) initial_glucose = np.random.uniform(low=0, high=20, size=n_bins) @@ -495,15 +494,18 @@ def run_comets(): other_results = load.gather_results() - assert results == other_results - - import ipdb; ipdb.set_trace() + np.testing.assert_equal( + results[('emitter',)][-1]['fields'], + other_results[('emitter',)][-1]['fields']) print(results) if __name__ == '__main__': - # run_dfba_spatial() - # run_diffusion_process() - run_comets() + core = ProcessTypes() + core = register_types(core) + + # run_dfba_spatial(core) + # run_diffusion_process(core) + run_comets(core)