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
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 ]
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'])
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 _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'])