Example #1
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)
Example #2
0
    def generate(self) -> XMLLuigi:
        """
        Generates XML changes to simulation input files that are common to all
        experiments.
        """
        # ARGoS uses a single input file
        wr_config = XMLWriterConfig([{
            'src_parent':
            None,
            'src_tag':
            '.',
            'opath_leaf':
            config.kARGoS['launch_file_ext'],
            'create_tags':
            None,
            'dest_parent':
            None,
            'rename_to':
            None
        }])
        exp_def = XMLLuigi(input_fpath=self.template_input_file,
                           write_config=wr_config)

        # Generate # robots
        self._generate_n_robots(exp_def)

        # Setup library
        self._generate_library(exp_def)

        # Setup simulation visualizations
        self._generate_visualization(exp_def)

        # Setup threading
        self._generate_threading(exp_def)

        # Setup robot sensors/actuators
        self._generate_saa(exp_def)

        # Setup simulation time parameters
        self._generate_time(exp_def)

        return exp_def
Example #3
0
    def _generate_saa(self, exp_def: XMLLuigi) -> None:
        """
        Generates XML changes to disable selected sensors/actuators, which are
        computationally expensive in large swarms, but not that costly if the
        # robots is small.

        Does not write generated changes to the simulation definition pickle
        file.
        """
        self.logger.trace("Generating changes for SAA (all runs)")

        if not self.cmdopts["with_robot_rab"]:
            exp_def.tag_remove(".//media", "range_and_bearing", noprint=True)
            exp_def.tag_remove(".//actuators",
                               "range_and_bearing",
                               noprint=True)
            exp_def.tag_remove(".//sensors", "range_and_bearing", noprint=True)

        if not self.cmdopts["with_robot_leds"]:
            exp_def.tag_remove(".//actuators", "leds", noprint=True)
            exp_def.tag_remove(".//sensors",
                               "colored_blob_omnidirectional_camera",
                               noprint=True)
            exp_def.tag_remove(".//media", "led", noprint=True)

        if not self.cmdopts["with_robot_battery"]:
            exp_def.tag_remove(".//sensors", "battery", noprint=True)
            exp_def.tag_remove(".//entity/*", "battery", noprint=True)
Example #4
0
    def generate(self) -> XMLLuigi:
        exp_def = XMLLuigi(input_fpath=self.template_input_file)
        wr_config = XMLWriterConfig([])

        if exp_def.has_tag('./params'):
            self.logger.debug("Using shared XML parameter file")
            wr_config.add({
                'src_parent': '.',
                'src_tag': 'params',
                'opath_leaf': config.kROS['param_file_ext'],
                'create_tags': None,
                'dest_parent': None,
                'rename_to': None
            })

        else:
            self.ros_param_server = True

        exp_def.write_config_set(wr_config)

        # Add <master> tag
        if not exp_def.has_tag("./master"):
            exp_def.tag_add(".", "master", {})
        if not exp_def.has_tag("./master/group/[@ns='sierra']"):
            exp_def.tag_add("./master", "group", {'ns': 'sierra'})
        # Add <robot> tag
        if not exp_def.has_tag("./robot"):
            exp_def.tag_add(".", "robot", {})
        if not exp_def.has_tag("./robot/group/[@ns='sierra']"):
            exp_def.tag_add("./robot", "group", {'ns': 'sierra'})

        # Generate core experiment definitions
        self._generate_experiment(exp_def)

        return exp_def
Example #5
0
    def _generate_gazebo_core(self, exp_def: XMLLuigi) -> None:
        """
        Generate XML tag changes to setup Gazebo core experiment parameters.

        Does not write generated changes to the run definition pickle
        file.
        """
        self.logger.debug("Generating Gazebo experiment changes (all runs)")

        # Start Gazebo/ROS in debug mode to make post-mortem analysis easier.
        exp_def.tag_add("./master/include",
                        "arg",
                        {
                            "name": "verbose",
                            "value": "true"
                        })

        # Terminate Gazebo server whenever the launch script that invoked it
        # exits.
        exp_def.tag_add("./master/include",
                        "arg",
                        {
                            "name": "server_required",
                            "value": "true"
                        })

        # Don't record stuff
        exp_def.tag_remove("./master/include", "arg/[@name='headless']")
        exp_def.tag_remove("./master/include", "arg/[@name='recording']")

        # Don't start paused
        exp_def.tag_remove("./master/include", "arg/[@name='paused']")

        # Don't start gazebo under gdb
        exp_def.tag_remove("./master/include", "arg/[@name='debug']")