Add adaptations for execution in Binder
Context
When executing in Binder, the server works behind a proxy, thus the URL generated for visualization must be adapted in consequence.
Moreover, for model_explorer
each node must have an (unique) ID associated to it. However, in the current conversion logic, Aidge's nodes names are set following this convention "{node_name}[{node_type}#{type_rank}]"
, which introduces brackets ([ ]
) and hash symbols (#
). During the export phase, specially when generating C/C++ code, the nodes names become variables names, but brackets and hashs are not valid characters in C/C++ identifiers.
In addition, each time the GraphView is visualized (with aidge_model_explorer.visualize()
), nodes are renamed again with the current logic, creating excessively long and cluttered names.
Modified files
-
aidge_model_explorer/visualize.py
:- added condition to test if notebook is running in Binder (and adapt URL accordingly);
- renamed methods (
show_server()
->show_ext_server()
andshow_IFrame()
->show_in_notebook()
) to make their names more descriptive.
-
aidge_model_explorer/__init__.py
, modified imports with new methods names; -
aidge_model_explorer/converters/runtime_converter.py
:- replaced brackets (
[ ]
) and hash (#
) by underscores (_
); - added conditions for node re-naming.
- replaced brackets (
Detailed major modifications
def _generate_unique_ids(graphview)
in aidge_model_explorer/converters/runtime_converter.py
:
Only sets a name to node if:
- Node has no name, then name according to convention, i.e., ""_Type_RankType;
- Node has a name but it does not follow convention. Ex. node named
myConv
, of typeConv2D
, is the first of this type in the graph (rank among type = 0), it is then renamed asmyConv_Conv2D_0
; - Node has a name that follows the convention, but its rank among type changed;