Skip to content

Commit

Permalink
nested observables
Browse files Browse the repository at this point in the history
  • Loading branch information
prismofeverything committed Apr 25, 2024
1 parent ad716b7 commit 17d8927
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 33 deletions.
16 changes: 8 additions & 8 deletions process_bigraph/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,11 @@ def query(self, query=None):
return result


def test_emitter():
composite = Composite({})

composite.add_emitter(['emitters', 'ram'], 'ram-emitter')
composite.emit_port(
['emitters', 'ram'],
['processes', 'translation'],
['outputs', 'protein'])
# def test_emitter():
# composite = Composite({})

# composite.add_emitter(['emitters', 'ram'], 'ram-emitter')
# composite.emit_port(
# ['emitters', 'ram'],
# ['processes', 'translation'],
# ['outputs', 'protein'])
79 changes: 54 additions & 25 deletions process_bigraph/experiments/parameter_scan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy
import numpy as np

from bigraph_schema import get_path, set_path
from bigraph_schema import get_path, set_path, transform_path
from process_bigraph import Step, Process, Composite, ProcessTypes, interval_time_precision, deep_merge


Expand Down Expand Up @@ -139,9 +139,8 @@ def __init__(self, config, core):
set_path(
self.inputs_config,
observable,
[observable[-1]])

import ipdb; ipdb.set_trace()
observable)
# [observable[-1]])

emit_config = dict(
{'time': 'float'},
Expand Down Expand Up @@ -199,17 +198,6 @@ def outputs(self):
{'time': 'list[float]'},
**self.results_schema)}

# outputs = self.process.outputs()
# outputs['time'] = 'float'

# return {
# 'results': {
# output_key: {
# '_type': 'list',
# '_apply': 'set',
# '_element': output_schema}
# for output_key, output_schema in outputs.items()}}


def update(self, inputs):
# TODO: instead of the composite being a reference it is instead read through
Expand All @@ -223,7 +211,9 @@ def update(self, inputs):
histories = self.composite.gather_results()

results = {
key: timeseries_from_history(history)
key: timeseries_from_history(
history,
self.config['observables'] + [['time']])
for key, history in histories.items()}

all_results = {}
Expand All @@ -233,13 +223,18 @@ def update(self, inputs):
return {'results': all_results}


def timeseries_from_history(history):
def timeseries_from_history(history, observables):
results = {}
for moment in history:
for key, value in moment.items():
if key not in results:
results[key] = []
results[key].append(value)
for observable in observables:
def transform(before):
if not before:
before = []
value = get_path(moment, observable)
before.append(value)
return before

transform_path(results, observable, transform)

return results

Expand Down Expand Up @@ -358,8 +353,6 @@ def outputs(self):
def update(self, inputs):
results = self.scan.update({}, 0.0)

import ipdb; ipdb.set_trace()

update = {}
for result in results:
observable_list = []
Expand Down Expand Up @@ -432,6 +425,43 @@ def test_run_process():
assert results[0]['results']['species'][0]['A'] == initial_A


def test_nested_wires():
timestep = 0.1
runtime = 10.0

initial_A = 11.11

state = {
'species': {'A': initial_A},
'run': {
'_type': 'step',
'address': 'local:!process_bigraph.experiments.parameter_scan.RunProcess',
'config': {
'process_address': 'local:!process_bigraph.experiments.parameter_scan.ToySystem',
'process_config': {
'rates': {
'A': {
'kdeg': 1.1,
'ksynth': 0.9}}},
'observables': [['species', 'A']],
'timestep': timestep,
'runtime': runtime},
# '_outputs': {'results': {'_emit': True}},
'inputs': {'species': ['species']},
'outputs': {'results': ['A_results']}}}

process = Composite({
'bridge': {
'outputs': {
'results': ['A_results']}},
'state': state})

results = process.update({}, 0.0)

assert results[0]['results']['time'][-1] == runtime
assert results[0]['results']['species']['A'][0] == initial_A


def test_parameter_scan():
# TODO: make a parameter scan with a biosimulator process,
# ie - Copasi
Expand Down Expand Up @@ -470,8 +500,6 @@ def test_parameter_scan():
# result = scan.update({})
result = scan.update({}, 0.0)

import ipdb; ipdb.set_trace()


def test_composite_workflow():
# TODO: Make a workflow with a composite inside
Expand All @@ -491,4 +519,5 @@ def test_composite_workflow():

if __name__ == '__main__':
test_run_process()
test_nested_wires()
test_parameter_scan()

0 comments on commit 17d8927

Please sign in to comment.