Skip to content

Commit

Permalink
composite type initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
prismofeverything committed Nov 1, 2023
1 parent 223cdf5 commit 9c89e6d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 50 deletions.
1 change: 1 addition & 0 deletions process_bigraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
# TODO
process_registry.register('console-emitter', ConsoleEmitter)
process_registry.register('ram-emitter', RAMEmitter)

16 changes: 7 additions & 9 deletions process_bigraph/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def build_step_network(steps):

if ancestors[step_key]['output_paths'] is None:
ancestors[step_key]['output_paths'] = find_leaves(
wires['outputs'])
wires.get('outputs', {}))
output_paths = ancestors[step_key]['output_paths']

for input in input_paths:
Expand Down Expand Up @@ -414,17 +414,19 @@ def determine_steps(steps, remaining, fulfilled):


class Composite(Process):
"""Composite parent class.
"""
Composite parent class.
"""


config_schema = {
# TODO: add schema type
'composition': 'tree[any]',
'state': 'tree[any]',
'schema': 'tree[any]',
'bridge': 'wires',
'global_time_precision': 'maybe[float]',
}
'global_time_precision': 'maybe[float]'}


# TODO: if processes are serialized, deserialize them first
def __init__(self, config=None, local_types=None):
Expand Down Expand Up @@ -669,8 +671,6 @@ def apply_updates(self, updates):
series = [series]

for update in series:
# print(update)

paths = hierarchy_depth(update)
update_paths.extend(paths.keys())

Expand Down Expand Up @@ -778,8 +778,6 @@ def determine_steps(self):


def run_steps(self, step_paths):
print(f'running steps: {step_paths}')

if len(step_paths) > 0:
updates = []
for step_path in step_paths:
Expand Down
1 change: 1 addition & 0 deletions process_bigraph/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@

#: Maps process names to :term:`protocol methods`
protocol_registry = Registry()

44 changes: 5 additions & 39 deletions process_bigraph/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,6 @@ def update(self, state, interval):
'level': state['level'] * self.config['rate']}


def test_serialized_composite():
# This should specify the same thing as above
composite_schema = {
'_type': 'process[exchange:float]',
'address': 'local:!process_bigraph.composite.Composite',
'config': {
'state': {
'increase': {
'_type': 'process[level:float]',
'address': 'local:!process_bigraph.tests.IncreaseProcess',
'config': {'rate': '0.3'},
'wires': {'level': ['value']}
},
'value': '11.11',
},
'schema': {
'increase': 'process[level:float]',
# 'increase': 'process[{"level":"float","down":{"a":"int"}}]',
'value': 'float',
},
'bridge': {
'exchange': 'value'
},
}
}

composite_instance = types.deserialize(composite_schema, {})
composite_instance.update()


def test_default_config():
process = IncreaseProcess()
assert process.config['rate'] == 0.1
Expand Down Expand Up @@ -259,6 +229,11 @@ def test_dependencies():
assert composite.state['h'] == -17396.469884


def test_dependency_cycle():
# test a step network with cycles in a few ways
pass


class SimpleCompartment(Process):
config_schema = {
'id': 'string'}
Expand Down Expand Up @@ -329,13 +304,6 @@ def update(self, state, interval):


# TODO: create reaction registry, register this under "divide"
def divide_reaction(config):
return {
'redex': {
config['id']: {}},
'reactum': {
daughter_config['id']: daughter_config['state']
for daughter_config in config['daughters']}}


def engulf_reaction(config):
Expand Down Expand Up @@ -375,8 +343,6 @@ def test_reaction():
'inner': ['inner']}}}}}}




if __name__ == '__main__':
test_default_config()
test_merge_collections()
Expand Down
2 changes: 1 addition & 1 deletion process_bigraph/type_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def infer_schema(self, schema, state, top_state=None, path=None):
else:
for key, value in state.items():
inner_path = path + (key,)
if get_path(schema, inner_path) is None or get_path(state, inner_path) is None:
if get_path(schema, inner_path) is None or get_path(state, inner_path) is None or (isinstance(value, dict) and '_type' in value):
schema, top_state = self.infer_schema(
schema,
value,
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[pytest]
python_files = *.py
addopts = --doctest-modules --strict-markers
testpaths = vivarium
testpaths = process_bigraph
markers =
slow: indicates slow tests (deselect with '-m "not slow"')

0 comments on commit 9c89e6d

Please sign in to comment.