Example #1
0
    def clarkson_algorithm(self, args={"file_suffix": "py"}, **kwargs):
        """Run the redundancy removal algorithm.

        The redundancy removal algorithm is run by writing the necessary data
        to disk with "_py" suffix, starting a julia instance and running the
        algorithm. After (successful) completion the resulting file with the
        non-redundant cbco indices is read and returned.

        Returns
        -------
        cbco : list
            List of the essential indices, i.e. the indices of the non-redundant
            cbco's.
        """

        self.write_cbco_info(self.julia_dir.joinpath("cbco_data"), "py",
                             **kwargs)

        if not self.julia_instance:
            self.julia_instance = tools.JuliaDaemon(self.logger, self.wdir,
                                                    self.package_dir,
                                                    "redundancy_removal")
        if not self.julia_instance.is_alive:
            self.julia_instance = tools.JuliaDaemon(self.logger, self.wdir,
                                                    self.package_dir,
                                                    "redundancy_removal")

        if self.options["optimization"]["type"] in ["zonal"]:
            self.julia_instance.disable_multi_threading()

        t_start = dt.datetime.now()
        self.logger.info("Start-Time: %s", t_start.strftime("%H:%M:%S"))

        self.julia_instance.run(args=args)

        t_end = dt.datetime.now()
        self.logger.info("End-Time: %s", t_end.strftime("%H:%M:%S"))
        self.logger.info("Total Time: %s",
                         str((t_end - t_start).total_seconds()) + " sec")

        if self.julia_instance.solved:
            file = tools.newest_file_folder(
                self.julia_dir.joinpath("cbco_data"), keyword="cbco")
            self.logger.info("cbco list save for later use to: \n%s",
                             file.stem + ".csv")
            cbco = list(pd.read_csv(file, delimiter=',').constraints.values)
        else:
            self.logger.critical("Error in Julia code")
            cbco = None
        return cbco
Example #2
0
    def run(self):
        """Run the julia Programm via command Line.

        Uses :class:`~pomato.tools.InteractiveJuliaProcess` from the attribite *julia_model* to
        run the market model. If the model is not initialized, it will be done here onece. The
        model run depends on the supplied options.
        In the case of successful completion, the resul folders are stores in the *result_folders*
        attribute for further processing thje in :class:`~pomato.data.ResultProcessing` module.

        """
        t_start = datetime.datetime.now()

        if not self.julia_model:
            self.julia_model = tools.JuliaDaemon(self.logger, self.wdir,
                                                 self.package_dir,
                                                 "market_model")

        self.logger.info("Start-Time: %s", t_start.strftime("%H:%M:%S"))

        args = {
            "redispatch": self.options["optimization"]["redispatch"]["include"]
        }
        self.julia_model.run(args=args)

        # self.julia_model.run(command)
        t_end = datetime.datetime.now()
        self.logger.info("End-Time: %s", t_end.strftime("%H:%M:%S"))
        self.logger.info("Total Time: %s",
                         str((t_end - t_start).total_seconds()) + " sec")

        if self.julia_model.solved:
            # find latest folders created in julia result folder
            # last for normal dispatch, least 2 for redispatch
            if self.options["optimization"]["redispatch"]["include"]:
                num_of_results = len(
                    self.options["optimization"]["redispatch"]["zones"]) + 1
                self.result_folders = tools.newest_file_folder(
                    self.data_dir.joinpath("results"),
                    number_of_elm=num_of_results)
            else:
                self.result_folders = [
                    tools.newest_file_folder(self.data_dir.joinpath("results"),
                                             number_of_elm=1)
                ]

            for folder in self.result_folders:
                with open(folder.joinpath("optionfile.json"), 'w') as file:
                    json.dump(self.options["optimization"], file, indent=2)

            self.status = 'solved'
        else:
            self.logger.warning("Process not terminated successfully!")
            self.status = 'error'
Example #3
0
    def run(self):
        """Run the julia program via command Line.

        Uses :class:`~pomato.tools.JuliaDaemon` that is initialized into the *julia_model* attribute
        to run the market model. The model run depends on the supplied options.
        In the case of successful completion, the result folders are stores in the *result_folders*
        attribute which will be instantiated as :class:`~pomato.data.Results` as part of the 
        DataManagement module.

        """
        t_start = datetime.datetime.now()

        if not self.julia_model:
            self.julia_model = tools.JuliaDaemon(self.logger, self.wdir, self.package_dir, "market_model")

        self.logger.info("Start-Time: %s", t_start.strftime("%H:%M:%S"))

        args = {"redispatch": self.options["optimization"]["redispatch"]["include"],
                "chance_constrained": self.options["optimization"]["chance_constrained"]["include"]}
        self.julia_model.run(args=args)
        t_end = datetime.datetime.now()
        self.logger.info("End-Time: %s", t_end.strftime("%H:%M:%S"))
        self.logger.info("Total Time: %s", str((t_end-t_start).total_seconds()) + " sec")

        if self.julia_model.solved:
            # find latest folders created in julia result folder
            # last for normal dispatch, least 2 for redispatch
            if self.options["optimization"]["redispatch"]["include"]:
                if self.options["optimization"]["redispatch"]["zonal_redispatch"]:
                    num_of_results = len(self.options["optimization"]["redispatch"]["zones"]) + 1
                else:
                    num_of_results = 2
                self.result_folders = tools.newest_file_folder(self.results_dir,
                                                               number_of_elm=num_of_results)
            else:
                self.result_folders = [tools.newest_file_folder(self.results_dir,
                                                                number_of_elm=1)]  

            for folder in self.result_folders:
                with open(folder.joinpath("optionfile.json"), 'w') as file:
                    json.dump(self.options["optimization"], file, indent=2)

            self.status = 'solved'
        else:
            self.logger.warning("Process not terminated successfully!")
            self.status = 'error'
Example #4
0
 def _start_julia_daemon(self):
     self.julia_instance = tools.JuliaDaemon(self.logger, self.wdir, self.package_dir, "redundancy_removal")
Example #5
0
 def _start_julia_daemon(self):
     """Start julia subprocess."""
     self.julia_model = tools.JuliaDaemon(self.logger, self.wdir, self.package_dir, "market_model")