Skip to content

Commit

Permalink
merge with latest main
Browse files Browse the repository at this point in the history
  • Loading branch information
prismofeverything committed Feb 27, 2024
2 parents 5cfaec4 + eddbeaa commit afeec05
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
1 change: 0 additions & 1 deletion process_bigraph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pprint

from process_bigraph.protocols import local_lookup
from process_bigraph.composite import Process, Step, Composite, ProcessTypes


Expand Down
23 changes: 12 additions & 11 deletions process_bigraph/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import collections
from typing import Dict


from bigraph_schema import Edge, TypeSystem, get_path, validate_merge, establish_path, set_path, deep_merge
from bigraph_schema.registry import Registry

from process_bigraph.protocols import local_lookup, local_lookup_module


# TODO: implement these
def apply_process(current, update, schema, core):
def apply_process(schema, current, update, core):
process_schema = schema.copy()
process_schema.pop('_apply')
return core.apply(
Expand All @@ -26,17 +27,17 @@ def apply_process(current, update, schema, core):
update)


def check_process(state, schema, core):
def check_process(schema, state, core):
return 'instance' in state and isinstance(
state['instance'],
Edge)


def divide_process(value, schema, core):
def divide_process(schema, value, core):
return value


def serialize_process(value, schema, core):
def serialize_process(schema, value, core):
"""Serialize a process to a JSON-safe representation."""
# TODO -- need to get back the protocol: address and the config
process = value.copy()
Expand All @@ -57,7 +58,7 @@ def assert_interface(interface):
'float': 'float'}


def deserialize_process(encoded, schema, core):
def deserialize_process(schema, encoded, core):
"""Deserialize a process from a serialized state.
This function is used by the type system to deserialize a process.
Expand Down Expand Up @@ -91,7 +92,7 @@ def deserialize_process(encoded, schema, core):
encoded.get('interval'))

if not 'instance' in deserialized:
process = instantiate(config, core)
process = instantiate(config, core=core)
deserialized['instance'] = process

deserialized['config'] = config
Expand All @@ -100,7 +101,7 @@ def deserialize_process(encoded, schema, core):
return deserialized


def deserialize_step(encoded, schema, core):
def deserialize_step(schema, encoded, core):
deserialized = encoded.copy()
protocol, address = encoded['address'].split(':', 1)

Expand All @@ -120,7 +121,7 @@ def deserialize_step(encoded, schema, core):
encoded.get('config', {}))

if not 'instance' in deserialized:
process = instantiate(config, core)
process = instantiate(config, core=core)
deserialized['instance'] = process

deserialized['config'] = config
Expand Down Expand Up @@ -346,7 +347,6 @@ def lookup_address(self, address):
if protocol == 'local':
self.lookup_local(config)


def hierarchy_depth(hierarchy, path=()):
"""
Create a mapping of every path in the hierarchy to the node living at
Expand Down Expand Up @@ -383,7 +383,7 @@ class Step(Edge):


def __init__(self, config=None, core=None):
self.core = core
self.core = core or ProcessTypes()

if config is None:
config = {}
Expand Down Expand Up @@ -427,7 +427,8 @@ class can provide a ``defaults`` class variable to specify the
config_schema = {}

def __init__(self, config=None, core=None):
self.core = core
self.core = core or ProcessTypes()

if config is None:
config = {}

Expand Down
29 changes: 17 additions & 12 deletions process_bigraph/experiments/minimal_gillespie.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
from process_bigraph import Step, Process, Composite, ProcessTypes


@pytest.fixture
def core():
return ProcessTypes()


# 'map[float](default:1.0|apply:set)'
# 'float(default:1.0)'


EXPORT = {
'default 1': {
'_inherit': 'float',
'_default': 1.0}}


class GillespieInterval(Step):
config_schema = {
'ktsc': {
Expand Down Expand Up @@ -165,13 +166,14 @@ def update(self, state, interval):
return update


def test_gillespie_composite(core):
core.register(
'default 1', {
'_inherit': 'float',
'_default': 1.0})

@pytest.fixture
def core():
core = ProcessTypes()
core.import_types(EXPORT)
return core

def test_gillespie_composite(core):
composite_schema = {
# This all gets inferred -------------
# ==================================
Expand Down Expand Up @@ -280,7 +282,9 @@ def test_gillespie_composite(core):
# 'mRNA': {
# 'C': '21.0'}}}

gillespie = Composite(composite_schema, core)
gillespie = Composite(
composite_schema,
core=core)

updates = gillespie.update({
'DNA': {
Expand Down Expand Up @@ -311,6 +315,7 @@ def test_stochastic_deterministic_composite(core):

if __name__ == '__main__':
core = ProcessTypes()
core.import_types(EXPORT)

test_gillespie_composite(core)
test_union_tree(core)
26 changes: 18 additions & 8 deletions process_bigraph/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def update(self, state, interval):


def test_default_config(core):
process = IncreaseProcess({}, core)
process = IncreaseProcess(core=core)

assert process.config['rate'] == 0.1


Expand All @@ -56,14 +57,22 @@ def test_merge_collections(core):
assert c[('what',)] == [1, 2, 3, 4, 5, 11]


@pytest.fixture
def core():
return ProcessTypes()


def test_process(core):
process = IncreaseProcess({'rate': 0.2}, core)
process = IncreaseProcess({'rate': 0.2}, core=core)
interface = process.interface()
state = core.fill(interface['inputs'])
state = core.fill(interface['outputs'])
update = process.update({'level': 5.5}, 1.0)

new_state = core.apply(interface['outputs'], state, update)
new_state = core.apply(
interface['outputs'],
state,
update)

assert new_state['level'] == 1.1

Expand Down Expand Up @@ -96,7 +105,7 @@ def test_composite(core):
'interval': 1.0,
'inputs': {'level': ['value']},
'outputs': {'level': ['value']}},
'value': '11.11'}}, core)
'value': '11.11'}}, core=core)

initial_state = {'exchange': 3.33}

Expand All @@ -120,7 +129,7 @@ def test_infer(core):
'config': {'rate': '0.3'},
'inputs': {'level': ['value']},
'outputs': {'level': ['value']}},
'value': '11.11'}}, core)
'value': '11.11'}}, core=core)

assert composite.composition['value']['_type'] == 'float'
assert composite.state['value'] == 11.11
Expand Down Expand Up @@ -184,8 +193,7 @@ def test_step_initialization(core):
'a': ['B'],
'b': ['C']},
'outputs': {
'c': ['D']}}}}, core)

'c': ['D']}}}}, core=core)

assert composite.state['D'] == (13 + 21) * 21

Expand Down Expand Up @@ -247,7 +255,9 @@ def test_dependencies(core):
'outputs': {
'c': ['i']}}}

composite = Composite({'state': operation}, core)
composite = Composite(
{'state': operation},
core=core)

assert composite.state['h'] == -17396.469884

Expand Down

0 comments on commit afeec05

Please sign in to comment.