コード例 #1
0
ファイル: common.py プロジェクト: zooks97/aiida_core
def print_node_info(node, print_summary=True):
    from tabulate import tabulate
    from aiida.backends.utils import get_log_messages
    from aiida.orm.calculation.work import WorkCalculation

    if print_summary:
        print_node_summary(node)

    table_headers = ['Link label', 'PK', 'Type']

    table = []
    print "##### INPUTS:"
    for k, v in node.get_inputs_dict().iteritems():
        if k == 'code': continue
        table.append([k, v.pk, v.__class__.__name__])
    print(tabulate(table, headers=table_headers))

    table = []
    print "##### OUTPUTS:"
    for k, v in node.get_outputs(also_labels=True):
        table.append([k, v.pk, v.__class__.__name__])
    print(tabulate(table, headers=table_headers))

    log_messages = get_log_messages(node)
    if log_messages:
        print "##### LOGS:"
        print ("There are {} log messages for this calculation".format(len(log_messages)))
        if isinstance(node, WorkCalculation):
            print ("Run 'verdi work report {}' to see them".format(node.pk))
        else:
            print ("Run 'verdi calculation logshow {}' to see them".format(node.pk))
コード例 #2
0
ファイル: common.py プロジェクト: asle85/aiida-core
def print_node_info(node, print_summary=True):
    from aiida.backends.utils import get_log_messages
    from tabulate import tabulate

    if print_summary:
        print_node_summary(node)

    table_headers = ['Link label', 'PK', 'Type']

    table = []
    print "##### INPUTS:"
    for k, v in node.get_inputs_dict().iteritems():
        if k == 'code': continue
        table.append([k, v.pk, v.__class__.__name__])
    print(tabulate(table, headers=table_headers))

    table = []
    print "##### OUTPUTS:"
    for k, v in node.get_outputs(also_labels=True):
        table.append([k, v.pk, v.__class__.__name__])
    print(tabulate(table, headers=table_headers))

    log_messages = get_log_messages(node)
    if log_messages:
        print("##### NOTE! There are {} log messages for this "
              "calculation.".format(len(log_messages)))
        print "      Use the 'calculation logshow' command to see them."
コード例 #3
0
def workflow_logshow(workflows):
    """Show the log for each workflow in a list of WORKFLOWS."""
    from aiida.backends.utils import get_log_messages
    for workflow in workflows:
        log_messages = get_log_messages(workflow)
        label_str = ' [{}]'.format(workflow.label) if workflow.label else ''
        state = workflow.get_state()
        echo.echo('*** {pk}{label}: {state}'.format(pk=format_pk(workflow),
                                                    label=label_str,
                                                    state=state))

        if workflow.get_report():
            echo.echo(
                'Print the report with `verdi workflow report {}`'.format(
                    format_pk(workflow)))
        else:
            echo.echo('*** Report is empty')

        if log_messages:
            echo.echo('*** {} LOG MESSAGES:'.format(len(log_messages)))
        else:
            echo.echo('*** NO LOG MESSAGES')

        for log in log_messages:
            echo.echo('+-> {} at {}'.format(log['levelname'], log['time']))
            echo.echo('\n'.join([
                '|\t{}'.format(msg)
                for msg in log.get('message', '').splitlines()
            ]))
コード例 #4
0
def get_calc_log(calcnode):
    """get a formatted string of the calculation log"""
    from aiida.backends.utils import get_log_messages

    log_string = "- Calc State:\n{0}\n- Scheduler Out:\n{1}\n- Scheduler Err:\n{2}\n- Log:\n{3}".format(
        calcnode.get_state(), calcnode.get_scheduler_output(),
        calcnode.get_scheduler_error(),
        json.dumps(get_log_messages(calcnode), default=json_default, indent=2))
    return log_string
コード例 #5
0
ファイル: calculation.py プロジェクト: kriskornel/aiida_core
    def calculation_logshow(self, *args):
        from aiida.common.exceptions import NotExistent
        from aiida.backends.utils import get_log_messages
        from aiida.common.datastructures import calc_states

        if not is_dbenv_loaded():
            load_dbenv()

        for calc_pk in args:
            try:
                calc = load_node(int(calc_pk))
            except ValueError:
                print "*** {}: Not a valid PK".format(calc_pk)
                continue
            except NotExistent:
                print "*** {}: Not a valid calculation".format(calc_pk)
                continue

            log_messages = get_log_messages(calc)
            label_string = " [{}]".format(calc.label) if calc.label else ""
            state = calc.get_state()
            if state == calc_states.WITHSCHEDULER:
                sched_state = calc.get_scheduler_state()
                if sched_state is None:
                    sched_state = "(unknown)"
                state += ", scheduler state: {}".format(sched_state)
            print "*** {}{}: {}".format(calc_pk, label_string, state)

            sched_out = calc.get_scheduler_output()
            sched_err = calc.get_scheduler_error()
            if sched_out is None:
                print "*** Scheduler output: N/A"
            elif sched_out:
                print "*** Scheduler output:"
                print sched_out
            else:
                print "*** (empty scheduler output file)"

            if sched_err is None:
                print "*** Scheduler errors: N/A"
            elif sched_err:
                print "*** Scheduler errors:"
                print sched_err
            else:
                print "*** (empty scheduler errors file)"

            if log_messages:
                print "*** {} LOG MESSAGES:".format(len(log_messages))
            else:
                print "*** 0 LOG MESSAGES"

            for log in log_messages:
                print "+-> {} at {}".format(log['levelname'], log['time'])
                # Print the message, with a few spaces in front of each line
                print "\n".join(
                    ["|   {}".format(_) for _ in log['message'].splitlines()])
コード例 #6
0
def get_calculation_log_report(calculation):
    """
    Return a multi line string representation of the log messages and output of a given calculation

    :param calculation: the calculation node
    :return: a string representation of the log messages and scheduler output
    """
    from aiida.backends.utils import get_log_messages
    from aiida.common.datastructures import calc_states

    log_messages = get_log_messages(calculation)
    scheduler_out = calculation.get_scheduler_output()
    scheduler_err = calculation.get_scheduler_error()
    calculation_state = calculation.get_state()
    scheduler_state = calculation.get_scheduler_state()

    report = []

    if calculation_state == calc_states.WITHSCHEDULER:
        state_string = '{}, scheduler state: {}'.format(
            calculation_state,
            scheduler_state if scheduler_state else '(unknown)')
    else:
        state_string = '{}'.format(calculation_state)

    label_string = ' [{}]'.format(
        calculation.label) if calculation.label else ''

    report.append('*** {}{}: {}'.format(calculation.pk, label_string,
                                        state_string))

    if scheduler_out is None:
        report.append('*** Scheduler output: N/A')
    elif scheduler_out:
        report.append('*** Scheduler output:\n{}'.format(scheduler_out))
    else:
        report.append('*** (empty scheduler output file)')

    if scheduler_err is None:
        report.append('*** Scheduler errors: N/A')
    elif scheduler_err:
        report.append('*** Scheduler errors:\n{}'.format(scheduler_err))
    else:
        report.append('*** (empty scheduler errors file)')

    if log_messages:
        report.append('*** {} LOG MESSAGES:'.format(len(log_messages)))
    else:
        report.append('*** 0 LOG MESSAGES')

    for log in log_messages:
        report.append('+-> {} at {}'.format(log['levelname'], log['time']))
        for message in log['message'].splitlines():
            report.append(' | {}'.format(message))

    return '\n'.join(report)
コード例 #7
0
    def print_logshow(self, *args):
        from aiida.backends.utils import load_dbenv, is_dbenv_loaded
        if not is_dbenv_loaded():
            load_dbenv()

        from aiida.orm.utils import load_workflow
        from aiida.backends.utils import get_log_messages
        from aiida.common.exceptions import NotExistent

        for wf_pk in args:
            try:
                wf = load_workflow(int(wf_pk))
            except ValueError:
                print "*** {}: Not a valid PK".format(wf_pk)
                continue
            except NotExistent:
                print "*** {}: Not a valid Workflow".format(wf_pk)
                continue

            log_messages = get_log_messages(wf)
            label_string = " [{}]".format(wf.label) if wf.label else ""
            state = wf.get_state()
            print "*** {}{}: {}".format(wf_pk, label_string, state)

            if wf.get_report():
                print "Print the report with 'verdi workflow report {}'".format(
                    wf_pk)
            else:
                print "*** Report is empty"

            if log_messages:
                print "*** {} LOG MESSAGES:".format(len(log_messages))
            else:
                print "*** 0 LOG MESSAGES"

            for log in log_messages:
                print "+-> {} at {}".format(log['levelname'], log['time'])
                # Print the message, with a few spaces in front of each line
                print "\n".join(
                    ["|   {}".format(_) for _ in log['message'].splitlines()])
コード例 #8
0
def get_node_info(node, include_summary=True):
    # pylint: disable=too-many-branches
    """
    Return a multi line string of information about the given node, such as the incoming and outcoming links

    :param include_summary: also include a summary of node properties
    :return: a string summary of the node including a description of all its links and log messages
    """
    from aiida.backends.utils import get_log_messages
    from aiida.common.links import LinkType
    from aiida.orm.calculation.work import WorkCalculation

    if include_summary:
        result = get_node_summary(node)
    else:
        result = ''

    nodes_input = node.get_inputs(link_type=LinkType.INPUT, also_labels=True)
    nodes_caller = node.get_inputs(link_type=LinkType.CALL, also_labels=True)
    nodes_create = node.get_outputs(link_type=LinkType.CREATE,
                                    also_labels=True)
    nodes_return = node.get_outputs(link_type=LinkType.RETURN,
                                    also_labels=True)
    nodes_called = node.get_outputs(link_type=LinkType.CALL, also_labels=True)
    nodes_output = nodes_create + nodes_return

    if nodes_caller:
        table = []
        table_headers = ['Called by', 'PK', 'Type']
        for key, value in nodes_caller:
            table.append([key, value.pk, value.__class__.__name__])
        result += '\n{}'.format(tabulate(table, headers=table_headers))

    if nodes_input:
        table = []
        table_headers = ['Inputs', 'PK', 'Type']
        for key, value in nodes_input:
            if key == 'code':
                continue
            table.append([key, value.pk, value.__class__.__name__])
        result += '\n{}'.format(tabulate(table, headers=table_headers))

    if nodes_output:
        table = []
        table_headers = ['Outputs', 'PK', 'Type']
        for key, value in nodes_output:
            table.append([key, value.pk, value.__class__.__name__])
        result += '\n{}'.format(tabulate(table, headers=table_headers))

    if nodes_called:
        table = []
        table_headers = ['Called', 'PK', 'Type']
        for key, value in nodes_called:
            table.append([key, value.pk, value.__class__.__name__])
        result += '\n{}'.format(tabulate(table, headers=table_headers))

    log_messages = get_log_messages(node)

    if log_messages:
        table = []
        table_headers = ['Log messages']
        table.append([
            'There are {} log messages for this calculation'.format(
                len(log_messages))
        ])
        if isinstance(node, WorkCalculation):
            table.append(
                ["Run 'verdi work report {}' to see them".format(node.pk)])
        else:
            table.append([
                "Run 'verdi calculation logshow {}' to see them".format(
                    node.pk)
            ])
        result += '\n{}'.format(tabulate(table, headers=table_headers))

    return result
コード例 #9
0
print('Code name in db: {}'.format(calc.get_code()))
#print "Input structure (chemical formula): {}".format(calc.inp.structure.get_formula())
print('Code name/version: {}'.format(res.creator_name))
print('The following files were retrieved: {}'.format(
    calc.out.retrieved.get_folder_list()))

#print "Wall time: {} s".format(calc.res.wall_time_seconds)
#print "Input wavefunction cutoff: {} Ry".format(calc.inp.parameters.dict.SYSTEM['ecutwfc'])
print('The total energy of the system is {} eV'.format(res.energy))
print('The fermi energy of the system is {} htr'.format(res.fermi_energy))

if res.number_of_spin_components == 1:
    print('Non magnetic calculation, 1 spin component')
    print('Charge distance of the system is: {} me/bohr^3'.format(
        res.charge_density))
else:
    print('Magnetic calculation, 2 spin components')
    print('Charge distance spin 1 of the system is: {} me/bohr^3'.format(
        res.charge_density1))
    print('Charge distance spin 2 of the system is: {} me/bohr^3'.format(
        res.charge_density2))
    print('Spin density distance of the system is: {} me/bohr^3'.format(
        res.spin_density))

#if calc.res.warnings:
#    print "List of warnings:"
#    for warning in calc.res.warnings:
#        print "- {}".format(warning)
#if 'res
print('Log messages: {}'.format(get_log_messages(calc)))
コード例 #10
0
print "Code name in db: {}".format(calc.get_code())
#print "Input structure (chemical formula): {}".format(calc.inp.structure.get_formula())
print "Code name/version: {}".format(res.creator_name)
print "The following files were retrieved: {}".format(
    calc.out.retrieved.get_folder_list())

#print "Wall time: {} s".format(calc.res.wall_time_seconds)
#print "Input wavefunction cutoff: {} Ry".format(calc.inp.parameters.dict.SYSTEM['ecutwfc'])
print "The total energy of the system is {} eV".format(res.energy)
print "The fermi energy of the system is {} htr".format(res.fermi_energy)

if res.number_of_spin_components == 1:
    print "Non magnetic calculation, 1 spin component"
    print "Charge distance of the system is: {} me/bohr^3".format(
        res.charge_density)
else:
    print "Magnetic calculation, 2 spin components"
    print "Charge distance spin 1 of the system is: {} me/bohr^3".format(
        res.charge_density1)
    print "Charge distance spin 2 of the system is: {} me/bohr^3".format(
        res.charge_density2)
    print "Spin density distance of the system is: {} me/bohr^3".format(
        res.spin_density)

#if calc.res.warnings:
#    print "List of warnings:"
#    for warning in calc.res.warnings:
#        print "- {}".format(warning)
#if 'res
print "Log messages: {}".format(get_log_messages(calc))