Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eagmon committed Feb 16, 2024
1 parent b13050e commit 321eb96
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
22 changes: 15 additions & 7 deletions builder/builder_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion builder/out/nodebuilder_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 11 additions & 10 deletions notebooks/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"outputs": [],
"source": [
"# imports\n",
"from builder import Builder, Process"
"from builder import Builder, Process, ProcessTypes"
]
},
{
Expand All @@ -39,7 +39,8 @@
"metadata": {},
"outputs": [],
"source": [
"b = Builder()"
"core = ProcessTypes()\n",
"b = Builder(core=core)"
]
},
{
Expand Down Expand Up @@ -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"
]
}
],
Expand Down Expand Up @@ -270,7 +271,7 @@
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x106e91af0>"
"<graphviz.graphs.Digraph at 0x1138962e0>"
]
},
"execution_count": 10,
Expand Down Expand Up @@ -316,7 +317,7 @@
}
],
"source": [
"b['event_process'].ports(True)"
"b['event_process'].interface(True)"
]
},
{
Expand Down Expand Up @@ -351,7 +352,7 @@
" 'outputs': {\n",
" 'mRNA': ['mRNA_store']\n",
" },\n",
" 'instance': <process_bigraph.experiments.minimal_gillespie.GillespieEvent object at 0x106e9a0d0>,\n",
" 'instance': <process_bigraph.experiments.minimal_gillespie.GillespieEvent object at 0x1138592b0>,\n",
" 'interval': 1.0\n",
"}\n",
"}"
Expand Down Expand Up @@ -453,7 +454,7 @@
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x106e9ab20>"
"<graphviz.graphs.Digraph at 0x113859fd0>"
]
},
"execution_count": 13,
Expand Down Expand Up @@ -585,7 +586,7 @@
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x106f25700>"
"<graphviz.graphs.Digraph at 0x113896cd0>"
]
},
"execution_count": 15,
Expand All @@ -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'"
]
}
Expand Down

0 comments on commit 321eb96

Please sign in to comment.