def run(self):
reaction = self._get_objective()<EOL>if not self._mm.has_reaction(reaction):<EOL><INDENT>self.fail('<STR_LIT>'.format(<EOL>reaction))<EOL><DEDENT>varying_reaction = self._args.varying<EOL>if not self._mm.has_reaction(varying_reaction):<EOL><INDENT>self.fail('<STR_LIT>'.format(<EOL>varying_reaction))<EOL><DEDENT>steps = self._args.steps<EOL>if steps <= <NUM_LIT:0>:<EOL><INDENT>self.argument_error('<STR_LIT>'.format(steps))<EOL><DEDENT>loop_removal = self._get_loop_removal_option()<EOL>if loop_removal == '<STR_LIT>':<EOL><INDENT>solver = self._get_solver(integer=True)<EOL><DEDENT>else:<EOL><INDENT>solver = self._get_solver()<EOL><DEDENT>p = fluxanalysis.FluxBalanceProblem(self._mm, solver)<EOL>if loop_removal == '<STR_LIT>':<EOL><INDENT>p.add_thermodynamic()<EOL><DEDENT>try:<EOL><INDENT>p.check_constraints()<EOL><DEDENT>except fluxanalysis.FluxBalanceError as e:<EOL><INDENT>self.report_flux_balance_error(e)<EOL><DEDENT>if self._args.maximum is None:<EOL><INDENT>p.maximize(varying_reaction)<EOL>flux_max = p.get_flux(varying_reaction)<EOL><DEDENT>else:<EOL><INDENT>flux_max = self._args.maximum<EOL><DEDENT>if self._args.minimum is None:<EOL><INDENT>p.maximize({varying_reaction: -<NUM_LIT:1>})<EOL>flux_min = p.get_flux(varying_reaction)<EOL><DEDENT>else:<EOL><INDENT>flux_min = self._args.minimum<EOL><DEDENT>if flux_min > flux_max:<EOL><INDENT>self.argument_error('<STR_LIT>'.format(<EOL>flux_min, flux_max))<EOL><DEDENT>logger.info('<STR_LIT>'.format(<EOL>varying_reaction, steps, flux_min, flux_max))<EOL>start_time = time.time()<EOL>handler_args = (<EOL>self._mm, solver, loop_removal, self._args.all_reaction_fluxes)<EOL>executor = self._create_executor(<EOL>RobustnessTaskHandler, handler_args, cpus_per_worker=<NUM_LIT:2>)<EOL>def iter_tasks():<EOL><INDENT>for i in range(steps):<EOL><INDENT>fixed_flux = flux_min + i*(flux_max - flux_min)/float(steps-<NUM_LIT:1>)<EOL>constraint = varying_reaction, fixed_flux<EOL>yield constraint, reaction<EOL><DEDENT><DEDENT>with executor:<EOL><INDENT>for task, result in executor.imap_unordered(iter_tasks(), <NUM_LIT:16>):<EOL><INDENT>(varying_reaction, fixed_flux), _ = task<EOL>if result is None:<EOL><INDENT>logger.warning('<STR_LIT>'.format(<EOL>varying_reaction, fixed_flux))<EOL><DEDENT>elif self._args.all_reaction_fluxes:<EOL><INDENT>for other_reaction in self._mm.reactions:<EOL><INDENT>print('<STR_LIT>'.format(<EOL>other_reaction, fixed_flux,<EOL>result[other_reaction]))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>print('<STR_LIT>'.format(fixed_flux, result))<EOL><DEDENT><DEDENT><DEDENT>executor.join()<EOL>logger.info('<STR_LIT>'.format(<EOL>time.time() - start_time))<EOL>
Run robustness command.