In [1]:
from bigraph_viz import plot_bigraph
plot_settings = {}
In [2]:
# !pip install bigraph-viz --upgrade
!pip freeze | grep bigraph-viz
-e git+https://github.com/vivarium-collective/bigraph-viz.git@846f9a2bfd4f601146f9143a7f5bf2c80e559393#egg=bigraph_viz
In [3]:
help(plot_bigraph)
Help on function plot_bigraph in module bigraph_viz.diagram: plot_bigraph(state, schema=None, core=None, out_dir=None, filename=None, file_format='png', size='16,10', node_label_size='12pt', show_values=False, show_types=False, port_labels=True, port_label_size='10pt', rankdir='TB', print_source=False, dpi='70', label_margin='0.05', node_border_colors=None, node_fill_colors=None, node_groups=False, remove_nodes=None, invisible_edges=False, remove_process_place_edges=False, show_process_schema_keys=['interval'])
example¶
This example uses a composite specification that has nesting, multiple processes, types and values included.
In [6]:
nested_composite_spec = {
'store1': {
'store1.1': {
'_value': 1.1,
'_type': 'float',
},
'store1.2': {
'_value': 2,
'_type': 'int',
},
'store1.3': {
'_value': 1.1,
'_type': 'float',
},
'process1': {
'_outputs': {
'port1': 'float',
'port2': 'int',
},
'outputs': {
'port1': 'store1.1',
'port2': 'store1.2',
}
},
'process2': {
'_outputs': {
'port1': 'float',
'port2': 'int',
},
'outputs': {
'port1': 'store1.1',
'port2': 'store1.2',
}
},
},
'process3': {
'outputs': {
'port1': 'store1',
}
}
}
plot_bigraph(nested_composite_spec)
--------------------------------------------------------------------------- Exception Traceback (most recent call last) Cell In[6], line 42 1 nested_composite_spec = { 2 'store1': { 3 'store1.1': { (...) 40 } 41 } ---> 42 plot_bigraph(nested_composite_spec) File ~/code/bigraph-viz/bigraph_viz/diagram.py:430, in plot_bigraph(state, schema, core, out_dir, filename, file_format, size, node_label_size, show_values, show_types, port_labels, port_label_size, rankdir, print_source, dpi, label_margin, node_border_colors, node_fill_colors, node_groups, remove_nodes, invisible_edges, remove_process_place_edges, show_process_schema_keys) 427 if not core.exists('process'): 428 core.register('process', process_type) --> 430 schema, state = core.complete(schema, state) 432 # parse out the network 433 graph_dict = get_graph_dict( 434 schema=schema, 435 state=state, (...) 438 show_process_schema_keys=show_process_schema_keys, 439 ) File ~/code/bigraph-schema/bigraph_schema/type_system.py:1334, in TypeSystem.complete(self, initial_schema, initial_state) 1328 state = self.hydrate( 1329 full_schema, 1330 initial_state) 1332 # fill in the parts of the composition schema 1333 # determined by the state -> 1334 schema, state = self.infer_schema( 1335 full_schema, 1336 state) 1338 final_state = self.fill(schema, state) 1340 # TODO: add flag to types.access(copy=True) File ~/code/bigraph-schema/bigraph_schema/type_system.py:1260, in TypeSystem.infer_schema(self, schema, state, top_state, path) 1257 inner_path = path + (key,) 1258 # if get_path(schema, inner_path) is None or get_path(state, inner_path) is None: -> 1260 schema, top_state = self.infer_schema( 1261 schema, 1262 value, 1263 top_state=top_state, 1264 path=inner_path) 1266 elif isinstance(state, str): 1267 pass File ~/code/bigraph-schema/bigraph_schema/type_system.py:1260, in TypeSystem.infer_schema(self, schema, state, top_state, path) 1257 inner_path = path + (key,) 1258 # if get_path(schema, inner_path) is None or get_path(state, inner_path) is None: -> 1260 schema, top_state = self.infer_schema( 1261 schema, 1262 value, 1263 top_state=top_state, 1264 path=inner_path) 1266 elif isinstance(state, str): 1267 pass File ~/code/bigraph-schema/bigraph_schema/type_system.py:1218, in TypeSystem.infer_schema(self, schema, state, top_state, path) 1211 state_type = { 1212 key: value 1213 for key, value in state.items() 1214 if key.startswith('_')} 1215 state_schema = self.access( 1216 state_type) -> 1218 hydrated_state = self.deserialize(state_schema, state) 1219 top_state = set_path( 1220 top_state, 1221 path, 1222 hydrated_state) 1224 update = state_type File ~/code/bigraph-schema/bigraph_schema/type_system.py:684, in TypeSystem.deserialize(self, schema, encoded) 682 for key, branch in encoded.items(): 683 if key in schema: --> 684 result[key] = self.deserialize( 685 schema[key], 686 branch) 687 return result 689 else: File ~/code/bigraph-schema/bigraph_schema/type_system.py:658, in TypeSystem.deserialize(self, schema, encoded) 657 def deserialize(self, schema, encoded): --> 658 found = self.retrieve(schema) 660 if '_deserialize' in found: 661 deserialize = found['_deserialize'] File ~/code/bigraph-schema/bigraph_schema/type_system.py:97, in TypeSystem.retrieve(self, schema) 95 found = self.access(schema) 96 if found is None: ---> 97 raise Exception(f'schema not found for type: {schema}') 98 return found Exception: schema not found for type: 2
Processes are by default shown with place edges to their outer nodes (see process1 and process2 above). To remove this use remove_process_place_edges=True
:
In [ ]:
plot_settings['remove_process_place_edges'] = True
plot_bigraph(nested_composite_spec, **plot_settings)
To remove specific nodes from the vizualization, pass in a list of paths to those nodes. In this example the node in path ('store1', 'store1.3')
is removed:
In [ ]:
remove_nodes = [
('store1', 'store1.3'),
]
plot_settings['remove_nodes'] = remove_nodes
plot_bigraph(nested_composite_spec, **plot_settings)
Remove port labels:
In [ ]:
plot_settings['port_labels'] = False
plot_bigraph(nested_composite_spec, **plot_settings)
Change node borders or fill colors
In [ ]:
plot_settings['node_border_colors'] = {
('store1', 'store1.1'): 'blue',
}
plot_settings['node_fill_colors'] = {
('store1', 'store1.2'): 'red',
}
plot_bigraph(nested_composite_spec, **plot_settings)
To group nodes use node_groups
, A list of lists of grouped node paths, which will be visually placed at the same rank.
In [ ]:
plot_settings['node_groups'] = [
[('store1', 'process1'), ('store1', 'process2'), ('process3',)]
]
plot_bigraph(nested_composite_spec, **plot_settings)
Change the orientation with rankdir
using the graphviz orientation key. 'TB'
=top-to-bottom, 'LR'
=left-to-right. By default this is top-to-bottom.
In [ ]:
plot_settings['rankdir'] = 'LR'
plot_bigraph(nested_composite_spec, **plot_settings)
In [ ]: