Beispiel #1
0
    def _on_setup_computer(self, _=None):
        """When setup computer button is pressed."""
        with self._setup_comp_out:
            clear_output()
            if self.label is None:  # check hostname
                print("Please specify the computer name (for AiiDA)")
                return
            try:
                computer = Computer.objects.get(name=self.label)
                print(f"A computer called {self.label} already exists.")
                return
            except NotExistent:
                pass

            print(f"Creating new computer with name '{self.label}'")
            computer = Computer(name=self.label,
                                hostname=self.hostname,
                                description=self.description)
            computer.set_transport_type(self.transport)
            computer.set_scheduler_type(self.scheduler)
            computer.set_workdir(self.work_dir)
            computer.set_mpirun_command(self.mpirun_command.split())
            computer.set_default_mpiprocs_per_machine(
                self.mpiprocs_per_machine)
            if self.prepend_text:
                computer.set_prepend_text(self.prepend_text)
            if self.append_text:
                computer.set_append_text(self.append_text)

            computer.store()
            self._configure_computer()
Beispiel #2
0
    def _on_setup_computer(self, change):  # pylint: disable=unused-argument
        """When setup computer button is pressed."""
        with self._setup_comp_out:
            clear_output()
            if self.name is None:  # check hostname
                print("Please specify the computer name (for AiiDA)")
                return
            try:
                computer = Computer.objects.get(name=self.name)
                print("A computer called {} already exists.".format(self.name))
                return
            except NotExistent:
                pass

            print("Creating new computer with name '{}'".format(self.name))
            computer = Computer(name=self.name,
                                hostname=self.hostname,
                                description=self.description)
            computer.set_transport_type(self.transport_type)
            computer.set_scheduler_type(self.scheduler)
            computer.set_workdir(self.workdir)
            computer.set_mpirun_command(self.mpirun_cmd.split())
            computer.set_default_mpiprocs_per_machine(self.ncpus)
            if self._prepend_text.value:
                computer.set_prepend_text(self.prepend_text)
            if self._append_text.value:
                computer.set_append_text(self.append_text)
            computer.store()
            self._configure_computer()
Beispiel #3
0
    def new(self):
        """Build and return a new computer instance (not stored)"""
        from aiida.orm import Computer

        self.validate()

        # Will be used at the end to check if all keys are known
        passed_keys = set(self._computer_spec.keys())
        used = set()

        computer = Computer(name=self._get_and_count('label', used),
                            hostname=self._get_and_count('hostname', used))

        computer.set_description(self._get_and_count('description', used))
        computer.set_scheduler_type(self._get_and_count('scheduler', used))
        computer.set_transport_type(self._get_and_count('transport', used))
        computer.set_prepend_text(self._get_and_count('prepend_text', used))
        computer.set_append_text(self._get_and_count('append_text', used))
        computer.set_workdir(self._get_and_count('work_dir', used))
        computer.set_shebang(self._get_and_count('shebang', used))

        mpiprocs_per_machine = self._get_and_count('mpiprocs_per_machine',
                                                   used)
        # In the command line, 0 means unspecified
        if mpiprocs_per_machine == 0:
            mpiprocs_per_machine = None
        if mpiprocs_per_machine is not None:
            try:
                mpiprocs_per_machine = int(mpiprocs_per_machine)
            except ValueError:
                raise self.ComputerValidationError(
                    'Invalid value provided for mpiprocs_per_machine, '
                    'must be a valid integer')
            if mpiprocs_per_machine <= 0:
                raise self.ComputerValidationError(
                    'Invalid value provided for mpiprocs_per_machine, '
                    'must be positive')
            computer.set_default_mpiprocs_per_machine(mpiprocs_per_machine)

        mpirun_command_internal = self._get_and_count('mpirun_command',
                                                      used).strip().split(' ')
        if mpirun_command_internal == ['']:
            mpirun_command_internal = []
        computer._mpirun_command_validator(mpirun_command_internal)  # pylint: disable=protected-access
        computer.set_mpirun_command(mpirun_command_internal)

        # Complain if there are keys that are passed but not used
        if passed_keys - used:
            raise self.ComputerValidationError(
                'Unknown parameters passed to the ComputerBuilder: {}'.format(
                    ', '.join(sorted(passed_keys - used))))

        return computer