Ejemplo n.º 1
0
def get_record_full_string(record, show_info = True, show_logs = True, truncate_logs = None, show_result ='deep',
        show_exceptions=True, truncate_result = None, include_bottom_border = True, header_width=64):
    """
    Get a human-readable string containing info about the experiment record.

    :param show_info: Show info about experiment (name, id, runtime, etc)
    :param show_logs: Show logs (True, False, or an integer character count to truncate logs at)
    :param show_result: Show the result.  Options for display are:
        'short': Print a one-liner (note: sometimes prints multiple lines)
        'long': Directly call str
        'deep': Use the deepstr function for a compact nested printout.
    :return: A string to print.
    """

    assert show_result in (False, 'full', 'deep')
    full_info_string = surround_with_header(record.get_id(), width=header_width, char='=') + '\n'
    if show_info:
        full_info_string += '{}\n'.format(record.info.get_text())
    if show_logs:
        log = record.get_log()
        if truncate_logs is not None and len(log)>truncate_logs:
            log = log[:truncate_logs-100] + '\n\n ... LOG TRUNCATED TO {} CHARACTERS ... \n\n'.format(truncate_logs) + log[-100:]
        full_info_string += section_with_header('Logs', log, width=header_width)

    error_trace = record.get_error_trace()
    if show_exceptions and error_trace is not None:
        full_info_string += section_with_header('Error Trace', record.get_error_trace(), width=header_width)

    if show_result:
        result_str = get_record_result_string(record, truncate_to=truncate_result, func=show_result)
        full_info_string += section_with_header('Result', result_str, width=header_width, bottom_char='=' if include_bottom_border else None)

    return full_info_string
Ejemplo n.º 2
0
def _get_record_log_section(record, truncate_logs=None, header_width=64):
    log = record.get_log()
    if truncate_logs is not None and len(log) > truncate_logs:
        log = log[:truncate_logs -
                  100] + '\n\n ... LOG TRUNCATED TO {} CHARACTERS ... \n\n'.format(
                      truncate_logs) + log[-100:]
    return section_with_header('Logs', log, width=header_width)
Ejemplo n.º 3
0
def _get_record_error_trace_section(record, header_width):
    error_trace = record.get_error_trace()
    if error_trace is None:
        return ''
    else:
        return section_with_header('Error Trace',
                                   record.get_error_trace(),
                                   width=header_width)
Ejemplo n.º 4
0
def get_record_full_string(record, show_info = True, show_logs = True, truncate_logs = None, show_result ='deep',
        show_exceptions=True, truncate_result = None, include_bottom_border = True, header_width=64, return_list = False):
    """
    Get a human-readable string containing info about the experiment record.

    :param show_info: Show info about experiment (name, id, runtime, etc)
    :param show_logs: Show logs (True, False, or an integer character count to truncate logs at)
    :param show_result: Show the result.  Options for display are:
        'short': Print a one-liner (note: sometimes prints multiple lines)
        'long': Directly call str
        'deep': Use the deepstr function for a compact nested printout.
    :return: A string to print.
    """

    parts = [surround_with_header(record.get_id(), width=header_width, char='=')]

    if show_info:
        parts.append(section_with_header('Info', record.info.get_text(), width=header_width))

    if show_logs:
        log = record.get_log()
        if truncate_logs is not None and len(log)>truncate_logs:
            log = log[:truncate_logs-100] + '\n\n ... LOG TRUNCATED TO {} CHARACTERS ... \n\n'.format(truncate_logs) + log[-100:]
        # return section_with_header('Logs', log, width=header_width)
        parts.append(section_with_header('Logs', log, width=header_width))

    if show_exceptions:
        error_trace = record.get_error_trace()
        error_trace_text = '' if error_trace is None else section_with_header('Error Trace', record.get_error_trace(), width=header_width)
        parts.append(error_trace_text)

    if show_result:
        assert show_result in (False, 'full', 'deep')
        result_str = get_record_result_string(record, truncate_to=truncate_result, func=show_result)
        parts.append(section_with_header('Result', result_str, width=header_width))

    if return_list:
        return parts
    else:
        return '\n'.join(parts)
Ejemplo n.º 5
0
def show_experiment_records(records, parallel_text=None, hang_notice = None, show_logs=True, truncate_logs=None, truncate_result=10000, header_width=100, show_result ='deep', hang=True):
    """
    Show the console logs, figures, and results of a collection of experiments.

    :param records:
    :param parallel_text:
    :param hang_notice:
    :return:
    """
    if isinstance(records, ExperimentRecord):
        records = [records]
    if parallel_text is None:
        parallel_text = len(records)>1
    if len(records)==0:
        print '... No records to show ...'
    else:
        strings = [get_record_full_string(rec, show_logs=show_logs, show_result=show_result, truncate_logs=truncate_logs,
                    truncate_result=truncate_result, header_width=header_width, include_bottom_border=False) for rec in records]
    has_matplotlib_figures = any(loc.endswith('.pkl') for rec in records for loc in rec.get_figure_locs())
    if has_matplotlib_figures:
        from matplotlib import pyplot as plt
        from artemis.plotting.saving_plots import interactive_matplotlib_context
        for rec in records:
            rec.show_figures(hang=False)
        if hang_notice is not None:
            print hang_notice

        with interactive_matplotlib_context(not hang):
            plt.show()

    if any(rec.get_experiment().display_function is not None for rec in records):
        from artemis.plotting.saving_plots import interactive_matplotlib_context
        with interactive_matplotlib_context():
            for i, rec in enumerate(records):
                with CaptureStdOut(print_to_console=False) as cap:
                    display_experiment_record(rec)
                if cap != '':
                    # strings[i] += '{subborder} Result Display {subborder}\n{out} \n{border}'.format(subborder='-'*20, out=cap.read(), border='='*50)
                    strings[i] += section_with_header('Result Display', cap.read(), width=header_width, bottom_char='=')

    if parallel_text:
        print side_by_side(strings, max_linewidth=128)
    else:
        for string in strings:
            print string

    return has_matplotlib_figures
Ejemplo n.º 6
0
def _get_result_section(record, truncate_result, show_result, header_width):
    assert show_result in (False, 'full', 'deep')
    result_str = get_record_result_string(record,
                                          truncate_to=truncate_result,
                                          func=show_result)
    return section_with_header('Result', result_str, width=header_width)
Ejemplo n.º 7
0
def _get_record_info_section(record, header_width):
    return section_with_header('Info',
                               record.info.get_text(),
                               width=header_width)
Ejemplo n.º 8
0
def _get_result_section(record, truncate_result, show_result, header_width):
    assert show_result in (False, 'full', 'deep')
    result_str = get_record_result_string(record, truncate_to=truncate_result, func=show_result)
    return section_with_header('Result', result_str, width=header_width)
Ejemplo n.º 9
0
def _get_record_error_trace_section(record, header_width):
    error_trace = record.get_error_trace()
    if error_trace is None:
        return ''
    else:
        return section_with_header('Error Trace', record.get_error_trace(), width=header_width)
Ejemplo n.º 10
0
def _get_record_log_section(record, truncate_logs = None, header_width=64):
    log = record.get_log()
    if truncate_logs is not None and len(log)>truncate_logs:
        log = log[:truncate_logs-100] + '\n\n ... LOG TRUNCATED TO {} CHARACTERS ... \n\n'.format(truncate_logs) + log[-100:]
    return section_with_header('Logs', log, width=header_width)
Ejemplo n.º 11
0
def _get_record_info_section(record, header_width):
    return section_with_header('Info', record.info.get_text(), width=header_width)