From bcfc17fe60ff2aee68704dda204d45c2157c0483 Mon Sep 17 00:00:00 2001 From: Eran Date: Fri, 5 Jan 2024 18:50:54 -0500 Subject: [PATCH] wip --- builder/builder_api.py | 63 +++++++++++----- notebooks/demo.ipynb | 166 +++++++++++++++++++++++++++-------------- 2 files changed, 152 insertions(+), 77 deletions(-) diff --git a/builder/builder_api.py b/builder/builder_api.py index 12ce5b4..bb7aac4 100644 --- a/builder/builder_api.py +++ b/builder/builder_api.py @@ -10,12 +10,15 @@ import pprint import warnings -from process_bigraph import Process, Composite, types, register_process +from process_bigraph import Process, Composite, types from process_bigraph import process_registry as PROCESS_REGISTRY from process_bigraph.experiments.minimal_gillespie import GillespieEvent, GillespieInterval from bigraph_viz import plot_bigraph +# PROCESS_REGISTRY = types.process_registry + + pretty = pprint.PrettyPrinter(indent=2) @@ -78,12 +81,20 @@ def fill_process_ports(tree, schema): class Builder: - def __init__(self, tree=None, schema=None, process_registry=None): + def __init__(self, tree=None, schema=None, process_registry=None, parent=None): super().__init__() self.tree = builder_tree_from_dict(tree) self.schema = schema or {} # TODO -- need to track schema self.compiled_composite = None - self.process_registry = process_registry or PROCESS_REGISTRY + self.process_registry = process_registry or PROCESS_REGISTRY # THis should maybe be the types.process_registry + self.parent = parent + + def top(self): + # recursively get the top parent + if self.parent: + return self.parent.top() + else: + return self def __repr__(self): return f"Builder({pf(self.tree)})" @@ -113,7 +124,7 @@ def __getitem__(self, keys): first_key = keys[0] if first_key not in self.tree: - self.tree[first_key] = Builder() + self.tree[first_key] = Builder(parent=self) remaining = keys[1:] if len(remaining) > 0: @@ -170,12 +181,9 @@ def add_process( self.schema = schema # reset compiled composite - self.compiled_composite = None + self.compile() def connect(self, port=None, target=None): - if not self.compiled_composite: - self.compile() - assert self.schema.get('_type') in EDGE_KEYS, f"Invalid type for connect: {self.schema}, needs to be in {EDGE_KEYS}" if port in self.schema['_inputs']: self.tree['inputs'][port] = target @@ -183,7 +191,7 @@ def connect(self, port=None, target=None): self.tree['outputs'][port] = target # reset compiled composite - self.compiled_composite = None + self.compile() def document(self): doc = types.serialize( @@ -205,12 +213,14 @@ def write(self, filename, outdir='out'): print(f"File '{filename}' successfully written in '{outdir}' directory.") def compile(self): - self.schema, tree = types.complete( - self.schema, - dict_from_builder_tree(self.tree) + top = self.top() + + top.schema, tree = types.complete( + top.schema, + dict_from_builder_tree(top.tree) ) - self.tree = builder_tree_from_dict(tree) - self.compiled_composite = Composite({'state': tree, 'composition': self.schema}) + top.tree = builder_tree_from_dict(tree) + top.compiled_composite = Composite({'state': tree, 'composition': top.schema}) def run(self, interval): if not self.compiled_composite: @@ -218,7 +228,7 @@ def run(self, interval): self.compiled_composite.run(interval) def ports(self): - self.compile() + # self.compile() tree_dict = dict_from_builder_tree(self.tree) tree_type = tree_dict.get('_type') if not tree_type: @@ -247,6 +257,22 @@ def plot(self, filename=None, out_dir=None, **kwargs): def get_results(self, query=None): return self.compiled_composite.gather_results(query) + def add_emitter(self, emitter='ram-emitter', protocol='local', emit_keys=None): + emitter_schema = { + 'emitter': { + '_type': 'step', + 'address': f'{protocol}:{emitter}', + 'config': { + 'ports': { + 'inputs': emit_keys or 'tree[any]' # TODO -- these should be filled in automatically, but also turn off paths + } + }, + 'wires': { + 'inputs': emit_keys or 'tree[any]' # TODO -- these should be filled in automatically + } + } + } + def build_gillespie(): # register processes @@ -257,7 +283,6 @@ def build_gillespie(): gillespie['event_process'].add_process( name='GillespieEvent', kdeg=1.0, # kwargs fill parameters in the config - ) gillespie['interval_process'].add_process( name='process_bigraph.experiments.minimal_gillespie.GillespieInterval', @@ -282,7 +307,7 @@ def build_gillespie(): # This needs to work node = gillespie['path', 'to'] - # node.add_process() + node.add_process() def test1(): @@ -314,9 +339,9 @@ def update(self, state, interval): print(ports) # b.plot(filename='toy[1]') - b['toy'].connect(port='A', target='A_store') + b['toy'].connect(port='A', target=['A_store']) b['A_store'] = 2.3 - b['toy'].connect(port='B', target='B_store') + b['toy'].connect(port='B', target=['B_store']) b.plot(filename='toy[2]') # b.write(filename='toy[2]', outdir='out') diff --git a/notebooks/demo.ipynb b/notebooks/demo.ipynb index e16b149..ea492e3 100644 --- a/notebooks/demo.ipynb +++ b/notebooks/demo.ipynb @@ -2,12 +2,12 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "id": "b385dca6-942d-472c-9963-13b8cb33843c", "metadata": { "ExecuteTime": { - "end_time": "2024-01-04T18:21:10.713077Z", - "start_time": "2024-01-04T18:21:10.066013Z" + "end_time": "2024-01-05T23:20:40.215672Z", + "start_time": "2024-01-05T23:20:40.203405Z" } }, "outputs": [], @@ -18,12 +18,12 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "id": "30297af1-2d65-43d9-9ab7-0589d94a8cfe", "metadata": { "ExecuteTime": { - "end_time": "2024-01-04T18:21:10.716181Z", - "start_time": "2024-01-04T18:21:10.713591Z" + "end_time": "2024-01-05T23:20:40.215813Z", + "start_time": "2024-01-05T23:20:40.212345Z" } }, "outputs": [], @@ -33,13 +33,13 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "outputs": [ { "data": { - "text/plain": "['smoldyn_process',\n 'console-emitter',\n 'tellurium_step',\n 'cobra',\n 'ram-emitter',\n 'copasi',\n 'tellurium_process',\n 'database-emitter']" + "text/plain": "['database-emitter',\n 'smoldyn_process',\n 'tellurium_process',\n 'copasi',\n 'console-emitter',\n 'tellurium_step',\n 'ram-emitter',\n 'cobra']" }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -50,31 +50,47 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:10.720884Z", - "start_time": "2024-01-04T18:21:10.717768Z" + "end_time": "2024-01-05T23:20:40.224957Z", + "start_time": "2024-01-05T23:20:40.217244Z" } }, "id": "979e0bd85a31d4b0" }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "outputs": [], "source": [ - "# b['cobra'].add_process(name='cobra')" + "# b['fba'].add_process(name='cobra')" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:10.722818Z", - "start_time": "2024-01-04T18:21:10.720631Z" + "end_time": "2024-01-05T23:20:40.229319Z", + "start_time": "2024-01-05T23:20:40.220620Z" } }, "id": "a84d340622208914" }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, + "outputs": [], + "source": [ + "# b['smoldyn'].add_process(name='smoldyn_process')" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "end_time": "2024-01-05T23:20:40.229868Z", + "start_time": "2024-01-05T23:20:40.224645Z" + } + }, + "id": "235efcd79c0f13c1" + }, + { + "cell_type": "code", + "execution_count": 7, "outputs": [], "source": [ "class Toy(Process):\n", @@ -106,21 +122,21 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:10.726752Z", - "start_time": "2024-01-04T18:21:10.725035Z" + "end_time": "2024-01-05T23:20:40.234521Z", + "start_time": "2024-01-05T23:20:40.228999Z" } }, "id": "1ee84904801a9ab" }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 8, "outputs": [ { "data": { - "text/plain": "['smoldyn_process',\n 'console-emitter',\n 'tellurium_step',\n 'cobra',\n 'ram-emitter',\n 'copasi',\n 'tellurium_process',\n 'database-emitter',\n 'toy']" + "text/plain": "['database-emitter',\n 'toy',\n 'smoldyn_process',\n 'tellurium_process',\n 'copasi',\n 'console-emitter',\n 'tellurium_step',\n 'ram-emitter',\n 'cobra']" }, - "execution_count": 6, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -131,15 +147,15 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:10.730640Z", - "start_time": "2024-01-04T18:21:10.727548Z" + "end_time": "2024-01-05T23:20:40.234796Z", + "start_time": "2024-01-05T23:20:40.232182Z" } }, "id": "dae8ca8db70c4845" }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "outputs": [], "source": [ "b['toy'].add_process(name='toy')" @@ -147,21 +163,21 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:10.733312Z", - "start_time": "2024-01-04T18:21:10.729971Z" + "end_time": "2024-01-05T23:20:40.238681Z", + "start_time": "2024-01-05T23:20:40.235627Z" } }, "id": "8b1f49a78de17642" }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "outputs": [ { "data": { "text/plain": "{'_inputs': {'A': 'float', 'B': 'float'}, '_outputs': {'C': 'float'}}" }, - "execution_count": 8, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -172,22 +188,22 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:10.753676Z", - "start_time": "2024-01-04T18:21:10.733042Z" + "end_time": "2024-01-05T23:20:40.242117Z", + "start_time": "2024-01-05T23:20:40.239091Z" } }, "id": "329e64816e8ff626" }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "outputs": [ { "data": { "image/svg+xml": "\n\n\n\n\n\nbigraph\n\n\n\n('toy',)\n\ntoy\n\n\n\n\n('toy', 'A')->('toy',)\n\n\nA\n\n\n\n\n('toy', 'B')->('toy',)\n\n\nB\n\n\n\n\n('toy', 'C')->('toy',)\n\n\nC\n\n\n\n", - "text/plain": "" + "text/plain": "" }, - "execution_count": 9, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -198,61 +214,65 @@ "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:10.798231Z", - "start_time": "2024-01-04T18:21:10.737443Z" + "end_time": "2024-01-05T23:20:40.520038Z", + "start_time": "2024-01-05T23:20:40.248932Z" } }, "id": "3b1dd8569f3bb67a" }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 14, "outputs": [ { - "ename": "Exception", - "evalue": "cannot wire A as we are already at the top level {'A': 'float', 'B': 'float'}", + "ename": "AssertionError", + "evalue": "Invalid type for connect: {}, needs to be in ['process', 'step', 'edge']", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", - "\u001B[0;31mException\u001B[0m Traceback (most recent call last)", - "Cell \u001B[0;32mIn[10], line 2\u001B[0m\n\u001B[1;32m 1\u001B[0m b[\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mtoy\u001B[39m\u001B[38;5;124m'\u001B[39m]\u001B[38;5;241m.\u001B[39mconnect(port\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mA\u001B[39m\u001B[38;5;124m'\u001B[39m, target\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mA_store\u001B[39m\u001B[38;5;124m'\u001B[39m)\n\u001B[0;32m----> 2\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;43mB\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;43mB_store\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\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:177\u001B[0m, in \u001B[0;36mBuilder.connect\u001B[0;34m(self, port, target)\u001B[0m\n\u001B[1;32m 175\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[1;32m 176\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mcompiled_composite:\n\u001B[0;32m--> 177\u001B[0m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mcompile\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 179\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mschema\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m_type\u001B[39m\u001B[38;5;124m'\u001B[39m) \u001B[38;5;129;01min\u001B[39;00m EDGE_KEYS, \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mInvalid type for connect: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mschema\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m, needs to be in \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mEDGE_KEYS\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 180\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", - "File \u001B[0;32m~/code/bigraph-builder/builder/builder_api.py:208\u001B[0m, in \u001B[0;36mBuilder.compile\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 207\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21mcompile\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n\u001B[0;32m--> 208\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mschema, tree \u001B[38;5;241m=\u001B[39m \u001B[43mtypes\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mcomplete\u001B[49m\u001B[43m(\u001B[49m\n\u001B[1;32m 209\u001B[0m \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\n\u001B[1;32m 210\u001B[0m \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\n\u001B[1;32m 211\u001B[0m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 212\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\u001B[1;32m 213\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mcompiled_composite \u001B[38;5;241m=\u001B[39m Composite({\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mstate\u001B[39m\u001B[38;5;124m'\u001B[39m: tree, \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mcomposition\u001B[39m\u001B[38;5;124m'\u001B[39m: \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mschema})\n", - "File \u001B[0;32m~/code/bigraph-schema/bigraph_schema/type_system.py:967\u001B[0m, in \u001B[0;36mTypeSystem.complete\u001B[0;34m(self, initial_schema, initial_state)\u001B[0m\n\u001B[1;32m 963\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 964\u001B[0m initial_schema)\n\u001B[1;32m 966\u001B[0m \u001B[38;5;66;03m# hydrate the state given the initial composition\u001B[39;00m\n\u001B[0;32m--> 967\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 968\u001B[0m \u001B[43m \u001B[49m\u001B[43mfull_schema\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 969\u001B[0m \u001B[43m \u001B[49m\u001B[43minitial_state\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 971\u001B[0m \u001B[38;5;66;03m# fill in the parts of the composition schema\u001B[39;00m\n\u001B[1;32m 972\u001B[0m \u001B[38;5;66;03m# determined by the state\u001B[39;00m\n\u001B[1;32m 973\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 974\u001B[0m full_schema,\n\u001B[1;32m 975\u001B[0m state)\n", - "File \u001B[0;32m~/code/bigraph-schema/bigraph_schema/type_system.py:959\u001B[0m, in \u001B[0;36mTypeSystem.hydrate\u001B[0;34m(self, schema, state)\u001B[0m\n\u001B[1;32m 956\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 957\u001B[0m \u001B[38;5;66;03m# TODO: support partial hydration (!)\u001B[39;00m\n\u001B[1;32m 958\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--> 959\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:658\u001B[0m, in \u001B[0;36mTypeSystem.fill\u001B[0;34m(self, original_schema, state)\u001B[0m\n\u001B[1;32m 652\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 653\u001B[0m \u001B[38;5;66;03m# # Removing deepcopy means the state may be updated\u001B[39;00m\n\u001B[1;32m 654\u001B[0m \u001B[38;5;66;03m# if state is not None:\u001B[39;00m\n\u001B[1;32m 655\u001B[0m \u001B[38;5;66;03m# state = copy.deepcopy(state)\u001B[39;00m\n\u001B[1;32m 656\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--> 658\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 659\u001B[0m \u001B[43m \u001B[49m\u001B[43mschema\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 660\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:619\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 617\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 618\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--> 619\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 620\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 621\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 622\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 623\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 624\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 626\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 627\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:571\u001B[0m, in \u001B[0;36mTypeSystem.fill_ports\u001B[0;34m(self, schema, wires, state, top, path)\u001B[0m\n\u001B[1;32m 568\u001B[0m subwires \u001B[38;5;241m=\u001B[39m (subwires,)\n\u001B[1;32m 570\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--> 571\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mException\u001B[39;00m(\n\u001B[1;32m 572\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 574\u001B[0m peer \u001B[38;5;241m=\u001B[39m get_path(\n\u001B[1;32m 575\u001B[0m top,\n\u001B[1;32m 576\u001B[0m path[:\u001B[38;5;241m-\u001B[39m\u001B[38;5;241m1\u001B[39m])\n\u001B[1;32m 578\u001B[0m destination \u001B[38;5;241m=\u001B[39m establish_path(\n\u001B[1;32m 579\u001B[0m peer,\n\u001B[1;32m 580\u001B[0m subwires[:\u001B[38;5;241m-\u001B[39m\u001B[38;5;241m1\u001B[39m],\n\u001B[1;32m 581\u001B[0m top\u001B[38;5;241m=\u001B[39mtop,\n\u001B[1;32m 582\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 A as we are already at the top level {'A': 'float', 'B': 'float'}" + "\u001B[0;31mAssertionError\u001B[0m Traceback (most recent call last)", + "Cell \u001B[0;32mIn[14], 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:179\u001B[0m, in \u001B[0;36mBuilder.connect\u001B[0;34m(self, port, target)\u001B[0m\n\u001B[1;32m 178\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--> 179\u001B[0m \u001B[38;5;28;01massert\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mschema\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m_type\u001B[39m\u001B[38;5;124m'\u001B[39m) \u001B[38;5;129;01min\u001B[39;00m EDGE_KEYS, \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mInvalid type for connect: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mschema\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m, needs to be in \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mEDGE_KEYS\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m\n\u001B[1;32m 180\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 181\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: Invalid type for connect: {}, needs to be in ['process', 'step', 'edge']" ] } ], "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", + "# b['toy'].connect(port='B', target='B_store') # TODO -- compile is trying to connect A at the wrong level??\n", "# b['toy'].connect(port='C', target='C_store')" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:11.103806Z", - "start_time": "2024-01-04T18:21:10.798981Z" + "end_time": "2024-01-05T23:22:09.785238Z", + "start_time": "2024-01-05T23:22:09.767488Z" } }, "id": "f02c15797bdb73b8" }, { "cell_type": "code", - "execution_count": null, - "outputs": [], + "execution_count": 15, + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n\n\n\nbigraph\n\n\n\n('toy',)\n\ntoy\n\n\n\n\n('toy', 'A')->('toy',)\n\n\nA\n\n\n\n\n('toy', 'B')->('toy',)\n\n\nB\n\n\n\n\n('toy', 'C')->('toy',)\n\n\nC\n\n\n\n", + "text/plain": "" + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "b.plot()" ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:11.103968Z", - "start_time": "2024-01-04T18:21:11.103916Z" + "end_time": "2024-01-05T23:22:12.114819Z", + "start_time": "2024-01-05T23:22:12.048640Z" } }, "id": "aeb344bcd6a120ae" @@ -261,15 +281,45 @@ "cell_type": "code", "execution_count": null, "outputs": [], - "source": [], + "source": [ + "b.document()" + ], "metadata": { "collapsed": false, "ExecuteTime": { - "end_time": "2024-01-04T18:21:11.105709Z", - "start_time": "2024-01-04T18:21:11.105131Z" + "end_time": "2024-01-05T23:20:40.556168Z", + "start_time": "2024-01-05T23:20:40.553864Z" } }, "id": "c975aab012b2706f" + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [ + "b.write(filename='toy_bigraph')" + ], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "start_time": "2024-01-05T23:20:40.555800Z" + } + }, + "id": "752e43636bf9fd17" + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [], + "metadata": { + "collapsed": false, + "ExecuteTime": { + "start_time": "2024-01-05T23:20:40.557101Z" + } + }, + "id": "c88f8059a315792e" } ], "metadata": {