Example #1
0
    def __call__(self, population, num_generations, num_evaluations, args):
        if self.progress is None:
            self.max_evaluations = args.get('max_evaluations', 50000)
            self.progress = ProgressBar(maxval=self.max_evaluations,
                                        widgets=["Running Optimization", Bar(), Percentage()])
            self.progress.start()

        if num_evaluations % args.get('n', 1) == 0:
            if num_evaluations > self.max_evaluations:
                self.progress.update(self.max_evaluations)
            else:
                self.progress.update(num_evaluations)
Example #2
0
class ProgressObserver(object):
    """
    Progress bar to in command line. It keeps track of the progress during heuristic optimization.
    """
    __name__ = "Progress Observer"

    def __init__(self):
        self.progress = None

    def __call__(self, population, num_generations, num_evaluations, args):
        if self.progress is None:
            self.max_evaluations = args.get('max_evaluations', 50000)
            self.progress = ProgressBar(maxval=self.max_evaluations,
                                        widgets=["Running Optimization", Bar(), Percentage()])
            self.progress.start()

        if num_evaluations % args.get('n', 1) == 0:
            if num_evaluations > self.max_evaluations:
                self.progress.update(self.max_evaluations)
            else:
                self.progress.update(num_evaluations)

    def reset(self):
        self.progress = None

    def end(self):
        self.progress.finish()
Example #3
0
class ProgressObserver(object):
    """
    Progress bar to in command line. It keeps track of the progress during heuristic optimization.
    """
    __name__ = "Progress Observer"

    def __init__(self):
        self.progress = None

    def __call__(self, population, num_generations, num_evaluations, args):
        if self.progress is None:
            self.max_evaluations = args.get('max_evaluations', 50000)
            self.progress = ProgressBar(maxval=self.max_evaluations,
                                        widgets=["Running Optimization", Bar(), Percentage()])
            self.progress.start()

        if num_evaluations % args.get('n', 1) == 0:
            if num_evaluations > self.max_evaluations:
                self.progress.update(self.max_evaluations)
            else:
                self.progress.update(num_evaluations)

    def reset(self):
        self.progress = None

    def end(self):
        self.progress.finish()
        self.progress = None
Example #4
0
    def _process_solutions(self):
        processed_solutions = DataFrame(columns=[
            "reactions", "size", "fva_min", "fva_max", "target_flux",
            "biomass_flux", "yield", "fitness"
        ])

        if len(self._swaps) == 0:
            logger.warn("No solutions found")
            self._processed_solutions = processed_solutions

        else:
            progress = ProgressBar(
                maxval=len(self._swaps),
                widgets=["Processing solutions: ",
                         Bar(), Percentage()])
            for i, solution in progress(enumerate(self._swaps)):
                try:
                    processed_solutions.loc[
                        i] = process_reaction_swap_solution(
                            self._model, solution[0], self._simulation_method,
                            self._simulation_kwargs, self._biomass,
                            self._target, self._substrate,
                            self._objective_function, self._swap_pairs)
                except OptimizationError as e:
                    logger.error(e)
                    processed_solutions.loc[i] = [
                        numpy.nan for _ in processed_solutions.columns
                    ]

            self._processed_solutions = processed_solutions
Example #5
0
    def _process_knockouts(self):
        progress = ProgressBar(
            maxval=len(self._knockouts),
            widgets=["Processing solutions: ",
                     Bar(), Percentage()])

        self._processed_knockouts = DataFrame(columns=[
            "reactions", "size", self._target, "biomass", "fva_min", "fva_max"
        ])

        for i, knockouts in progress(enumerate(self._knockouts)):
            try:
                with self._model:
                    [
                        self._model.reactions.get_by_id(ko).knock_out()
                        for ko in knockouts
                    ]
                    fva = flux_variability_analysis(self._model,
                                                    fraction_of_optimum=0.99,
                                                    reactions=[self.target])
                self._processed_knockouts.loc[i] = [
                    knockouts,
                    len(knockouts), self.production[i], self.biomass[i],
                    fva.lower_bound(self.target),
                    fva.upper_bound(self.target)
                ]
            except OptimizationError:
                self._processed_knockouts.loc[i] = [
                    numpy.nan for _ in self._processed_knockouts.columns
                ]
Example #6
0
    def _process_message(self, message):
        i = message['index']
        if i not in self.progress_bar:
            label = "Island %i" % (i + 1)
            self.progress_bar[i] = ProgressBar(maxval=message['max_evaluations'],
                                               widgets=[label, Bar(), Percentage()])
            self.progress_bar[message['index']].start()

        self.progress_bar[message['index']].set(message['progress'])
Example #7
0
    def __call__(self, population, num_generations, num_evaluations, args):
        if self.progress is None:
            self.max_evaluations = args.get('max_evaluations', 50000)
            self.progress = ProgressBar(maxval=self.max_evaluations,
                                        widgets=["Running Optimization", Bar(), Percentage()])
            self.progress.start()

        if num_evaluations % args.get('n', 1) == 0:
            if num_evaluations > self.max_evaluations:
                self.progress.update(self.max_evaluations)
            else:
                self.progress.update(num_evaluations)
Example #8
0
    def _process_message(self, message):
        i = message['index']
        if i not in self.progress_bar:
            print("")
            label = "Island %i: " % (i + 1)
            pos = abs(len(self.clients) - i)
            writer = self.TerminalWriter((self.terminal.height or 1) - pos, self.terminal)
            self.progress_bar[i] = ProgressBar(maxval=message['max_evaluations'],
                                               widgets=[label, Bar(), Percentage()],
                                               fd=writer)
            self.progress_bar[i].start()

        self.progress_bar[i].update(message['num_evaluations'])