Esempio n. 1
0
    def __compile(self):
        # Use makefile.
        if self.resume:
            if self.resume[0].model != self.model:
                raise gillespyError.ModelError(
                    'When resuming, one must not alter the model being resumed.'
                )
            else:
                built = subprocess.run(
                    ["make", "-C", self.output_directory, 'UserSimulation'],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
        else:
            try:
                cleaned = subprocess.run(
                    ["make", "-C", self.output_directory, 'cleanSimulation'],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
                built = subprocess.run(
                    ["make", "-C", self.output_directory, 'UserSimulation'],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
            except KeyboardInterrupt:
                log.warning(
                    "Solver has been interrupted during compile time, unexpected behavior may occur."
                )

        if built.returncode == 0:
            self.__compiled = True
        else:
            raise gillespyError.BuildError(
                "Error encountered while compiling file:\nReturn code: "
                "{0}.\nError:\n{1}\n{2}\n".format(
                    built.returncode, built.stdout.decode('utf-8'),
                    built.stderr.decode('utf-8')))
Esempio n. 2
0
    def build_simulation(self,
                         simulation_name: "str",
                         definitions: "dict[str, str]" = None) -> str:
        """
        Build the solver to the temp directory.

        :param simulation_name: The name of the simulation to build. For example, ODESimulation.
        :type simulation_name: str

        :param definitions: Dictionary of environment variables to be overriden when the Makefile is invoked.
        Intended for use when running through a debugger environment or profiler.
        :type definitions: dict[str, str]

        :return: The path of the newly build solver executable.
        """
        if definitions is None:
            definitions = {}

        if self.make is None:
            raise gillespyError.BuildError(
                "Failed to build the simulation. The build environment has not yet been prepared.\n"
                "To fix, call `BuildEngine.prepare()` prior to attempting to build the simulation."
            )

        self.make.build_simulation(simulation_name,
                                   template_dir=str(self.template_dir),
                                   **definitions)
        return str(self.make.output_file)
Esempio n. 3
0
    def __execute(self, target: str, **kwargs):        
        # Default make arguments.
        args_dict = {
            "cbase_dir": str(self.cbase_dir.resolve()),
            "obj_dir": str(self.obj_dir.resolve()),
            "output_dir": str(self.output_dir.resolve()),
            "output_file": str(self.output_dir.joinpath(self.output_file).resolve())
        }

        # Overwrite keys supplied in **kwargs.
        for key, value in kwargs.items():
            args_dict[key] = value

        # Create the emake arguments. Note, arguments are UPPERCASE.
        make_args = [(f"{key.upper()}={value}") for key, value in args_dict.items()]

        # Create the make command.
        make_cmd = ["make", "-C", str(self.cbase_dir), "-f", str(self.makefile), target] + make_args

        try:
            result = subprocess.run(make_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        except KeyboardInterrupt:
            log.warning(f"Makefile was interrupted during execution of target: '{target}', unexpected behavior may occur.")

        if result.returncode == 0:
            return

        raise gillespyError.BuildError(f"Error encountered during execution of Makefile target: '{target}'.\n"
            f"Return code: {result.returncode}"
            f"- stdout: {result.stdout.decode('utf-8', errors='ignore')}\n"
            f"- stderr: {result.stderr.decode('utf-8', errors='ignore')}\n"
            f"- make_cmd: {make_cmd}\n"
            f"- os.listdir({os.path.join(self.cbase_dir,'template')}): {os.listdir(os.path.join(self.cbase_dir,'template'))}\n")
Esempio n. 4
0
 def compile(self):
     # Use makefile.
     cleaned = subprocess.run(
         ["make", "-C", self.output_directory, 'cleanSimulation'],
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE)
     built = subprocess.run(
         ["make", "-C", self.output_directory, 'UserSimulation'],
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE)
     if built.returncode == 0:
         self.compiled = True
     else:
         raise gillespyError.BuildError(
             "Error encountered while compiling file:\nReturn code: {0}.\nError:\n{1}\n"
             .format(built.returncode, built.stderr))