From 321eb9624c04cef34a2caf4e4cf5f38eae419ec4 Mon Sep 17 00:00:00 2001 From: Eran Date: Fri, 16 Feb 2024 18:36:10 -0500 Subject: [PATCH] wip --- builder/builder_api.py | 22 +++++++++++++++------- builder/out/nodebuilder_api.py | 2 +- notebooks/demo.ipynb | 21 +++++++++++---------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/builder/builder_api.py b/builder/builder_api.py index 3f79d58..95d9ab3 100644 --- a/builder/builder_api.py +++ b/builder/builder_api.py @@ -85,7 +85,7 @@ class Builder(dict): def __init__(self, tree=None, schema=None, core=None, parent=None): super().__init__() self.builder_tree = builder_tree_from_dict(tree) - self.schema = schema or {} # TODO -- need to track schema + self.schema = schema or {} # TODO -- keep schema at the top level only self.core = core or ProcessTypes() self.parent = parent @@ -213,7 +213,7 @@ def add_process( 'address': f'local:{name}', # TODO -- only support local right now? 'config': config, 'inputs': {} if inputs is None else inputs, - 'outputs': outputs or {}, + 'outputs': {} if outputs is None else outputs, } initial_schema = {'_type': edge_type} @@ -314,7 +314,7 @@ def run(self, interval): self.compile() self.compiled_composite.run(interval) - def ports(self, print_ports=False): + def interface(self, print_ports=False): # self.compile() tree_dict = self.get_tree() tree_type = tree_dict.get('_type') @@ -342,20 +342,28 @@ def visualize(self, filename=None, out_dir=None, **kwargs): def get_results(self, query=None): return self.compiled_composite.gather_results(query) - def emitter(self, name='ram-emitter'): + def emitter(self, name='ram-emitter', path=None): + if path: + assert isinstance(path, list) + # TODO -- support more emitters self.add_process( name, edge_type='step', - config={'emit': 'schema'}, - inputs=[], # top level emit, TODO this should be more configurable + config={'emit': 'any'}, + inputs=[] or path, # TODO this should be more configurable ) def build_gillespie(): from process_bigraph.experiments.minimal_gillespie import GillespieEvent #, GillespieInterval + # from process_bigraph.experiments.definitions import definitions + # from sbmlprocess import definitions as sbml_definitions core = ProcessTypes() + # core.import(definitions) + + # TODO -- this should not be required. Gillespie should somehow provide this core.register( 'default 1', { '_inherit': 'float', @@ -404,7 +412,7 @@ def build_gillespie(): gillespie.visualize(filename='bigraph2', out_dir='out') ## choose an emitter - gillespie.emitter(name='ram-emitter') # choose the emitter, path=[] would be all + gillespie.emitter(name='ram-emitter', path=['mRNA_store']) # choose the emitter, path=[] would be all # gillespie.emitter(name='csv-emitter', emit_paths=['DNA_store']) # add a second emitter # ## turn on emits (assume ram-emitter if none provided) diff --git a/builder/out/nodebuilder_api.py b/builder/out/nodebuilder_api.py index 2b5ea14..b5a7ab8 100644 --- a/builder/out/nodebuilder_api.py +++ b/builder/out/nodebuilder_api.py @@ -173,7 +173,7 @@ def build_gillespie(): gillespie.add_process(type='event', protocol='local', rate_param=1.0, wires={}) # protocol local should be default. kwargs could fill the config gillespie.add_process(type='interval') - print(gillespie['event'].ports()) + print(gillespie['event'].interface()) gillespie['event'].connect(port='DNA', target=['DNA_store']) gillespie['DNA_store'] = {'C': 2.0} # this should check the type diff --git a/notebooks/demo.ipynb b/notebooks/demo.ipynb index 42f55aa..8fd754a 100644 --- a/notebooks/demo.ipynb +++ b/notebooks/demo.ipynb @@ -21,7 +21,7 @@ "outputs": [], "source": [ "# imports\n", - "from builder import Builder, Process" + "from builder import Builder, Process, ProcessTypes" ] }, { @@ -39,7 +39,8 @@ "metadata": {}, "outputs": [], "source": [ - "b = Builder()" + "core = ProcessTypes()\n", + "b = Builder(core=core)" ] }, { @@ -210,7 +211,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "['console-emitter', 'GillespieInterval', 'ram-emitter', 'GillespieEvent', 'toy']\n" + "['toy', 'GillespieEvent', 'ram-emitter', 'GillespieInterval', 'console-emitter']\n" ] } ], @@ -270,7 +271,7 @@ "\n" ], "text/plain": [ - "" + "" ] }, "execution_count": 10, @@ -316,7 +317,7 @@ } ], "source": [ - "b['event_process'].ports(True)" + "b['event_process'].interface(True)" ] }, { @@ -351,7 +352,7 @@ " 'outputs': {\n", " 'mRNA': ['mRNA_store']\n", " },\n", - " 'instance': ,\n", + " 'instance': ,\n", " 'interval': 1.0\n", "}\n", "}" @@ -453,7 +454,7 @@ "\n" ], "text/plain": [ - "" + "" ] }, "execution_count": 13, @@ -585,7 +586,7 @@ "\n" ], "text/plain": [ - "" + "" ] }, "execution_count": 15, @@ -611,8 +612,8 @@ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[16], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mb\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect_all\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/code/bigraph-builder/builder/builder_api.py:245\u001b[0m, in \u001b[0;36mBuilder.connect_all\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 243\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m port \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mschema[k][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_inputs\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 244\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m port \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m v\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--> 245\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mk\u001b[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[43mport\u001b[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[43mport\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 246\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m port \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mschema[k][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_outputs\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 247\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m port \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m v\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-builder/builder/builder_api.py:256\u001b[0m, in \u001b[0;36mBuilder.connect\u001b[0;34m(self, port, target)\u001b[0m\n\u001b[1;32m 254\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[39mget_tree())\n\u001b[1;32m 255\u001b[0m \u001b[38;5;66;03m# self.complete()\u001b[39;00m\n\u001b[0;32m--> 256\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m port \u001b[38;5;129;01min\u001b[39;00m \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[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:\n\u001b[1;32m 257\u001b[0m \u001b[38;5;28mself\u001b[39m[\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[1;32m 258\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_outputs\u001b[39m\u001b[38;5;124m'\u001b[39m]:\n", + "File \u001b[0;32m~/code/bigraph-builder/builder/builder_api.py:246\u001b[0m, in \u001b[0;36mBuilder.connect_all\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 244\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m port \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mschema[k][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_inputs\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 245\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m port \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m v\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--> 246\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mk\u001b[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[43mport\u001b[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[43mport\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 247\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m port \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mschema[k][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_outputs\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39mkeys():\n\u001b[1;32m 248\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m port \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m v\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-builder/builder/builder_api.py:257\u001b[0m, in \u001b[0;36mBuilder.connect\u001b[0;34m(self, port, target)\u001b[0m\n\u001b[1;32m 255\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[39mget_tree())\n\u001b[1;32m 256\u001b[0m \u001b[38;5;66;03m# self.complete()\u001b[39;00m\n\u001b[0;32m--> 257\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m port \u001b[38;5;129;01min\u001b[39;00m \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[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:\n\u001b[1;32m 258\u001b[0m \u001b[38;5;28mself\u001b[39m[\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[1;32m 259\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_outputs\u001b[39m\u001b[38;5;124m'\u001b[39m]:\n", "\u001b[0;31mKeyError\u001b[0m: '_inputs'" ] }