Skip to content

Add adaptations for execution in Binder

Iryna de Albuquerque Silva requested to merge fix_for_binder into dev

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:
    1. added condition to test if notebook is running in Binder (and adapt URL accordingly);
    2. renamed methods (show_server() -> show_ext_server() and show_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:
    1. replaced brackets ([ ]) and hash (#) by underscores (_);
    2. added conditions for node re-naming.

Detailed major modifications

def _generate_unique_ids(graphview) in aidge_model_explorer/converters/runtime_converter.py:

Only sets a name to node if:

  1. Node has no name, then name according to convention, i.e., ""_Type_RankType;
  2. Node has a name but it does not follow convention. Ex. node named myConv, of type Conv2D, is the first of this type in the graph (rank among type = 0), it is then renamed as myConv_Conv2D_0;
  3. Node has a name that follows the convention, but its rank among type changed;
Edited by Iryna de Albuquerque Silva

Merge request reports

Loading