Exemplo n.º 1
0
    def setUp(self):
        self.comp = Computer.get('comp')
        self.runner = CliRunner()
        self.this_folder = os.path.dirname(__file__)
        self.this_file = os.path.basename(__file__)

        self.cli_runner = CliRunner()
Exemplo n.º 2
0
    def setUp(self):
        from aiida.orm import Computer
        self.comp = Computer.get('comp')

        self.runner = CliRunner()
        self.this_folder = os.path.dirname(__file__)
        self.this_file = os.path.basename(__file__)
Exemplo n.º 3
0
def get_computer(name='localhost'):
    """Get local computer.

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

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

    try:
        computer = Computer.get(name)
    except NotExistent:

        computer = Computer(
            name=name,
            description='localhost computer set up by aiida_gudhi tests',
            hostname='localhost',
            workdir=tempfile.mkdtemp(),
            transport_type='local',
            scheduler_type='direct',
            enabled_state=True)
        computer.store()

    return computer
Exemplo n.º 4
0
def set_deneb_defaults(options_template):
    from aiida.orm import Computer

    options_template.max_wallclock_seconds = DEFAULT_OPTIONS[
        'max_wallclock_seconds']
    options_template.resources = DEFAULT_OPTIONS['resources']
    options_template.queue_name = DEFAULT_OPTIONS['queue_name']
    options_template.computer = Computer.get(DEFAULT_OPTIONS['computer'])
Exemplo n.º 5
0
    def test_mixed(self):
        from aiida.orm import Computer
        os.environ['VISUAL'] = 'sleep 1; vim -cwq'
        os.environ['EDITOR'] = 'sleep 1; vim -cwq'
        label = 'mixed_computer'

        options_dict = generate_setup_options_dict(
            replace_args={'label': label})
        options_dict_full = options_dict.copy()

        options_dict.pop('non-interactive', 'None')

        non_interactive_options_dict = {}
        non_interactive_options_dict['enabled'] = None

        non_interactive_options_dict['prepend-text'] = options_dict.pop(
            'prepend-text')
        non_interactive_options_dict['append-text'] = options_dict.pop(
            'append-text')
        non_interactive_options_dict['shebang'] = options_dict.pop('shebang')
        non_interactive_options_dict['scheduler'] = options_dict.pop(
            'scheduler')

        # In any case, these would be managed by the visual editor
        user_input = "\n".join(
            generate_setup_options_interactive(options_dict))
        options = generate_setup_options(non_interactive_options_dict)

        result = self.runner.invoke(setup_computer, options, input=user_input)
        self.assertIsNone(
            result.exception,
            msg="There was an unexpected exception. Output: {}".format(
                result.output))

        new_computer = Computer.get(label)
        self.assertIsInstance(new_computer, Computer)

        self.assertEqual(new_computer.description,
                         options_dict_full['description'])
        self.assertEqual(new_computer.hostname, options_dict_full['hostname'])
        self.assertEqual(new_computer.get_transport_type(),
                         options_dict_full['transport'])
        self.assertEqual(new_computer.get_scheduler_type(),
                         options_dict_full['scheduler'])
        self.assertTrue(new_computer.is_enabled())
        self.assertEqual(new_computer.get_mpirun_command(),
                         options_dict_full['mpirun-command'].split())
        self.assertEqual(new_computer.get_shebang(),
                         options_dict_full['shebang'])
        self.assertEqual(new_computer.get_workdir(),
                         options_dict_full['work-dir'])
        self.assertEqual(new_computer.get_default_mpiprocs_per_machine(),
                         int(options_dict_full['mpiprocs-per-machine']))
        # For now I'm not writing anything in them
        self.assertEqual(new_computer.get_prepend_text(),
                         options_dict_full['prepend-text'])
        self.assertEqual(new_computer.get_append_text(),
                         options_dict_full['append-text'])
Exemplo n.º 6
0
 def test_data_loaded(self):
     """
     Check that the data is indeed in the DB when calling load_node
     """
     from aiida.orm import Computer
     from aiida.orm import load_node
     self.assertTrue(is_dbenv_loaded())
     self.assertEqual(load_node(self.data_pk).uuid, self.data.uuid)
     self.assertEqual(Computer.get('localhost').uuid, self.computer.uuid)
Exemplo n.º 7
0
    def test_delete(self):
        from aiida.orm import Computer
        new_comp = Computer(name='aaa',
                            hostname='aaa',
                            transport_type='local',
                            scheduler_type='pbspro',
                            workdir='/tmp/aiida')
        new_comp.store()

        comp_pk = new_comp.pk

        check_computer = Computer.get(comp_pk)
        self.assertEquals(comp_pk, check_computer.pk)

        from aiida.orm.computer import delete_computer
        delete_computer(pk=comp_pk)

        with self.assertRaises(NotExistent):
            Computer.get(comp_pk)
Exemplo n.º 8
0
    def setUp(self):
        comp = Computer.get('comp')
        self.r = RemoteData()
        p = tempfile.mkdtemp()
        self.r.set_remote_path(p)
        with open(p + '/file.txt', 'w') as f:
            f.write("test string")
        self.r.set_computer(comp)
        self.r.store()

        self.cli_runner = CliRunner()
Exemplo n.º 9
0
def test_duplicate(cmd_test_env):
    """Test the duplicate command"""
    from aiida.orm import Computer, Code
    _ = cmd_test_env
    runner = CliRunner()

    runner.invoke(duplicate_fe, ["-Y", "localhost"], catch_exceptions=False)
    assert Computer.get(label='localhost-fw')
    assert Computer.get(
        label='localhost-fw').scheduler_type == "fireworks_scheduler.default"

    runner.invoke(duplicate_fe, ["-Y", "localhost", "--suffix", 'fe'],
                  catch_exceptions=False)
    assert Computer.get(label='localhost-fe')

    runner.invoke(duplicate_fe,
                  ["-Y", "localhost", "--suffix", 'fc', '--include-codes'],
                  catch_exceptions=False)
    assert Computer.get(label='localhost-fc')
    assert Code.get_from_string("bash@localhost-fc")

    runner.invoke(
        duplicate_fe,
        ["-Y", "localhost", "--job-should-keep-env", "--suffix", 'env'],
        catch_exceptions=False)
    assert Computer.get(label='localhost-env')
    assert Computer.get(
        label='localhost-env').scheduler_type == "fireworks_scheduler.keepenv"
Exemplo n.º 10
0
    def generate_calc(self):
        from aiida.orm import Code, Computer, CalculationFactory
        from aiida.common.datastructures import calc_states

        CustomCalc = CalculationFactory('simpleplugins.templatereplacer')

        computer = Computer.get("localhost")

        calc = CustomCalc(computer=computer, withmpi=True)
        calc.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
        calc.store()
        calc._set_state(calc_states.FINISHED)

        return calc
Exemplo n.º 11
0
def generate_calc():
    from aiida.orm import Code, Computer, CalculationFactory
    from aiida.common.datastructures import calc_states

    CustomCalc = CalculationFactory('simpleplugins.templatereplacer')

    computer = Computer.get("localhost")

    calc = CustomCalc(computer=computer, withmpi=True)
    calc.set_resources({"num_machines": 1, "num_mpiprocs_per_machine": 1})
    calc.store()
    calc._set_state(calc_states.FINISHED)

    return calc
Exemplo n.º 12
0
    def _set_computer_string(self, string):
        """
        Set the computer starting from a string.
        """
        from aiida.common.exceptions import ValidationError, NotExistent
        from aiida.orm import Computer as AiidaOrmComputer

        try:
            computer = AiidaOrmComputer.get(string)
        except NotExistent:
            raise ValidationError("Computer with name '{}' not found in "
                                  "DB".format(string))

        self._computer_validator(computer)
        self.computer = computer
Exemplo n.º 13
0
    def setUp(self):
        from aiida.orm import Computer, Code
        self.comp = Computer.get('comp')

        try:
            code = Code.get_from_string('code')
        except NotExistent:
            code = Code(
                input_plugin_name='simpleplugins.arithmetic.add',
                remote_computer_exec=[self.comp, '/remote/abs/path'],
            )
            code.label = 'code'
            code.store()
        self.code = code

        self.runner = CliRunner()
Exemplo n.º 14
0
    def test_noninteractive_optional_default_mpiprocs(self):
        """
        Check that if is ok not to specify mpiprocs-per-machine
        """
        from aiida.orm import Computer

        options_dict = generate_setup_options_dict(
            {'label': 'computer_default_mpiprocs'})
        options_dict.pop('mpiprocs-per-machine')
        options = generate_setup_options(options_dict)
        result = self.runner.invoke(setup_computer, options)

        self.assertIsNone(result.exception, result.output[-1000:])

        new_computer = Computer.get(options_dict['label'])
        self.assertIsInstance(new_computer, Computer)
        self.assertIsNone(new_computer.get_default_mpiprocs_per_machine())
Exemplo n.º 15
0
    def test_noninteractive_optional_default_mpiprocs_2(self):
        """
        Check that if is the specified value is zero, it means unspecified
        """
        from aiida.orm import Computer

        options_dict = generate_setup_options_dict(
            {'label': 'computer_default_mpiprocs_2'})
        options_dict['mpiprocs-per-machine'] = 0
        options = generate_setup_options(options_dict)
        result = self.runner.invoke(setup_computer, options)

        self.assertIsNone(result.exception, result.output[-1000:])

        new_computer = Computer.get(options_dict['label'])
        self.assertIsInstance(new_computer, Computer)
        self.assertIsNone(new_computer.get_default_mpiprocs_per_machine())
Exemplo n.º 16
0
def run_wswannier():
    input_archive = get_input_archive()
    code = Code.get_from_string('Wannier90_2.1.0')
    calc = CalculationFactory('vasp.wswannier')()
    calc.use_code(code)
    # Monch
    calc.set_resources(dict(num_machines=1, tot_num_mpiprocs=1))
    calc.set_computer(Computer.get('Monch'))
    calc.set_queue_name('express_compute')
    calc.use_data(input_archive)
    # hard-code parameters for InSb test
    calc.use_settings(
        ParameterData(dict=dict(
            num_wann=14,
            num_bands=36,
            dis_num_iter=1000,
            num_iter=0,
            dis_win_min=-4.5,
            dis_win_max=16.,
            dis_froz_min=-4.,
            dis_froz_max=6.5,
            write_hr=True,
            use_ws_distance=True,
            write_xyz=True,
            write_tb=True,
            projections=[['In : s; px; py; pz'], ['Sb : px; py; pz']],
            spinors=True,
            unit_cell_cart=[[0., 3.2395, 3.2395], [3.2395, 0., 3.2395],
                            [3.2395, 3.2395, 0.]],
            bands_plot=True,
            atoms_cart=[['In', 0., 0., 0.], ['Sb', 1.61975, 1.61975, 1.61975]],
            mp_grid='6 6 6',
            kpoints=[
                list(reversed(x)) for x in itertools.
                product((0., 1 / 6, 2 / 6, 0.5, -2 / 6, -1 / 6), repeat=3)
            ],
            kpoint_path=[
                ['G', 0, 0, 0, 'L', 0.5, 0.5, 0.5],
            ])))
    calc.store_all()
    calc.submit()
    print('Submitted calculation', calc.pk)
Exemplo n.º 17
0
    def test_noninteractive_enabled(self):
        """
        I check what happens if the computer should be enabled, explicitly setting
        --enabled.

        I only check the changes, the rest is already checked in ``test_noninteractive()``.
        """
        from aiida.orm import Computer

        options_dict = generate_setup_options_dict(
            {'label': 'computer_enabled'})
        options_dict.pop('disabled', None)  # Make sure 'disabled' is not there
        options_dict['enabled'] = None  # Activate --enabled
        options = generate_setup_options(options_dict)

        result = self.runner.invoke(setup_computer, options)

        self.assertIsNone(result.exception, result.output[-1000:])
        new_computer = Computer.get(options_dict['label'])
        self.assertIsInstance(new_computer, Computer)
        self.assertTrue(new_computer.is_enabled())
Exemplo n.º 18
0
def get_computer(name='localhost'):
    """Setup localhost computer"""
    from aiida.orm import Computer
    from aiida.common.exceptions import NotExistent

    try:
        computer = Computer.get(name)
    except NotExistent:

        import tempfile
        computer = Computer(
            name=name,
            description='localhost computer set up by aiida_gudhi tests',
            hostname='localhost',
            workdir=tempfile.mkdtemp(),
            transport_type='local',
            scheduler_type='direct',
            enabled_state=True)
        computer.store()

    return computer
Exemplo n.º 19
0
    def test_noninteractive(self):
        """
        Main test to check if the non-interactive command works
        """
        from aiida.orm import Computer

        options_dict = generate_setup_options_dict()
        options = generate_setup_options(options_dict)

        result = self.runner.invoke(setup_computer, options)

        self.assertIsNone(result.exception, result.output[-1000:])
        new_computer = Computer.get(options_dict['label'])
        self.assertIsInstance(new_computer, Computer)

        self.assertEqual(new_computer.description, options_dict['description'])
        self.assertEqual(new_computer.hostname, options_dict['hostname'])
        self.assertEqual(new_computer.get_transport_type(),
                         options_dict['transport'])
        self.assertEqual(new_computer.get_scheduler_type(),
                         options_dict['scheduler'])
        self.assertTrue(new_computer.is_enabled())
        self.assertEqual(new_computer.get_mpirun_command(),
                         options_dict['mpirun-command'].split())
        self.assertEqual(new_computer.get_shebang(), options_dict['shebang'])
        self.assertEqual(new_computer.get_workdir(), options_dict['work-dir'])
        self.assertEqual(new_computer.get_default_mpiprocs_per_machine(),
                         int(options_dict['mpiprocs-per-machine']))
        self.assertEqual(new_computer.get_prepend_text(),
                         options_dict['prepend-text'])
        self.assertEqual(new_computer.get_append_text(),
                         options_dict['append-text'])

        # Test that I cannot generate twice a computer with the same label
        result = self.runner.invoke(setup_computer, options)
        self.assertIsInstance(result.exception, SystemExit)
        self.assertIn("already exists", result.output)
Exemplo n.º 20
0
###############################
# Set your values here
codename = 'fleur_inpgen_mac'
computer_name = 'local_mac'
#computer_name = 'iff003'
#codename2 = 'fleur_v0.27@iff003'
codename2 = 'fleur_iff003_v0_27@iff003'

#codename2 = 'fleur_mac'

###############################

code = Code.get_from_string(codename)
code2 = Code.get_from_string(codename2)
#JobCalc = FleurinputgenCalculation.process()
computer = Computer.get(computer_name)

s = load_node(14204)  #13586)#137)# Be13586, W 137
print s.sites
#print s.cell
parameters = load_node(13496)  # Be 13496, W 13161
wf_para = ParameterData(dict={
    'relax_runmax': 5,
    'density_criterion': 0.0000001,
    'max_force_cycle': 9
})

res = fleur_relax_wc.run(wf_parameters=wf_para,
                         structure=s,
                         calc_parameters=parameters,
                         inpgen=code,
Exemplo n.º 21
0
from aiida import load_dbenv
load_dbenv()

from aiida.orm import Code, Computer
from aiida.orm.querytool import QueryTool
from aiida.orm.calculation.job.vasp.maker import VaspMaker
import sys

cifname = sys.argv[1]
mkcalc = VaspMaker(structure=cifname)
mkcalc.code = Code.get_from_string('asevasp@monch')
mkcalc.kpoints.set_kpoints_mesh([8, 8, 8])
mkcalc.add_settings(system=mkcalc.structure.filename, npar=8)
mkcalc.recipe = 'test_sc'

mkcalc.computer = Computer.get('monch')
mkcalc.queue = 'dphys_compute'

v5 = mkcalc.new()
v5.set_resources({'num_machines': 8, 'num_mpiprocs_per_machine': 2})
# ~ v5.set_max_memory_kb(8000000)

tag = sys.argv[2]
q = QueryTool()
q.set_class(mkcalc.calc_cls)
q.add_extra_filter('tag', '=', tag)
ql = map(lambda c: c.get_extra('test-nr'), q.run_query())

last_tn = ql and max(ql) or 0

v5.store_all()
Exemplo n.º 22
0
            for l in valid_code_labels:
                print >> sys.stderr, "*", l
        else:
            print >> sys.stderr, "Code not valid, and no valid codes for {}. Configure at least one first using".format(
                expected_code_type)
            print >> sys.stderr, "    verdi code setup"
        sys.exit(1)

    cif = None
    if len(files) == 1:
        cif = CifData(file=os.path.abspath(files[0]))
    else:
        raise ValueError("Please specify a single CIF file")

    parameters = ParameterData(dict=options)
    computer = Computer.get(Computer.list_names()[0])

    calc = code.new_calc()
    calc.label = "Test cod-tools cif_cod_deposit"
    calc.description = "Test deposition with the cod-tools cif_cod_deposit"
    calc.set_max_wallclock_seconds(30 * 60)  # 30 min
    calc.set_resources({"num_machines": 1,
                        "num_mpiprocs_per_machine": 1})
    calc.set_computer(computer)

    calc.use_cif(cif)
    calc.use_parameters(parameters)

    if submit_test:
        subfolder, script_filename = calc.submit_test()
        print "Test_submit for calculation (uuid='{}')".format(
Exemplo n.º 23
0
    def query_jobcalculations_by_computer_user_state(
            self,
            state,
            computer=None,
            user=None,
            only_computer_user_pairs=False,
            only_enabled=True,
            limit=None):
        # Here I am overriding the implementation using the QueryBuilder:
        """
        Filter all calculations with a given state.

        Issue a warning if the state is not in the list of valid states.

        :param state: The state to be used to filter (should be a string among
                those defined in aiida.common.datastructures.calc_states)
        :type state: str
        :param computer: a Django DbComputer entry, or a Computer object, of a
                computer in the DbComputer table.
                A string for the hostname is also valid.
        :param user: a Django entry (or its pk) of a user in the DbUser table;
                if present, the results are restricted to calculations of that
                specific user
        :param bool only_computer_user_pairs: if False (default) return a queryset
                where each element is a suitable instance of Node (it should
                be an instance of Calculation, if everything goes right!)
                If True, return only a list of tuples, where each tuple is
                in the format
                ('dbcomputer__id', 'user__id')
                [where the IDs are the IDs of the respective tables]

        :return: a list of calculation objects matching the filters.
        """
        # I assume that calc_states are strings. If this changes in the future,
        # update the filter below from dbattributes__tval to the correct field.
        from aiida.orm import Computer
        from aiida.common.exceptions import InputValidationError
        from aiida.orm.implementation.django.calculation.job import JobCalculation
        from aiida.common.datastructures import calc_states
        from aiida.backends.djsite.db.models import DbUser

        if state not in calc_states:
            raise InputValidationError(
                "querying for calculation state='{}', but it "
                "is not a valid calculation state".format(state))

        kwargs = {}
        if computer is not None:
            # I convert it from various type of inputs
            # (string, DbComputer, Computer)
            # to a DbComputer type
            kwargs['dbcomputer'] = Computer.get(computer).dbcomputer
        if user is not None:
            kwargs['user'] = user
        if only_enabled:
            kwargs['dbcomputer__enabled'] = True

        queryresults = JobCalculation.query(dbattributes__key='state',
                                            dbattributes__tval=state,
                                            **kwargs)

        if only_computer_user_pairs:
            computer_users_ids = queryresults.values_list(
                'dbcomputer__id', 'user__id').distinct()
            computer_users = []
            for computer_id, user_id in computer_users_ids:  # return cls(dbcomputer=DbComputer.get_dbcomputer(computer))DbNode.objects.get(pk=pk).get_aiida_class()
                computer_users.append(
                    (Computer.get(computer_id),
                     DbUser.objects.get(pk=user_id).get_aiida_class()))
            return computer_users

        elif limit is not None:
            return queryresults[:limit]
        else:
            return queryresults
Exemplo n.º 24
0
            'lorbit': 11,
            'magmom': 3 * nions * [0.],
            'lsorbit': True,
            'nbands': nbands,
            'sigma': 0.05,
            'system': os.path.basename(cifname),
            'npar': 8,
        }))
tvc.use_structure(structure)

for kind in structure.get_kind_names():
    tvc.use_paw(Paw.load_paw(family='LDA', symbol=kind)[0], kind=kind)

tvc.use_kpoints(kp)

tvc.set_computer(Computer.get('monch'))
tvc.set_queue_name('dphys_compute')
tvc.set_resources({'num_machines': nbands / 8, 'num_mpiprocs_per_machine': 8})
tvc.set_max_memory_kb(16000000)

tvc.set_parser_name('vasp.vasp5')

tag = sys.argv[2]
q = QueryTool()
q.set_class(Tvc)
q.add_extra_filter('tag', '=', tag)
ql = map(lambda c: c.get_extra('test-nr'), q.run_query())

last_tn = max(ql)

tvc.store_all()