def _run_info_handler(self, args, screen_info=None): output = self._run_info # Add main menu. menu = debugger_cli_common.Menu() menu.append(debugger_cli_common.MenuItem("list_tensors", "lt")) menu.append(debugger_cli_common.MenuItem("help", "help")) output.annotations[debugger_cli_common.MAIN_MENU_KEY] = menu return output
def setUp(self): self.menu = debugger_cli_common.Menu() self.assertEqual(0, self.menu.num_items()) self.node1 = debugger_cli_common.MenuItem("water flower", "water_flower") self.node2 = debugger_cli_common.MenuItem( "measure wavelength", "measure_wavelength") self.menu.append(self.node1) self.menu.append(self.node2) self.assertEqual(2, self.menu.num_items())
def get_run_start_intro(run_call_count, fetches, feed_dict, tensor_filters, is_callable_runner=False): """Generate formatted intro for run-start UI. Args: run_call_count: (int) Run call counter. fetches: Fetches of the `Session.run()` call. See doc of `Session.run()` for more details. feed_dict: Feeds to the `Session.run()` call. See doc of `Session.run()` for more details. tensor_filters: (dict) A dict from tensor-filter name to tensor-filter callable. is_callable_runner: (bool) whether a runner returned by Session.make_callable is being run. Returns: (RichTextLines) Formatted intro message about the `Session.run()` call. """ fetch_lines = _get_fetch_names(fetches) if not feed_dict: feed_dict_lines = [debugger_cli_common.RichLine(" (Empty)")] else: feed_dict_lines = [] for feed_key in feed_dict: feed_key_name = get_graph_element_name(feed_key) feed_dict_line = debugger_cli_common.RichLine(" ") feed_dict_line += debugger_cli_common.RichLine( feed_key_name, debugger_cli_common.MenuItem(None, "pf '%s'" % feed_key_name)) # Surround the name string with quotes, because feed_key_name may contain # spaces in some cases, e.g., SparseTensors. feed_dict_lines.append(feed_dict_line) feed_dict_lines = debugger_cli_common.rich_text_lines_from_rich_line_list( feed_dict_lines) out = debugger_cli_common.RichTextLines(_HORIZONTAL_BAR) if is_callable_runner: out.append("Running a runner returned by Session.make_callable()") else: out.append("Session.run() call #%d:" % run_call_count) out.append("") out.append("Fetch(es):") out.extend( debugger_cli_common.RichTextLines( [" " + line for line in fetch_lines])) out.append("") out.append("Feed dict:") out.extend(feed_dict_lines) out.append(_HORIZONTAL_BAR) out.append("") out.append("Select one of the following commands to proceed ---->") out.extend( _recommend_command("run", "Execute the run() call with debug tensor-watching", create_link=True)) out.extend( _recommend_command( "run -n", "Execute the run() call without debug tensor-watching", create_link=True)) out.extend( _recommend_command( "run -t <T>", "Execute run() calls (T - 1) times without debugging, then " "execute run() once more with debugging and drop back to the CLI")) out.extend( _recommend_command( "run -f <filter_name>", "Keep executing run() calls until a dumped tensor passes a given, " "registered filter (conditional breakpoint mode)")) more_lines = [" Registered filter(s):"] if tensor_filters: filter_names = [] for filter_name in tensor_filters: filter_names.append(filter_name) command_menu_node = debugger_cli_common.MenuItem( "", "run -f %s" % filter_name) more_lines.append( RL(" * ") + RL(filter_name, command_menu_node)) else: more_lines.append(" (None)") out.extend( debugger_cli_common.rich_text_lines_from_rich_line_list(more_lines)) out.extend( _recommend_command( "invoke_stepper", "Use the node-stepper interface, which allows you to interactively " "step through nodes involved in the graph run() call and " "inspect/modify their values", create_link=True)) out.append("") out.append_rich_line( RL("For more details, see ") + RL("help.", debugger_cli_common.MenuItem("", "help")) + ".") out.append("") # Make main menu for the run-start intro. menu = debugger_cli_common.Menu() menu.append(debugger_cli_common.MenuItem("run", "run")) menu.append( debugger_cli_common.MenuItem("invoke_stepper", "invoke_stepper")) menu.append(debugger_cli_common.MenuItem("exit", "exit")) out.annotations[debugger_cli_common.MAIN_MENU_KEY] = menu return out
def get_run_start_intro(run_call_count, fetches, feed_dict, tensor_filters): """Generate formatted intro for run-start UI. Args: run_call_count: (int) Run call counter. fetches: Fetches of the `Session.run()` call. See doc of `Session.run()` for more details. feed_dict: Feeds to the `Session.run()` call. See doc of `Session.run()` for more details. tensor_filters: (dict) A dict from tensor-filter name to tensor-filter callable. Returns: (RichTextLines) Formatted intro message about the `Session.run()` call. """ fetch_lines = _get_fetch_names(fetches) if not feed_dict: feed_dict_lines = ["(Empty)"] else: feed_dict_lines = [] for feed_key in feed_dict: if isinstance(feed_key, six.string_types): feed_dict_lines.append(feed_key) else: feed_dict_lines.append(feed_key.name) intro_lines = [ "======================================", "Session.run() call #%d:" % run_call_count, "", "Fetch(es):" ] intro_lines.extend([" " + line for line in fetch_lines]) intro_lines.extend(["", "Feed dict(s):"]) intro_lines.extend([" " + line for line in feed_dict_lines]) intro_lines.extend([ "======================================", "", "Select one of the following commands to proceed ---->" ]) out = debugger_cli_common.RichTextLines(intro_lines) out.extend( _recommend_command( "run", "Execute the run() call with debug tensor-watching", create_link=True)) out.extend( _recommend_command( "run -n", "Execute the run() call without debug tensor-watching", create_link=True)) out.extend( _recommend_command( "run -t <T>", "Execute run() calls (T - 1) times without debugging, then " "execute run() once more with debugging and drop back to the CLI")) out.extend( _recommend_command( "run -f <filter_name>", "Keep executing run() calls until a dumped tensor passes a given, " "registered filter (conditional breakpoint mode)")) more_lines = [" Registered filter(s):"] if tensor_filters: filter_names = [] for filter_name in tensor_filters: filter_names.append(filter_name) command_menu_node = debugger_cli_common.MenuItem( "", "run -f %s" % filter_name) more_lines.append(RL(" * ") + RL(filter_name, command_menu_node)) else: more_lines.append(" (None)") out.extend( debugger_cli_common.rich_text_lines_from_rich_line_list(more_lines)) out.extend( _recommend_command( "invoke_stepper", "Use the node-stepper interface, which allows you to interactively " "step through nodes involved in the graph run() call and " "inspect/modify their values", create_link=True)) out.append("") out.append_rich_line(RL("For more details, see ") + RL("help.", debugger_cli_common.MenuItem("", "help")) + ".") out.append("") # Make main menu for the run-start intro. menu = debugger_cli_common.Menu() menu.append(debugger_cli_common.MenuItem("run", "run")) menu.append(debugger_cli_common.MenuItem( "invoke_stepper", "invoke_stepper")) menu.append(debugger_cli_common.MenuItem("exit", "exit")) out.annotations[debugger_cli_common.MAIN_MENU_KEY] = menu return out
def _add_main_menu(output, node_name=None, enable_list_tensors=True, enable_node_info=True, enable_print_tensor=True, enable_list_inputs=True, enable_list_outputs=True): """Generate main menu for the screen output from a command. Args: output: (debugger_cli_common.RichTextLines) the output object to modify. node_name: (str or None) name of the node involved (if any). If None, the menu items node_info, list_inputs and list_outputs will be automatically disabled, overriding the values of arguments enable_node_info, enable_list_inputs and enable_list_outputs. enable_list_tensors: (bool) whether the list_tensor menu item will be enabled. enable_node_info: (bool) whether the node_info item will be enabled. enable_print_tensor: (bool) whether the print_tensor item will be enabled. enable_list_inputs: (bool) whether the item list_inputs will be enabled. enable_list_outputs: (bool) whether the item list_outputs will be enabled. """ menu = debugger_cli_common.Menu() menu.append( debugger_cli_common.MenuItem("list_tensors", "list_tensors", enabled=enable_list_tensors)) if node_name: menu.append( debugger_cli_common.MenuItem("node_info", "node_info -a -d %s" % node_name, enabled=enable_node_info)) menu.append( debugger_cli_common.MenuItem("print_tensor", "print_tensor %s" % node_name, enabled=enable_print_tensor)) menu.append( debugger_cli_common.MenuItem("list_inputs", "list_inputs -c -r %s" % node_name, enabled=enable_list_inputs)) menu.append( debugger_cli_common.MenuItem("list_outputs", "list_outputs -c -r %s" % node_name, enabled=enable_list_outputs)) else: menu.append( debugger_cli_common.MenuItem("node_info", None, enabled=False)) menu.append( debugger_cli_common.MenuItem("print_tensor", None, enabled=False)) menu.append( debugger_cli_common.MenuItem("list_inputs", None, enabled=False)) menu.append( debugger_cli_common.MenuItem("list_outputs", None, enabled=False)) menu.append(debugger_cli_common.MenuItem("run_info", "run_info")) menu.append(debugger_cli_common.MenuItem("help", "help")) output.annotations[debugger_cli_common.MAIN_MENU_KEY] = menu