From 46a61fdbdcec120fa76387cc1a18a73aae7889af Mon Sep 17 00:00:00 2001 From: Eran Date: Wed, 14 Feb 2024 19:21:04 -0500 Subject: [PATCH] work in progress --- builder/builder_api.py | 31 +++-- notebooks/demo.ipynb | 290 +++++++++++++++++++---------------------- 2 files changed, 155 insertions(+), 166 deletions(-) diff --git a/builder/builder_api.py b/builder/builder_api.py index cdf8f01..0c5d29b 100644 --- a/builder/builder_api.py +++ b/builder/builder_api.py @@ -122,6 +122,7 @@ def decorator(cls): return decorator else: + # Check if address is a string if isinstance(address, str): protocol, addr = address.split(':', 1) @@ -133,6 +134,7 @@ def decorator(cls): self.core.process_registry.register(process_name, process_class, force=True) else: raise ValueError('Only local addresses starting with "!" are supported') + # Check if address is a class object elif issubclass(address, Edge): self.core.process_registry.register(process_name, address, force=True) @@ -204,7 +206,7 @@ def add_process( """ config = config or {} config.update(kwargs) - edge_type = 'process' + edge_type = 'process' # TODO -- don't hardcode as process # make the schema initial_state = { @@ -221,18 +223,25 @@ def add_process( self.tree = builder_tree_from_dict(state) self.schema = schema or {} - # reset compiled composite - self.compile() + # complete the composite + self.complete() + + def complete(self): + if self.parent: + return self.parent.complete() + else: + self.schema, tree = self.core.complete(self.schema, dict_from_builder_tree(self.tree)) + self.tree = builder_tree_from_dict(tree) def connect(self, port=None, target=None): - assert self.core.check('edge', self.schema) + assert self.core.check('edge', dict_from_builder_tree(self.tree)) if port in self.schema['_inputs']: self.tree['inputs'][port] = target if port in self.schema['_outputs']: self.tree['outputs'][port] = target # reset compiled composite - self.compile() + self.complete() def document(self): doc = self.core.serialize( @@ -307,14 +316,14 @@ def ports(self, print_ports=False): def visualize(self, filename=None, out_dir=None, **kwargs): if filename and not out_dir: out_dir = 'out' - if not self.compiled_composite: - self.compile() tree_dict = dict_from_builder_tree(self.tree) - tree_dict = fill_process_ports(tree_dict, self.schema) + schema_dict = fill_process_ports(tree_dict, self.schema) return plot_bigraph( tree_dict, + schema=self.schema, + core=self.core, out_dir=out_dir, filename=filename, # show_process_schema=False, @@ -361,7 +370,7 @@ def build_gillespie(): # build the bigraph - gillespie.update_tree(state={'variables': [0, 1, 2]}) # this should allow us to set variables + # gillespie.update_tree(state={'variables': [0, 1, 2]}) # this should allow us to set variables ## add processes gillespie['event_process'].add_process( @@ -373,6 +382,10 @@ def build_gillespie(): # inputs={'port_id': ['store']} # we should be able to set the wires directly like this ) + gillespie['event_process'].connect(port='mRNA', target=['mRNA_store']) + + gillespie.compile() + ## visualize part-way through build gillespie.visualize(filename='bigraph1', out_dir='out') diff --git a/notebooks/demo.ipynb b/notebooks/demo.ipynb index ae0a2ff..cf9d166 100644 --- a/notebooks/demo.ipynb +++ b/notebooks/demo.ipynb @@ -49,7 +49,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "['ram-emitter', 'console-emitter']\n" + "['console-emitter', 'ram-emitter']\n" ] } ], @@ -79,7 +79,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "['GillespieInterval', 'ram-emitter', 'console-emitter', 'GillespieEvent']\n" + "['GillespieEvent', 'console-emitter', 'ram-emitter', 'GillespieInterval']\n" ] } ], @@ -106,20 +106,9 @@ "execution_count": 7, "id": "b094f1e5-5202-48d0-8bdd-57bbdded7fd1", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "b.compile()" + "# b.compile()" ] }, { @@ -154,89 +143,152 @@ { "cell_type": "code", "execution_count": 9, - "id": "c9f462bb-5316-4724-aa8e-b3b71eb379b2", + "id": "6e496c34-72a4-4197-aadc-1f95c031d743", + "metadata": {}, + "outputs": [], + "source": [ + "# b.schema" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "da4365f0-7a55-4654-a21b-35a5b145b52d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{\n", - "'event_process': {\n", - " '_type': 'process',\n", - " 'address': 'local:GillespieEvent',\n", - " 'config': {\n", - " 'kdeg': 1.0,\n", - " 'ktsc': 5.0\n", - " },\n", - " 'inputs': {},\n", - " 'outputs': {},\n", - " 'instance': ,\n", - " 'interval': 1.0\n", - "},\n", - "'global_time': 0.0\n", - "}" + "{'_type': 'process',\n", + " '_default': {'inputs': {}, 'outputs': {}},\n", + " '_apply': 'process_bigraph.composite.apply_process',\n", + " '_serialize': 'process_bigraph.composite.serialize_process',\n", + " '_deserialize': 'process_bigraph.composite.deserialize_process',\n", + " '_check': 'process_bigraph.composite.check_process',\n", + " '_type_parameters': ['inputs', 'outputs'],\n", + " '_description': '',\n", + " 'inputs': {'_type': 'wires',\n", + " '_default': {},\n", + " '_apply': 'bigraph_schema.registry.apply_tree',\n", + " '_serialize': 'bigraph_schema.type_system.serialize_tree',\n", + " '_deserialize': 'bigraph_schema.type_system.deserialize_tree',\n", + " '_divide': 'bigraph_schema.type_system.divide_tree',\n", + " '_check': 'bigraph_schema.type_system.check_tree',\n", + " '_type_parameters': ['leaf'],\n", + " '_description': 'mapping from str to some type in a potentially nested form',\n", + " '_leaf': {'_type': 'path',\n", + " '_default': [],\n", + " '_apply': 'bigraph_schema.type_system.apply_path',\n", + " '_check': 'bigraph_schema.type_system.check_list',\n", + " '_serialize': 'bigraph_schema.type_system.serialize_list',\n", + " '_deserialize': 'bigraph_schema.type_system.deserialize_list',\n", + " '_divide': 'bigraph_schema.type_system.divide_list',\n", + " '_type_parameters': ['element'],\n", + " '_description': 'general list type (or sublists)',\n", + " '_element': {'_type': 'string',\n", + " '_default': '',\n", + " '_apply': 'bigraph_schema.type_system.replace',\n", + " '_check': 'bigraph_schema.type_system.check_string',\n", + " '_serialize': 'bigraph_schema.type_system.serialize_string',\n", + " '_deserialize': 'bigraph_schema.type_system.deserialize_string',\n", + " '_description': '64-bit integer'},\n", + " '_inherit': ['list[string]']},\n", + " '_inherit': ['tree[path]']},\n", + " 'outputs': {'_type': 'wires',\n", + " '_default': {},\n", + " '_apply': 'bigraph_schema.registry.apply_tree',\n", + " '_serialize': 'bigraph_schema.type_system.serialize_tree',\n", + " '_deserialize': 'bigraph_schema.type_system.deserialize_tree',\n", + " '_divide': 'bigraph_schema.type_system.divide_tree',\n", + " '_check': 'bigraph_schema.type_system.check_tree',\n", + " '_type_parameters': ['leaf'],\n", + " '_description': 'mapping from str to some type in a potentially nested form',\n", + " '_leaf': {'_type': 'path',\n", + " '_default': [],\n", + " '_apply': 'bigraph_schema.type_system.apply_path',\n", + " '_check': 'bigraph_schema.type_system.check_list',\n", + " '_serialize': 'bigraph_schema.type_system.serialize_list',\n", + " '_deserialize': 'bigraph_schema.type_system.deserialize_list',\n", + " '_divide': 'bigraph_schema.type_system.divide_list',\n", + " '_type_parameters': ['element'],\n", + " '_description': 'general list type (or sublists)',\n", + " '_element': {'_type': 'string',\n", + " '_default': '',\n", + " '_apply': 'bigraph_schema.type_system.replace',\n", + " '_check': 'bigraph_schema.type_system.check_string',\n", + " '_serialize': 'bigraph_schema.type_system.serialize_string',\n", + " '_deserialize': 'bigraph_schema.type_system.deserialize_string',\n", + " '_description': '64-bit integer'},\n", + " '_inherit': ['list[string]']},\n", + " '_inherit': ['tree[path]']},\n", + " '_inherit': ['edge'],\n", + " '_divide': 'process_bigraph.composite.divide_process',\n", + " 'interval': {'_type': 'interval',\n", + " '_apply': 'set',\n", + " '_check': 'bigraph_schema.type_system.check_float',\n", + " '_serialize': 'bigraph_schema.type_system.to_string',\n", + " '_description': '64-bit floating point precision number',\n", + " '_default': '1.0',\n", + " '_deserialize': 'bigraph_schema.type_system.deserialize_float',\n", + " '_divide': 'bigraph_schema.type_system.divide_float',\n", + " '_inherit': ['float']},\n", + " '_inputs': {'mRNA': 'map[float]',\n", + " 'DNA': {'A gene': 'float', 'B gene': 'float'}},\n", + " '_outputs': {'mRNA': 'map[float]'}}" ] }, - "execution_count": 9, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "b" + "b['event_process'].schema" ] }, { "cell_type": "code", - "execution_count": 10, - "id": "79809baf-1d87-475a-b85f-3729f4716cb4", + "execution_count": 11, + "id": "c9f462bb-5316-4724-aa8e-b3b71eb379b2", "metadata": {}, "outputs": [ { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('global_time',)\n", - "\n", - "global_time\n", - "\n", - "\n", - "\n", - "('event_process',)\n", - "\n", - "event_process\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" + "ename": "Exception", + "evalue": "cannot wire mRNA as we are already at the top level {'mRNA': 'map[float]', 'DNA': {'A gene': 'float', 'B gene': 'float'}}", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mException\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[11], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mb\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mevent_process\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43mport\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mmRNA\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mmRNA_store\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2\u001b[0m b\n", + "File \u001b[0;32m~/code/bigraph-builder/builder/builder_api.py:241\u001b[0m, in \u001b[0;36mBuilder.connect\u001b[0;34m(self, port, target)\u001b[0m\n\u001b[1;32m 238\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtree[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124moutputs\u001b[39m\u001b[38;5;124m'\u001b[39m][port] \u001b[38;5;241m=\u001b[39m target\n\u001b[1;32m 240\u001b[0m \u001b[38;5;66;03m# reset compiled composite\u001b[39;00m\n\u001b[0;32m--> 241\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcomplete\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/code/bigraph-builder/builder/builder_api.py:230\u001b[0m, in \u001b[0;36mBuilder.complete\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 229\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcomplete\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m--> 230\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mschema, tree \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcore\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcomplete\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mschema\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdict_from_builder_tree\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtree\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 231\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtree \u001b[38;5;241m=\u001b[39m builder_tree_from_dict(tree)\n", + "File \u001b[0;32m~/code/bigraph-schema/bigraph_schema/type_system.py:1252\u001b[0m, in \u001b[0;36mTypeSystem.complete\u001b[0;34m(self, initial_schema, initial_state)\u001b[0m\n\u001b[1;32m 1248\u001b[0m full_schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maccess(\n\u001b[1;32m 1249\u001b[0m initial_schema)\n\u001b[1;32m 1251\u001b[0m \u001b[38;5;66;03m# hydrate the state given the initial composition\u001b[39;00m\n\u001b[0;32m-> 1252\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mhydrate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1253\u001b[0m \u001b[43m \u001b[49m\u001b[43mfull_schema\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1254\u001b[0m \u001b[43m \u001b[49m\u001b[43minitial_state\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1256\u001b[0m \u001b[38;5;66;03m# fill in the parts of the composition schema\u001b[39;00m\n\u001b[1;32m 1257\u001b[0m \u001b[38;5;66;03m# determined by the state\u001b[39;00m\n\u001b[1;32m 1258\u001b[0m schema, state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minfer_schema(\n\u001b[1;32m 1259\u001b[0m full_schema,\n\u001b[1;32m 1260\u001b[0m state)\n", + "File \u001b[0;32m~/code/bigraph-schema/bigraph_schema/type_system.py:1244\u001b[0m, in \u001b[0;36mTypeSystem.hydrate\u001b[0;34m(self, schema, state)\u001b[0m\n\u001b[1;32m 1241\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mhydrate\u001b[39m(\u001b[38;5;28mself\u001b[39m, schema, state):\n\u001b[1;32m 1242\u001b[0m \u001b[38;5;66;03m# TODO: support partial hydration (!)\u001b[39;00m\n\u001b[1;32m 1243\u001b[0m hydrated \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhydrate_state(schema, state)\n\u001b[0;32m-> 1244\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfill\u001b[49m\u001b[43m(\u001b[49m\u001b[43mschema\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mhydrated\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/code/bigraph-schema/bigraph_schema/type_system.py:753\u001b[0m, in \u001b[0;36mTypeSystem.fill\u001b[0;34m(self, original_schema, state)\u001b[0m\n\u001b[1;32m 747\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfill\u001b[39m(\u001b[38;5;28mself\u001b[39m, original_schema, state\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[1;32m 748\u001b[0m \u001b[38;5;66;03m# # Removing deepcopy means the state may be updated\u001b[39;00m\n\u001b[1;32m 749\u001b[0m \u001b[38;5;66;03m# if state is not None:\u001b[39;00m\n\u001b[1;32m 750\u001b[0m \u001b[38;5;66;03m# state = copy.deepcopy(state)\u001b[39;00m\n\u001b[1;32m 751\u001b[0m schema \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39maccess(original_schema)\n\u001b[0;32m--> 753\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfill_state\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 754\u001b[0m \u001b[43m \u001b[49m\u001b[43mschema\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 755\u001b[0m \u001b[43m \u001b[49m\u001b[43mstate\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstate\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/code/bigraph-schema/bigraph_schema/type_system.py:714\u001b[0m, in \u001b[0;36mTypeSystem.fill_state\u001b[0;34m(self, schema, state, top, path, type_key, context)\u001b[0m\n\u001b[1;32m 712\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_inputs\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m schema:\n\u001b[1;32m 713\u001b[0m inputs \u001b[38;5;241m=\u001b[39m state\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124minputs\u001b[39m\u001b[38;5;124m'\u001b[39m, {})\n\u001b[0;32m--> 714\u001b[0m state \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfill_ports\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 715\u001b[0m \u001b[43m \u001b[49m\u001b[43mschema\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_inputs\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 716\u001b[0m \u001b[43m \u001b[49m\u001b[43mwires\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 717\u001b[0m \u001b[43m \u001b[49m\u001b[43mstate\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstate\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 718\u001b[0m \u001b[43m \u001b[49m\u001b[43mtop\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 719\u001b[0m \u001b[43m \u001b[49m\u001b[43mpath\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpath\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 721\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_outputs\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m schema:\n\u001b[1;32m 722\u001b[0m outputs \u001b[38;5;241m=\u001b[39m state\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124moutputs\u001b[39m\u001b[38;5;124m'\u001b[39m, {})\n", + "File \u001b[0;32m~/code/bigraph-schema/bigraph_schema/type_system.py:663\u001b[0m, in \u001b[0;36mTypeSystem.fill_ports\u001b[0;34m(self, schema, wires, state, top, path)\u001b[0m\n\u001b[1;32m 660\u001b[0m subwires \u001b[38;5;241m=\u001b[39m (subwires,)\n\u001b[1;32m 662\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(path) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m--> 663\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\n\u001b[1;32m 664\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcannot wire \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mport_key\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m as we are already at the top level \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mschema\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 666\u001b[0m peer \u001b[38;5;241m=\u001b[39m get_path(\n\u001b[1;32m 667\u001b[0m top,\n\u001b[1;32m 668\u001b[0m path[:\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m])\n\u001b[1;32m 670\u001b[0m destination \u001b[38;5;241m=\u001b[39m establish_path(\n\u001b[1;32m 671\u001b[0m peer,\n\u001b[1;32m 672\u001b[0m subwires[:\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m],\n\u001b[1;32m 673\u001b[0m top\u001b[38;5;241m=\u001b[39mtop,\n\u001b[1;32m 674\u001b[0m cursor\u001b[38;5;241m=\u001b[39mpath[:\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m])\n", + "\u001b[0;31mException\u001b[0m: cannot wire mRNA as we are already at the top level {'mRNA': 'map[float]', 'DNA': {'A gene': 'float', 'B gene': 'float'}}" + ] } ], + "source": [ + "b['event_process'].connect(port='mRNA', target=['mRNA_store'])\n", + "b" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "79809baf-1d87-475a-b85f-3729f4716cb4", + "metadata": {}, + "outputs": [], "source": [ "b.visualize()" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "72088795-49c9-4e28-b539-1bdacd70ea91", "metadata": {}, "outputs": [], @@ -249,7 +301,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "1ee84904801a9ab", "metadata": { "ExecuteTime": { @@ -290,7 +342,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "dae8ca8db70c4845", "metadata": { "ExecuteTime": { @@ -301,15 +353,7 @@ "outputs_hidden": false } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['GillespieInterval', 'console-emitter', 'toy', 'GillespieEvent', 'ram-emitter']\n" - ] - } - ], + "outputs": [], "source": [ "b.list_processes()" ] @@ -324,7 +368,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "8b1f49a78de17642", "metadata": { "ExecuteTime": { @@ -343,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "id": "329e64816e8ff626", "metadata": { "ExecuteTime": { @@ -354,25 +398,14 @@ "outputs_hidden": false } }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'_inputs': {}, '_outputs': {}}" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "b['toy'].ports()" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "3b1dd8569f3bb67a", "metadata": { "ExecuteTime": { @@ -383,58 +416,14 @@ "outputs_hidden": false } }, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "bigraph\n", - "\n", - "\n", - "\n", - "('global_time',)\n", - "\n", - "global_time\n", - "\n", - "\n", - "\n", - "('event_process',)\n", - "\n", - "event_process\n", - "\n", - "\n", - "\n", - "('toy',)\n", - "\n", - "toy\n", - "\n", - "\n", - "\n" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "b.visualize()" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "id": "f02c15797bdb73b8", "metadata": { "ExecuteTime": { @@ -445,20 +434,7 @@ "outputs_hidden": false } }, - "outputs": [ - { - "ename": "AssertionError", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[17], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mb\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mtoy\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43mport\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mA\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mA_store\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;66;03m# b['toy'].connect(port='B', target='B_store') # TODO -- compile is trying to connect A at the wrong level??\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m# b['toy'].connect(port='C', target='C_store')\u001b[39;00m\n", - "File \u001b[0;32m~/code/bigraph-builder/builder/builder_api.py:228\u001b[0m, in \u001b[0;36mBuilder.connect\u001b[0;34m(self, port, target)\u001b[0m\n\u001b[1;32m 227\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mconnect\u001b[39m(\u001b[38;5;28mself\u001b[39m, port\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, target\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[0;32m--> 228\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcore\u001b[38;5;241m.\u001b[39mcheck(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124medge\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mschema)\n\u001b[1;32m 229\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m port \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mschema[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_inputs\u001b[39m\u001b[38;5;124m'\u001b[39m]:\n\u001b[1;32m 230\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtree[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124minputs\u001b[39m\u001b[38;5;124m'\u001b[39m][port] \u001b[38;5;241m=\u001b[39m target\n", - "\u001b[0;31mAssertionError\u001b[0m: " - ] - } - ], + "outputs": [], "source": [ "b['toy'].connect(port='A', target='A_store')\n", "# b['toy'].connect(port='B', target='B_store') # TODO -- compile is trying to connect A at the wrong level??\n",