Ejemplo n.º 1
0
def new_database_with_daemon(aiida_profile):
    """When you run something in aiida v1, it will be done in its own runner,
    which is a mini daemon in and of its own.
    However, in 0.12 the global daemon is the only one that can
    submit, update and retrieve job calculations.
    Therefore, we must configure and start it before running JobProcesses
    """
    if aiida_version() < cmp_version('1.0.0a1'):
        from aiida.backends.utils import set_daemon_user
        from aiida.cmdline.commands.daemon import Daemon
        from aiida.common import setup

        set_daemon_user(aiida_profile.email)
        daemon = Daemon()
        daemon.logfile = os.path.join(aiida_profile.config_dir,
                                      setup.LOG_SUBDIR, setup.CELERY_LOG_FILE)
        daemon.pidfile = os.path.join(aiida_profile.config_dir,
                                      setup.LOG_SUBDIR, setup.CELERY_PID_FILE)
        daemon.celerybeat_schedule = os.path.join(aiida_profile.config_dir,
                                                  setup.DAEMON_SUBDIR,
                                                  'celerybeat-schedule')

        if daemon.get_daemon_pid() is None:
            daemon.daemon_start()
        else:
            daemon.daemon_restart()
        yield aiida_profile
        daemon.kill_daemon()
        aiida_profile.reset_db()
    else:
        yield aiida_profile
        aiida_profile.reset_db()
Ejemplo n.º 2
0
def get_computer(name=TEST_COMPUTER, workdir=None, configure=False):
    """Get local computer.

    Sets up local computer with 'name' or reads it from database,
    if it exists.

    :param name: Name of local computer
    :param workdir: path to work directory (required if creating a new computer)
    :param configure: whether to congfigure a new computer for the user email

    :return: The computer node
    :rtype: :py:class:`aiida.orm.Computer`
    """
    from aiida.common.exceptions import NotExistent

    if aiida_version() >= cmp_version("1.0.0a2"):
        from aiida.orm.backend import construct_backend
        backend = construct_backend()
        get_computer = lambda name: backend.computers.get(name=name)
        create_computer = backend.computers.create
    else:
        from aiida.orm import Computer
        get_computer = Computer.get
        create_computer = Computer

    try:
        computer = get_computer(name)
    except NotExistent:

        if workdir is None:
            raise ValueError(
                "to create a new computer, a work directory must be supplied")

        computer = create_computer(
            name=name,
            description='localhost computer set up by aiida_crystal17 tests',
            hostname=name,
            workdir=workdir,
            transport_type='local',
            scheduler_type='direct',
            enabled_state=True)
        computer.store()

        if configure:
            try:
                # aiida-core v1
                from aiida.control.computer import configure_computer
                configure_computer(computer)
            except ImportError:
                configure_computer_v012(computer)

    return computer
Ejemplo n.º 3
0
import pytest
from aiida_crystal17.aiida_compatability import aiida_version, cmp_version


def get_main_code(workdir):
    """get the crystal17.basic code """
    computer = tests.get_computer(workdir=workdir)
    # get code
    code = tests.get_code(entry_point='crystal17.main', computer=computer)

    return code


# TODO fails on sqlalchemy for aiida v0.12 because of error in computer config
@pytest.mark.skipif(
    aiida_version() < cmp_version('1.0.0a1') and tests.is_sqla_backend(),
    reason="Error in obtaining authinfo for computer configuration")
def test_full(new_database, new_workdir):
    from aiida_crystal17.calculations.cry_main_immigrant import CryMainImmigrantCalculation

    computer = tests.get_computer(workdir=new_workdir, configure=True)
    code = tests.get_code(entry_point='crystal17.main', computer=computer)

    inpath = os.path.join(TEST_DIR, "input_files", 'nio_sto3g_afm.crystal.d12')
    outpath = os.path.join(TEST_DIR, "output_files",
                           'nio_sto3g_afm.crystal.out')

    shutil.copy(inpath, new_workdir)
    shutil.copy(outpath, new_workdir)

    resources = {'num_machines': 1, 'num_mpiprocs_per_machine': 16}