Skip to content

Commit

Permalink
Merge branch 'initial-state-projection' into core
Browse files Browse the repository at this point in the history
  • Loading branch information
prismofeverything committed Jan 13, 2024
2 parents 216a690 + ba15606 commit 0c6851a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions process_bigraph/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def schema(self):
'level': 'float'}}


def initial_state(self):
return {
'inputs': {
'level': 11.0}}


def update(self, state, interval):
return {
'level': state['level'] * self.config['rate']}
Expand Down
23 changes: 19 additions & 4 deletions process_bigraph/type_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
=============
"""

from bigraph_schema import Edge, TypeSystem, get_path, establish_path, set_path
from bigraph_schema import Edge, TypeSystem, get_path, establish_path, set_path, deep_merge
from process_bigraph.registry import protocol_registry


Expand Down Expand Up @@ -286,13 +286,28 @@ def infer_edge(self, schema, wires):

def initialize_edge_state(self, schema, path, edge):
initial_state = edge['instance'].initial_state()
ports = get_path(schema, path + ('_ports',))
input_ports = get_path(schema, path + ('_inputs',))
output_ports = get_path(schema, path + ('_outputs',))
ports = {'inputs': input_ports, 'outputs': output_ports}

return self.project_edge(
input_state = self.project_edge(
ports,
edge,
path[:-1],
initial_state)
initial_state,
ports_key='input')

output_state = self.project_edge(
ports,
edge,
path[:-1],
initial_state,
ports_key='output')

state = deep_merge(input_state, output_state)

return state


def dehydrate(self, schema):
return {}
Expand Down

0 comments on commit 0c6851a

Please sign in to comment.