Пример #1
0
    def _generate_controller(self, exp_def: XMLLuigi) -> None:
        if self.category not in self.controller_config:
            self.logger.fatal(
                "Controller category '%s' not found in YAML configuration",
                self.category)
            assert False

        if not any([
                self.name in config['name'] for config in
                self.controller_config[self.category]['controllers']
        ]):
            self.logger.fatal(
                "Controller name '%s' not found in YAML configuration",
                self.name)
            assert False

        self.logger.debug(
            "Applying changes from controllers.yaml (all experiments)")
        for controller in self.controller_config[self.category]['controllers']:
            if controller['name'] != self.name:
                continue

            chgs = controller.get('xml', {}).get('attr_change', {})
            for t in chgs:
                exp_def.attr_change(t[0], t[1], t[2])

            chgs = controller.get('xml', {}).get('tag_change', {})
            for t in chgs:
                exp_def.tag_change(t[0], t[1], t[2])

            adds = controller.get('xml', {}).get('tag_add', {})
            for t in adds:
                self._do_tag_add(exp_def, XMLTagAdd(t[0], t[1], t[2], False))
Пример #2
0
def apply_to_expdef(var,
                    exp_def: XMLLuigi) -> tp.Tuple[tp.Optional[XMLTagRmList],
                                                   tp.Optional[XMLTagAddList],
                                                   tp.Optional[XMLAttrChangeSet]]:
    """
    Remove existing XML tags, add new XML tags, and change existing XML
    attributes (in that order) for the specified variable.
    """
    rmsl = var.gen_tag_rmlist()  # type: tp.List[XMLTagRmList]
    addsl = var.gen_tag_addlist()  # type: tp.List[XMLTagAddList]
    chgsl = var.gen_attr_changelist()  # type: tp.List[XMLAttrChangeSet]

    if rmsl:
        rms = rmsl[0]
        for r in rms:
            exp_def.tag_remove(r.path, r.tag)
    else:
        rms = None

    if addsl:
        adds = addsl[0]
        for a in adds:
            exp_def.tag_add(a.path, a.tag, a.attr, a.allow_dup)
    else:
        adds = None

    if chgsl:
        chgs = chgsl[0]
        for c in chgs:
            exp_def.attr_change(c.path, c.attr, c.value)
    else:
        chgs = None

    return rms, adds, chgs
Пример #3
0
    def __generate_visualization(self, exp_def: XMLLuigi):
        """
        Generates XML changes for setting up rendering for a specific simulation
        """
        self.logger.trace("Generating visualization changes for run%s",
                          self.run_num)

        if self.cmdopts['platform_vc']:
            frames_fpath = os.path.join(self.run_output_path,
                                        config.kARGoS['frames_leaf'])
            exp_def.attr_change(".//qt-opengl/frame_grabbing", "directory",
                                frames_fpath)  # probably will not be present
Пример #4
0
    def _generate_threading(self, exp_def: XMLLuigi) -> None:
        """
        Generates XML changes to set the # of cores for a simulation to use,
        which may be less than the total # available on the system, depending on
        the experiment definition and user preferences.

        Does not write generated changes to the simulation definition pickle
        file.
        """
        self.logger.trace("Generating changes for threading (all runs)")
        exp_def.attr_change(".//system", "threads",
                            str(self.cmdopts["physics_n_engines"]))
Пример #5
0
    def _generate_n_robots(self, xml: XMLLuigi) -> None:
        """
        Generate XML changes to setup # robots if it was specified on the
        cmdline.

        Writes generated changes to the simulation definition pickle file.
        """
        if self.cmdopts['n_robots'] is None:
            return

        self.logger.trace("Generating changes for # robots (all runs)")
        chgs = population_size.PopulationSize.gen_attr_changelist_from_list(
            [self.cmdopts['n_robots']])
        for a in chgs[0]:
            xml.attr_change(a.path, a.attr, a.value, True)

        # Write # robots info to file for later retrieval
        chgs[0].pickle(self.spec.exp_def_fpath)
Пример #6
0
    def _generate_controller_support(self, exp_def: XMLLuigi) -> None:
        # Setup controller support code (if any)
        chgs = self.controller_config.get(self.category,
                                          {}).get('xml',
                                                  {}).get('attr_change', {})
        for t in chgs:
            exp_def.attr_change(t[0], t[1], t[2])

        chgs = self.controller_config.get(self.category,
                                          {}).get('xml',
                                                  {}).get('tag_change', {})
        for t in chgs:
            exp_def.tag_change(t[0], t[1], t[2])

        adds = self.controller_config.get(self.category,
                                          {}).get('xml',
                                                  {}).get('tag_add', {})
        for t in adds:
            self._do_tag_add(exp_def, t)
Пример #7
0
    def _generate_library(self, exp_def: XMLLuigi) -> None:
        """
        Generates XML changes to set the library that controllers and loop
        functions are sourced from to the name of the plugin passed on the
        cmdline. The ``__CONTROLLER__`` tag is changed during stage 1, but since
        this function is called as part of common def generation, it happens
        BEFORE that, and so this is OK. If, for some reason that assumption
        becomes invalid, a warning will be issued about a non-existent XML path,
        so it won't be a silent error.

        Does not write generated changes to the simulation definition pickle
        file.

        """
        self.logger.trace("Generating changes for library (all runs)")
        run_config = self.spec.criteria.main_config['sierra']['run']
        lib_name = run_config.get('library_name',
                                  'lib' + self.cmdopts['project'])
        exp_def.attr_change(".//loop_functions", "library", lib_name)
        exp_def.attr_change(".//__CONTROLLER__", "library", lib_name)
Пример #8
0
    def _scaffold_expi(self,
                       expi_def: xml.XMLLuigi,
                       modsi: tp.Union[xml.XMLAttrChangeSet, xml.XMLTagAddList],
                       i: int,
                       cmdopts: types.Cmdopts) -> None:
        exp_dirname = self.gen_exp_dirnames(cmdopts)[i]
        self.logger.debug("Applying %s XML modifications from '%s' for exp%s in %s",
                          len(modsi),
                          self.cli_arg,
                          i,
                          exp_dirname)

        exp_input_root = os.path.join(self.batch_input_root,
                                      str(exp_dirname))

        utils.dir_create_checked(exp_input_root,
                                 exist_ok=cmdopts['exp_overwrite'])

        for mod in modsi:
            if isinstance(mod, xml.XMLAttrChange):
                expi_def.attr_change(mod.path, mod.attr, mod.value)
            elif isinstance(mod, xml.XMLTagAdd):
                expi_def.tag_add(mod.path, mod.tag, mod.attr, mod.allow_dup)
            else:
                assert False,\
                    "Batch criteria can only modify or remove XML tags"

        # This will be the "template" input file used to generate the input
        # files for each experimental run in the experiment
        wr_config = xml.XMLWriterConfig([{'src_parent': None,
                                          'src_tag': '.',
                                          'opath_leaf': None,
                                          'create_tags': None,
                                          'dest_parent': None
                                          }])
        expi_def.write_config_set(wr_config)
        opath = utils.batch_template_path(cmdopts,
                                          self.batch_input_root,
                                          exp_dirname)
        expi_def.write(opath)