Пример #1
0
    def test_session_update_and_expiration_2(self):
        """
        expire_on_commit=True & committing computer and code objects with
        their built-in store function.
        """
        from aiida.backends.sqlalchemy.models.user import DbUser
        from aiida.orm.computer import Computer
        from aiida.orm.code import Code
        from aiida.orm.user import User

        session = aiida.backends.sqlalchemy.get_scoped_session()

        self.set_connection(expire_on_commit=True)

        user = User(email=get_configured_user_email())
        session.add(user._dbuser)
        session.commit()

        defaults = dict(name='localhost',
                        hostname='localhost',
                        transport_type='local',
                        scheduler_type='pbspro',
                        workdir='/tmp/aiida')
        computer = Computer(**defaults)
        computer.store()

        code = Code()
        code.set_remote_computer_exec((computer, '/x.x'))
        code.store()

        self.drop_connection()
Пример #2
0
    def test_computer_delete(self):
        """
        Test if 'verdi computer delete' command works
        """
        from aiida.orm.computer import Computer as AiidaOrmComputer
        from aiida.common.exceptions import NotExistent

        # Setup a computer to delete during the test
        comp = AiidaOrmComputer(name='computer_for_test_delete',
                                hostname='localhost',
                                transport_type='local',
                                scheduler_type='direct',
                                workdir='/tmp/aiida')
        comp.store()

        # See if the command complains about not getting an invalid computer
        options = ['non_existent_computer_name']
        result = self.runner.invoke(computer_delete, options)
        # Exception should be raised
        self.assertIsNotNone(result.exception)

        # Delete a computer name successully.
        options = ['computer_for_test_delete']
        result = self.runner.invoke(computer_delete, options)
        # Exception should be not be raised
        self.assertIsNone(result.exception)
        # Check that the computer really was deleted
        with self.assertRaises(NotExistent):
            AiidaOrmComputer.get('computer_for_test_delete')
Пример #3
0
    def computer_setup(self, *args):
        """
        Setup a new or existing computer
        """
        import readline

        if len(args) != 0:
            print >> sys.stderr, ("after 'computer setup' there cannot be any "
                                  "argument.")
            sys.exit(1)

        if not is_dbenv_loaded():
            load_dbenv()

        from aiida.common.exceptions import NotExistent, ValidationError
        from aiida.orm.computer import Computer as AiidaOrmComputer

        print "At any prompt, type ? to get some help."
        print "---------------------------------------"

        # get the new computer name
        readline.set_startup_hook(lambda: readline.insert_text(previous_value))
        input_txt = raw_input("=> Computer name: ")
        if input_txt.strip() == '?':
            print "HELP:", "The computer name"
        computer_name = input_txt.strip()

        try:
            computer = self.get_computer(name=computer_name)
            print "A computer called {} already exists.".format(computer_name)
            print "Use 'verdi computer update' to update it, and be careful if"
            print "you really want to modify a database entry!"
            print "Now exiting..."
            sys.exit(1)
        except NotExistent:
            computer = AiidaOrmComputer(name=computer_name)
            print "Creating new computer with name '{}'".format(computer_name)

        prompt_for_computer_configuration(computer)

        try:
            computer.store()
        except ValidationError as e:
            print "Unable to store the computer: {}. Exiting...".format(
                e.message)
            sys.exit(1)

        print "Computer '{}' successfully stored in DB.".format(computer_name)
        print "pk: {}, uuid: {}".format(computer.pk, computer.uuid)
        print "Note: before using it with AiiDA, configure it using the command"
        print "  verdi computer configure {}".format(computer_name)
        print "(Note: machine_dependent transport parameters cannot be set via "
        print "the command-line interface at the moment)"
Пример #4
0
    def setUpClass(cls):
        """
        Basides the standard setup we need to add few more objects in the
        database to be able to explore different requests/filters/orderings etc.
        """

        # call parent setUpClass method
        super(RESTApiTestCase, cls).setUpClass()

        # connect the app and the api
        # Init the api by connecting it the the app (N.B. respect the following
        # order, api.__init__)
        kwargs = dict(PREFIX=cls._url_prefix,
                      PERPAGE_DEFAULT=cls._PERPAGE_DEFAULT,
                      LIMIT_DEFAULT=cls._LIMIT_DEFAULT)

        cls.app = App(__name__)
        cls.app.config['TESTING'] = True
        api = AiidaApi(cls.app, **kwargs)

        # create test inputs
        cell = ((2., 0., 0.), (0., 2., 0.), (0., 0., 2.))
        structure = StructureData(cell=cell)
        structure.append_atom(position=(0., 0., 0.), symbols=['Ba'])
        structure.store()

        cif = CifData(ase=structure.get_ase())
        cif.store()

        parameter1 = ParameterData(dict={"a": 1, "b": 2})
        parameter1.store()

        parameter2 = ParameterData(dict={"c": 3, "d": 4})
        parameter2.store()

        kpoint = KpointsData()
        kpoint.set_kpoints_mesh([4, 4, 4])
        kpoint.store()

        calc = Calculation()
        calc._set_attr("attr1", "OK")
        calc._set_attr("attr2", "OK")
        calc.store()

        calc.add_link_from(structure)
        calc.add_link_from(parameter1)
        kpoint.add_link_from(calc, link_type=LinkType.CREATE)

        calc1 = Calculation()
        calc1.store()

        from aiida.orm.computer import Computer

        dummy_computers = [{
            "name": "test1",
            "hostname": "test1.epfl.ch",
            "transport_type": "ssh",
            "scheduler_type": "pbspro",
        }, {
            "name": "test2",
            "hostname": "test2.epfl.ch",
            "transport_type": "ssh",
            "scheduler_type": "torque",
        }, {
            "name": "test3",
            "hostname": "test3.epfl.ch",
            "transport_type": "local",
            "scheduler_type": "slurm",
        }, {
            "name": "test4",
            "hostname": "test4.epfl.ch",
            "transport_type": "ssh",
            "scheduler_type": "slurm",
        }]

        for dummy_computer in dummy_computers:
            computer = Computer(**dummy_computer)
            computer.store()

        # Prepare typical REST responses
        cls.process_dummy_data()
Пример #5
0
class DjangoTests(AiidaTestImplementation):
    """
    Automatically takes care of the setUpClass and TearDownClass, when needed.
    """

    # Note this is has to be a normal method, not a class method
    def setUpClass_method(self):
        self.clean_db()
        self.insert_data()

    def setUp_method(self):
        pass

    def tearDown_method(self):
        pass

    def insert_data(self):
        """
        Insert default data into the DB.
        """
        from django.core.exceptions import ObjectDoesNotExist

        from aiida.backends.djsite.db.models import DbUser
        from aiida.orm.computer import Computer
        from aiida.common.utils import get_configured_user_email
        # We create the user only once:
        # Otherwise, get_automatic_user() will fail when the
        # user is recreated because it caches the user!
        # In any case, store it in self.user though
        try:
            self.user = DbUser.objects.get(email=get_configured_user_email())
        except ObjectDoesNotExist:
            self.user = DbUser.objects.create_user(get_configured_user_email(),
                                                   'fakepwd')
        # Reqired by the calling class
        self.user_email = self.user.email

        # Also self.computer is required by the calling class
        self.computer = Computer(name='localhost',
                                 hostname='localhost',
                                 transport_type='local',
                                 scheduler_type='pbspro',
                                 workdir='/tmp/aiida')
        self.computer.store()

    def clean_db(self):
        from aiida.backends.djsite.db.models import DbComputer

        # I first delete the workflows
        from aiida.backends.djsite.db.models import DbWorkflow, DbWorkflowStep, DbWorkflowData

        # Complicated way to make sure we 'unwind' all the relationships
        # between workflows and their children.
        DbWorkflowStep.calculations.through.objects.all().delete()
        DbWorkflowStep.sub_workflows.through.objects.all().delete()
        DbWorkflowData.objects.all().delete()
        DbWorkflowStep.objects.all().delete()
        DbWorkflow.objects.all().delete()

        # Delete groups
        from aiida.backends.djsite.db.models import DbGroup

        DbGroup.objects.all().delete()

        # I first need to delete the links, because in principle I could
        # not delete input nodes, only outputs. For simplicity, since
        # I am deleting everything, I delete the links first
        from aiida.backends.djsite.db.models import DbLink

        DbLink.objects.all().delete()

        # Then I delete the nodes, otherwise I cannot
        # delete computers and users
        from aiida.backends.djsite.db.models import DbNode

        DbNode.objects.all().delete()

        ## I do not delete it, see discussion in setUpClass
        # try:
        #    DbUser.objects.get(email=get_configured_user_email()).delete()
        # except ObjectDoesNotExist:
        #    pass

        DbComputer.objects.all().delete()

        from aiida.backends.djsite.db.models import DbLog

        DbLog.objects.all().delete()

    # Note this is has to be a normal method, not a class method
    def tearDownClass_method(self):
        from aiida.settings import REPOSITORY_PATH
        from aiida.common.setup import TEST_KEYWORD
        from aiida.common.exceptions import InvalidOperation

        base_repo_path = os.path.basename(os.path.normpath(REPOSITORY_PATH))
        if TEST_KEYWORD not in base_repo_path:
            raise InvalidOperation("Be careful. The repository for the tests "
                                   "is not a test repository. I will not "
                                   "empty the database and I will not delete "
                                   "the repository. Repository path: "
                                   "{}".format(REPOSITORY_PATH))

        self.clean_db()

        # I clean the test repository
        shutil.rmtree(REPOSITORY_PATH, ignore_errors=True)
        os.makedirs(REPOSITORY_PATH)
Пример #6
0
    def setUpClass(cls):
        """
        Basides the standard setup we need to add few more objects in the
        database to be able to explore different requests/filters/orderings etc.
        """

        # call parent setUpClass method
        super(RESTApiTestCase, cls).setUpClass()

        # create test inputs
        cell = ((2., 0., 0.), (0., 2., 0.), (0., 0., 2.))
        structure = StructureData(cell=cell)
        structure.append_atom(position=(0., 0., 0.), symbols=['Ba'])
        structure.store()

        parameter1 = ParameterData(dict={"a": 1, "b": 2})
        parameter1.store()

        parameter2 = ParameterData(dict={"c": 3, "d": 4})
        parameter2.store()

        kpoint = KpointsData()
        kpoint.set_kpoints_mesh([4, 4, 4])
        kpoint.store()

        calc = Calculation()
        calc._set_attr("attr1", "OK")
        calc._set_attr("attr2", "OK")
        calc.store()

        calc.add_link_from(structure)
        calc.add_link_from(parameter1)
        kpoint.add_link_from(calc, link_type=LinkType.CREATE)

        calc1 = Calculation()
        calc1.store()

        from aiida.orm.computer import Computer

        dummy_computers = [{
            "name": "test1",
            "hostname": "test1.epfl.ch",
            "transport_type": "ssh",
            "scheduler_type": "pbspro",
        }, {
            "name": "test2",
            "hostname": "test2.epfl.ch",
            "transport_type": "ssh",
            "scheduler_type": "torque",
        }, {
            "name": "test3",
            "hostname": "test3.epfl.ch",
            "transport_type": "local",
            "scheduler_type": "slurm",
        }, {
            "name": "test4",
            "hostname": "test4.epfl.ch",
            "transport_type": "ssh",
            "scheduler_type": "slurm",
        }]

        for dummy_computer in dummy_computers:
            computer = Computer(**dummy_computer)
            computer.store()

        # Prepare typical REST responses
        cls.process_dummy_data()
Пример #7
0
class TestWf(PluginTestCase):
    def setUp(self):
        """
        """
        from aiida import work
        from aiida.orm.code import Code
        from aiida.orm.nodes.parameter import Dict
        from aiida.orm.nodes.structure import StructureData
        from aiida.orm.nodes.remote import RemoteData
        from ase.spacegroup import crystal
        from aiida_quantumespresso.calculations.pw import PwCalculation
        from aiida_yambo.calculations.gw import YamboCalculation
        from aiida.common.links import LinkType
        from aiida.orm.computer import Computer as AiidaOrmComputer
        from aiida.common.datastructures import calc_states
        from aiida.plugins.utils import DataFactory
        runner = work.Runner(poll_interval=0.,
                             rmq_config=None,
                             enable_persistence=None)
        work.set_runner(runner)
        self.computer = AiidaOrmComputer(name="testcase")
        # conf_attrs hostname, description, enabled_state, transport_type, scheduler_type,  workdir
        # mpirun_command , default_mpiprocs_per_machine,
        self.computer._set_hostname_string("localhost")
        self.computer._set_enabled_state_string('True')
        self.computer._set_transport_type_string("local")
        self.computer._set_scheduler_type_string("direct")
        self.computer._set_workdir_string("/tmp/testcase/{username}/base")
        self.computer.store()
        create_authinfo(computer=self.computer).store()
        self.code_yambo = Code()
        self.code_yambo.label = "yambo"
        os_env = os.environ.copy()
        yambo_path = subprocess.check_output(['which', 'mock_yambo'],
                                             env=os_env).strip()
        self.code_yambo.set_remote_computer_exec((self.computer, yambo_path))
        self.code_yambo.set_input_plugin_name('yambo.yambo')

        self.code_p2y = Code()
        self.code_p2y.label = "p2y"
        p2y_path = subprocess.check_output(['which', 'mock_p2y'],
                                           env=os_env).strip()
        self.code_p2y.set_remote_computer_exec((self.computer, p2y_path))
        self.code_p2y.set_input_plugin_name('yambo.yambo')
        self.code_yambo.store()
        self.code_p2y.store()

        self.calc_pw = PwCalculation()
        self.calc_pw.set_computer(self.computer)
        self.calc_pw.set_resources({
            "num_machines": 1,
            "num_mpiprocs_per_machine": 16,
            'default_mpiprocs_per_machine': 16
        })
        StructureData = DataFactory('structure')
        cell = [[15.8753100000, 0.0000000000, 0.0000000000],
                [0.0000000000, 15.8753100000, 0.0000000000],
                [0.0000000000, 0.0000000000, 2.4696584760]]
        s = StructureData(cell=cell)
        self.calc_pw.use_structure(s)
        print((self.calc_pw.store_all(), " pw calc"))
        pw_remote_folder = RemoteData(computer=self.computer,
                                      remote_path="/tmp/testcase/work/calcPW")
        print((pw_remote_folder.store(), "pw remote data"))
        self.calc_pw._set_state(calc_states.PARSING)
        pw_remote_folder.add_link_from(self.calc_pw,
                                       label='remote_folder',
                                       link_type=LinkType.CREATE)

        outputs = Dict(
            dict={
                "lsda": False,
                "number_of_bands": 80,
                "number_of_electrons": 8.0,
                "number_of_k_points": 147,
                "non_colinear_calculation": False
            })
        outputs.store()
        outputs.add_link_from(self.calc_pw,
                              label='output_parameters',
                              link_type=LinkType.CREATE)

        self.calc = YamboCalculation()
        self.calc.set_computer(self.computer)
        self.calc.use_code(self.code_p2y)
        p2y_settings = {
            u'ADDITIONAL_RETRIEVE_LIST':
            [u'r-*', u'o-*', u'l-*', u'l_*', u'LOG/l-*_CPU_1'],
            u'INITIALISE':
            True
        }
        yambo_settings = {
            u'ADDITIONAL_RETRIEVE_LIST':
            [u'r-*', u'o-*', u'l-*', u'l_*', u'LOG/l-*_CPU_1']
        }
        self.calc.use_settings(Dict(dict=p2y_settings))
        self.calc.set_resources({
            "num_machines": 1,
            "num_mpiprocs_per_machine": 16,
            'default_mpiprocs_per_machine': 16
        })
        self.calc.use_parent_calculation(self.calc_pw)
        print((self.calc.store_all(), " yambo calc"))
        self.calc._set_state(calc_states.PARSING)
        a = 5.388
        cell = crystal('Si', [(0, 0, 0)],
                       spacegroup=227,
                       cellpar=[a, a, a, 90, 90, 90],
                       primitive_cell=True)
        self.struc = StructureData(ase=cell)
        self.struc.store()
        self.parameters = Dict(
            dict={
                "BndsRnXp": [1.0, 48.0],
                "Chimod": "Hartree",
                "DysSolver": "n",
                "FFTGvecs": 25,
                "FFTGvecs_units": "Ry",
                "GbndRnge": [1.0, 48.0],
                "HF_and_locXC": True,
                "LongDrXp": [1.0, 0.0, 0.0],
                "NGsBlkXp": 2,
                "NGsBlkXp_units": "Ry",
                "QPkrange": [[1, 145, 3, 5]],
                "SE_CPU": "1 2 4",
                "SE_ROLEs": "q qp b",
                "X_all_q_CPU": "1 1 4 2",
                "X_all_q_ROLEs": "q k c v",
                "em1d": True,
                "gw0": True,
                "ppa": True,
                "rim_cut": True
            })
        self.yambo_settings = Dict(
            dict={
                "ADDITIONAL_RETRIEVE_LIST": [
                    "r-*", "o-*", "l-*", "l_*", "LOG/l-*_CPU_1",
                    "aiida/ndb.QP", "aiida/ndb.HF_and_locXC"
                ]
            })
        self.p2y_settings = Dict(
            dict={
                "ADDITIONAL_RETRIEVE_LIST": [
                    'r-*', 'o-*', 'l-*', 'l_*', 'LOG/l-*_CPU_1',
                    'aiida/ndb.QP', 'aiida/ndb.HF_and_locXC'
                ],
                'INITIALISE':
                True
            })
        self.yambo_calc_set = Dict(
            dict={
                'resources': {
                    "num_machines": 1,
                    "num_mpiprocs_per_machine": 16
                },
                'max_wallclock_seconds': 60 * 29,
                'max_memory_kb': 1 * 88 * 1000000,
                "queue_name":
                "s3parvc3",  #'custom_scheduler_commands': u"#PBS -A  Pra14_3622" ,
                'environment_variables': {
                    "OMP_NUM_THREADS": "1"
                }
            })
        self.p2y_calc_set = Dict(
            dict={
                'resources': {
                    "num_machines": 1,
                    "num_mpiprocs_per_machine": 2
                },
                'max_wallclock_seconds': 60 * 2,
                'max_memory_kb': 1 * 10 * 1000000,
                "queue_name":
                "s3parvc3",  # 'custom_scheduler_commands': u"#PBS -A  Pra14_3622" ,
                'environment_variables': {
                    "OMP_NUM_THREADS": "2"
                }
            })
        self.remote_folder = RemoteData(computer=self.computer,
                                        remote_path="/tmp/testcase/work/calcX")
        self.remote_folder.store()
        self.remote_folder.add_link_from(self.calc,
                                         label='remote_folder',
                                         link_type=LinkType.CREATE)
        self.calc._set_state(calc_states.FINISHED)
        #self.calc.store_all()

    def tearDown(self):
        """
        """
        pass

    def test_simple_log(self):
        from aiida.engine.launch import run
        from aiida.orm.nodes import Float, Str, NumericType, List, Bool
        from aiida_yambo.workflows.yamborestart import YamboRestartWf
        p2y_result = run(YamboRestartWf,
                         precode=Str('p2y'),
                         yambocode=Str('yambo'),
                         parameters=self.parameters,
                         calculation_set=self.yambo_calc_set,
                         parent_folder=self.remote_folder,
                         settings=self.yambo_settings)
        assert 'retrieved' in p2y_result