def run(argv=None): # Initialize console = Console() console.init() programs = get_settings().get_programs() parser = _create_parser(programs) # Parse arguments (values, args) = parser.parse_args(argv) # Check inputs outputdir = values.outputdir if not os.path.exists(outputdir): console.print_error("The specified output directory (%s) does not exist" % outputdir) workdir = values.workdir if workdir is not None and not os.path.exists(workdir): console.print_error("The specified work directory (%s) does not exist" % workdir) if values.verbose: logging.getLogger().setLevel(logging.DEBUG) quiet = values.quiet nbprocesses = values.nbprocesses if nbprocesses <= 0: parser.error("Number of processes must be greater than 0.") overwrite = not values.skip aliases = dict(zip(map(attrgetter('alias'), programs), programs)) selected_aliases = [alias for alias in aliases if getattr(values, alias)] if not selected_aliases: console.print_error("Please select one Monte Carlo program") selected_programs = list(map(aliases.get, selected_aliases)) list_options = [] try: _load(args, list_options) except Exception as ex: console.print_error(str(ex)) if not list_options: console.print_error("Please specify at least one options file") # Setup runner = LocalRunner(outputdir, workdir, overwrite, nbprocesses) progressbar = ProgressBar(console) if not quiet: progressbar.start() # Start simulation with runner: for options in list_options: options.programs.update(selected_programs) runner.put(options) try: while runner.is_alive() and not runner.is_finished(): if not quiet: progressbar.update(runner.progress, runner.status) time.sleep(1) except Exception as ex: console.print_exception(ex) runner.close() if not quiet: progressbar.close() # Clean up console.close()
def run(argv=None): # Initialize console = Console() console.init() programs = get_settings().get_programs() parser = create_parser(programs) # Parse arguments (values, args) = parser.parse_args(argv) # Check inputs outputdir = values.outputdir if not os.path.exists(outputdir): console.print_error("The specified output directory (%s) does not exist" % outputdir) workdir = values.workdir if workdir is not None and not os.path.exists(workdir): console.print_error("The specified work directory (%s) does not exist" % workdir) if values.verbose: logging.getLogger().setLevel(logging.DEBUG) quiet = values.quiet nbprocesses = values.nbprocesses if nbprocesses <= 0: parser.error("Number of processes must be greater than 0.") overwrite = not values.skip max_iterations = values.max_iterations if max_iterations < 0: raise ValueError, 'Maximum number of iterations must be greater or equal to 0' convergence_limit = values.convergence_limit if convergence_limit <= 0.0: raise ValueError, 'Convergence limit must be greater than 0.0' if values.linear: iterator_class = SimpleIterator elif values.pouchou1991: iterator_class = Pouchou1991Iterator elif values.wegstein1958: iterator_class = Wegstein1958Iterator else: iterator_class = Heinrich1972Iterator if values.kratio: convergor_class = KRatioConvergor else: convergor_class = CompositionConvergor if values.fluorescence: calculator_class = FluorescenceCalculator else: calculator_class = SimpleCalculator aliases = map(attrgetter('alias'), programs) selected_programs = [alias for alias in aliases if getattr(values, alias)] if not selected_programs: console.print_error("Please select one Monte Carlo program") if len(selected_programs) > 1: console.print_error("Please select only one Monte Carlo program") selected_program = selected_programs[0] workers = dict(zip(aliases, map(attrgetter('worker'), programs))) worker_class = workers[selected_program] measurements = [] try: load_measurements(args, measurements) except Exception as ex: console.print_error(str(ex)) if not measurements: console.print_error("Please specify a measurement file") # Setup runner = Runner(worker_class, iterator_class, convergor_class, calculator_class, outputdir, workdir, overwrite, max_iterations, nbprocesses, limit=convergence_limit) progressbar = ProgressBar(console, len(measurements)) if not quiet: progressbar.start() runner.start() for measurement in measurements: runner.put(measurement) try: while runner.is_alive(): counter, progress, status = runner.report() if not quiet: progressbar.update(counter, progress, status) time.sleep(1) except Exception as ex: console.print_error('%s - %s' % (ex.__class__.__name__, str(ex))) runner.stop() if not quiet: progressbar.close() # Clean up console.close()
def run(argv=None): # Initialize console = Console() console.init() programs = get_settings().get_programs() parser = _create_parser(programs) # Parse arguments (values, args) = parser.parse_args(argv) # Check inputs outputdir = values.outputdir if not os.path.exists(outputdir): console.print_error( "The specified output directory (%s) does not exist" % outputdir) workdir = values.workdir if workdir is not None and not os.path.exists(workdir): console.print_error( "The specified work directory (%s) does not exist" % workdir) if values.verbose: logging.getLogger().setLevel(logging.DEBUG) quiet = values.quiet nbprocesses = values.nbprocesses if nbprocesses <= 0: parser.error("Number of processes must be greater than 0.") overwrite = not values.skip aliases = dict(zip(map(attrgetter('alias'), programs), programs)) selected_aliases = [alias for alias in aliases if getattr(values, alias)] if not selected_aliases: console.print_error("Please select one Monte Carlo program") selected_programs = list(map(aliases.get, selected_aliases)) list_options = [] try: _load(args, list_options) except Exception as ex: console.print_error(str(ex)) if not list_options: console.print_error("Please specify at least one options file") # Setup runner = LocalRunner(outputdir, workdir, overwrite, nbprocesses) progressbar = ProgressBar(console) if not quiet: progressbar.start() # Start simulation with runner: for options in list_options: options.programs.update(selected_programs) runner.put(options) try: while runner.is_alive() and not runner.is_finished(): if not quiet: progressbar.update(runner.progress, runner.status) time.sleep(1) except Exception as ex: console.print_exception(ex) runner.close() if not quiet: progressbar.close() # Clean up console.close()