示例#1
0
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()
示例#2
0
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()
示例#3
0
def run(argv=None):
    # Initialize
    console = Console()
    console.init()

    console.print_message("Configuration of pyMonteCarlo")
    console.print_line()

    # Find settings.cfg
    settings = get_settings()

    # Programs
    programs = []

    for program_alias in settings.get_available_program_aliases():
        default = program_alias in settings.get_program_aliases()
        answer = \
            console.prompt_boolean("Do you want to setup %s?" % program_alias, default)
        if answer:
            cli = settings.get_program_cli(program_alias)
            try:
                pass
            except Exception as ex:
                console.print_exception(ex)
                return

            cli.configure(console, settings)

            programs.append(program_alias)
        else:
            if program_alias in settings:
                delattr(settings, program_alias)

        console.print_line()

    settings.pymontecarlo.programs = ','.join(programs)

    # Save
    settings.write()
    console.print_success("Settings saved")

    # Finalize
    console.close()
示例#4
0
def run(argv=None):
    # Initialise programs
    get_settings().get_programs()

    # Initialise console
    console = Console()
    console.init()

    # Create parser
    usage = "%prog [options] [OPTION_FILE.xml or RESULTS_FILE.zip or RESULTS_FILE.h5 ...]"
    description = "pyMonteCarlo update tool. This script updates old version " + \
                  "of options or results file to the newer one."
    epilog = "For more information, see http://pymontecarlo.bitbucket.org"

    parser = OptionParser(usage=usage, description=description, epilog=epilog)

    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      default=False,
                      action='store_true',
                      help='Debug mode')

    # Parse arguments
    (values, args) = parser.parse_args(argv)

    if values.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    if not args:
        console.print_error('Please specify at least one file')

    for filepath in args:
        if not os.path.exists(filepath):
            console.print_error('File %s does not exists' % filepath)

        ext = os.path.splitext(filepath)[1]

        if ext == '.xml':
            console.print_info("Updating options %s" % filepath)
            filepath = OptionsUpdater().update(filepath)
            console.print_success("Successfully updated %s" % filepath)
        elif ext == '.zip' or ext == '.h5':
            console.print_info("Updating results %s" % filepath)
            filepath = ResultsUpdater().update(filepath)
            console.print_success("Successfully results %s" % filepath)
        else:
            console.print_error('Unknown extension %s' % ext)

    console.close()
示例#5
0
def run(argv=None):
    # Initialise programs
    get_settings().get_programs()

    # Initialise console
    console = Console()
    console.init()

    # Create parser
    usage = "%prog [options] [OPTION_FILE.xml or RESULTS_FILE.zip or RESULTS_FILE.h5 ...]"
    description = "pyMonteCarlo update tool. This script updates old version " + \
                  "of options or results file to the newer one."
    epilog = "For more information, see http://pymontecarlo.bitbucket.org"

    parser = OptionParser(usage=usage, description=description, epilog=epilog)

    parser.add_option('-v', '--verbose', dest='verbose', default=False,
                      action='store_true', help='Debug mode')

    # Parse arguments
    (values, args) = parser.parse_args(argv)

    if values.verbose:
        logging.getLogger().setLevel(logging.DEBUG)

    if not args:
        console.print_error('Please specify at least one file')

    for filepath in args:
        if not os.path.exists(filepath):
            console.print_error('File %s does not exists' % filepath)

        ext = os.path.splitext(filepath)[1]

        if ext == '.xml':
            console.print_info("Updating options %s" % filepath)
            filepath = OptionsUpdater().update(filepath)
            console.print_success("Successfully updated %s" % filepath)
        elif ext == '.zip' or ext == '.h5':
            console.print_info("Updating results %s" % filepath)
            filepath = ResultsUpdater().update(filepath)
            console.print_success("Successfully results %s" % filepath)
        else:
            console.print_error('Unknown extension %s' % ext)

    console.close()
示例#6
0
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()