Пример #1
0
def inspect_execution(
    flow,
    x,
    msg=None,
    target=None,
    path=None,
    name=None,
    tracer=None,
    debug=False,
    slide_style=None,
    show_size=False,
    **kwargs
):
    """Return the HTML code for an inspection slideshow of the execution
    and the return value of the execution (in a tuple).

    Note that the file into which the slideshow HTML is inserted must be in the
    snapshot_path.

    flow -- The flow for the execution.
    x, msg, target -- Data for the execution, msg and target can only be used
        for a BiFlow (default value is None).
    path -- Path were the slideshow will be stored, if None (default value)
        a temporary directory will be used.
    name -- Name string to be used for the slide files.
    tracer -- Instance of InspectionHTMLTracer, can be None for
        default class.
    debug -- If True (default is False) then any exception will be
        caught and the gathered data up to that point is returned in the
        normal way. This is useful for bimdp debugging.
    slide_style -- CSS code for the individual slides (when they are
        viewed as single HTML files), has no effect on the slideshow appearance.
    show_size -- Show the approximate memory footprint of all nodes.
    **kwargs -- Additional arguments for flow.execute can be specified
        as keyword arguments.
    """
    if path is None:
        path = tempfile.mkdtemp(prefix="MDP_")
    if not name:
        name = "execution_inspection"
    # create CSS file for the slides
    if not slide_style:
        slide_style = standard_css()
    robust_write_file(path=path, filename=STANDARD_CSS_FILENAME, content=slide_style)
    del slide_style
    if not tracer:
        tracer = InspectionHTMLTracer()
        tracer._html_converter.flow_html_converter.show_size = show_size
    # create slides
    try:
        slide_filenames, slide_node_ids, section_ids, result = tracer.trace_execution(
            path=path, trace_name=name, flow=flow, x=x, msg=msg, target=target, debug=debug, **kwargs
        )
    except TraceDebugException, debug_exception:
        if not debug_exception.result:
            return None
        traceback.print_exc()
        print("exception during excecution, " + "create inspection up to failure point...")
        slide_filenames, slide_node_ids, section_ids = debug_exception.result
        result = None
Пример #2
0
def inspect_training(snapshot_path, x_samples, msg_samples=None,
                     stop_messages=None, inspection_path=None,
                     tracer=None, debug=False,
                     slide_style=None, show_size=False,
                     verbose=True, **kwargs):
    """Return the HTML code for an inspection slideshow of the training.

    This function must be used after the training was completed. Before the
    training prepare_training_inspection must have been called to create
    snapshots. After training one should call remove_inspection_residues.

    Note that the file into which the returned slideshow HTML is inserted must
    be in the snapshot_path.

    snapshot_path -- Path were the flow training snapshots are stored.
    x_samples, msg_samples -- Lists with the input data for the training trace.
    stop_messages -- The stop msg for the training trace.
    inspection_path -- Path were the slides will be stored. If None (default
        value) then the snapshot_path is used.
    tracer -- Instance of InspectionHTMLTracer, can be None for
        default class.
    debug -- If True (default is False) then any exception will be
        caught and the gathered data up to that point is returned in the
        normal way. This is useful for bimdp debugging.
    slide_style -- CSS code for the individual slides (when they are
        viewed as single HTML files), has no effect on the slideshow appearance.
    show_size -- Show the approximate memory footprint of all nodes.
    verbose -- If True (default value) a status message is printed for each
        loaded snapshot.
    **kwargs -- Additional arguments for flow.train can be specified
        as keyword arguments.
    """
    if not inspection_path:
        inspection_path = snapshot_path
    ## create CSS file for the slides
    if not slide_style:
        slide_style = standard_css()
    robust_write_file(path=inspection_path, filename=STANDARD_CSS_FILENAME,
                      content=slide_style)
    del slide_style
    ## create slides
    try:
        slide_filenames, slide_node_ids, index_table = \
            _trace_biflow_training(snapshot_path=snapshot_path,
                                   inspection_path=inspection_path,
                                   x_samples=x_samples,
                                   msg_samples=msg_samples,
                                   stop_messages=stop_messages,
                                   tracer=tracer,
                                   debug=debug,
                                   show_size=show_size,
                                   verbose=verbose,
                                   **kwargs )
        if not slide_filenames:
            err = ("No inspection slides were generated, probably because "
                   "there are no untrained nodes in the given flow.")
            raise EmptyTraceException(err)
    except TraceDebugException, debug_exception:
        slide_filenames, slide_node_ids, index_table = debug_exception.result
Пример #3
0
def inspect_training(snapshot_path,
                     x_samples,
                     msg_samples=None,
                     stop_messages=None,
                     inspection_path=None,
                     tracer=None,
                     debug=False,
                     slide_style=None,
                     show_size=False,
                     verbose=True,
                     **kwargs):
    """Return the HTML code for an inspection slideshow of the training.

    This function must be used after the training was completed. Before the
    training prepare_training_inspection must have been called to create
    snapshots. After training one should call remove_inspection_residues.

    Note that the file into which the returned slideshow HTML is inserted must
    be in the snapshot_path.

    snapshot_path -- Path were the flow training snapshots are stored.
    x_samples, msg_samples -- Lists with the input data for the training trace.
    stop_messages -- The stop msg for the training trace.
    inspection_path -- Path were the slides will be stored. If None (default
        value) then the snapshot_path is used.
    tracer -- Instance of InspectionHTMLTracer, can be None for
        default class.
    debug -- If True (default is False) then any exception will be
        caught and the gathered data up to that point is returned in the
        normal way. This is useful for bimdp debugging.
    slide_style -- CSS code for the individual slides (when they are
        viewed as single HTML files), has no effect on the slideshow appearance.
    show_size -- Show the approximate memory footprint of all nodes.
    verbose -- If True (default value) a status message is printed for each
        loaded snapshot.
    **kwargs -- Additional arguments for flow.train can be specified
        as keyword arguments.
    """
    if not inspection_path:
        inspection_path = snapshot_path
    ## create CSS file for the slides
    if not slide_style:
        slide_style = standard_css()
    robust_write_file(path=inspection_path,
                      filename=STANDARD_CSS_FILENAME,
                      content=slide_style)
    del slide_style
    ## create slides
    try:
        slide_filenames, slide_node_ids, index_table = \
            _trace_biflow_training(snapshot_path=snapshot_path,
                                   inspection_path=inspection_path,
                                   x_samples=x_samples,
                                   msg_samples=msg_samples,
                                   stop_messages=stop_messages,
                                   tracer=tracer,
                                   debug=debug,
                                   show_size=show_size,
                                   verbose=verbose,
                                   **kwargs )
        if not slide_filenames:
            err = ("No inspection slides were generated, probably because "
                   "there are no untrained nodes in the given flow.")
            raise EmptyTraceException(err)
    except TraceDebugException, debug_exception:
        slide_filenames, slide_node_ids, index_table = debug_exception.result
Пример #4
0
def inspect_execution(flow,
                      x,
                      msg=None,
                      target=None,
                      path=None,
                      name=None,
                      tracer=None,
                      debug=False,
                      slide_style=None,
                      show_size=False,
                      **kwargs):
    """Return the HTML code for an inspection slideshow of the execution
    and the return value of the execution (in a tuple).

    Note that the file into which the slideshow HTML is inserted must be in the
    snapshot_path.

    flow -- The flow for the execution.
    x, msg, target -- Data for the execution, msg and target can only be used
        for a BiFlow (default value is None).
    path -- Path were the slideshow will be stored, if None (default value)
        a temporary directory will be used.
    name -- Name string to be used for the slide files.
    tracer -- Instance of InspectionHTMLTracer, can be None for
        default class.
    debug -- If True (default is False) then any exception will be
        caught and the gathered data up to that point is returned in the
        normal way. This is useful for bimdp debugging.
    slide_style -- CSS code for the individual slides (when they are
        viewed as single HTML files), has no effect on the slideshow appearance.
    show_size -- Show the approximate memory footprint of all nodes.
    **kwargs -- Additional arguments for flow.execute can be specified
        as keyword arguments.
    """
    if path is None:
        path = tempfile.mkdtemp(prefix='MDP_')
    if not name:
        name = "execution_inspection"
    # create CSS file for the slides
    if not slide_style:
        slide_style = standard_css()
    robust_write_file(path=path,
                      filename=STANDARD_CSS_FILENAME,
                      content=slide_style)
    del slide_style
    if not tracer:
        tracer = InspectionHTMLTracer()
        tracer._html_converter.flow_html_converter.show_size = show_size
    # create slides
    try:
        slide_filenames, slide_node_ids, section_ids, result = \
            tracer.trace_execution(path=path,
                                   trace_name=name,
                                   flow=flow,
                                   x=x, msg=msg, target=target,
                                   debug=debug,
                                   **kwargs)
    except TraceDebugException, debug_exception:
        if not debug_exception.result:
            return None
        traceback.print_exc()
        print("exception during excecution, " +
              "create inspection up to failure point...")
        slide_filenames, slide_node_ids, section_ids = debug_exception.result
        result = None