Skip to content

Commit

Permalink
successfully loading a saved composite
Browse files Browse the repository at this point in the history
  • Loading branch information
prismofeverything committed Aug 28, 2024
1 parent 0d50bd4 commit aa11888
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
1 change: 1 addition & 0 deletions process_bigraph/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 31 additions & 29 deletions process_bigraph/experiments/comets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit aa11888

Please sign in to comment.