Esempio n. 1
0
def run_refinement(projectf, mixture_index, options):
    """
        Runs a refinement setup for 
            - projectf: project data
            - mixture_index: what mixture in the project to use
            - options: refinement options
    """
    if projectf is not None:
        from pyxrd.data import settings
        settings.CACHE = None
        settings.apply_runtime_settings()

        from pyxrd.generic import pool
        pool.get_pool()

        from pyxrd.project.models import Project

        type(Project).object_pool.clear()
        project = Project.load_object(None, data=projectf)
        del projectf
        import gc
        gc.collect()

        mixture = project.mixtures[mixture_index]
        mixture.update_refinement_treestore()
        mixture.refiner.setup_context(store=False) # we already have a dumped project
        context = mixture.refiner.context
        context.options = options

        mixture.refiner.refine(stop=pool.pool_stop)

        return list(context.best_solution), context.best_residual, (context.record_header, context.records) #@UndefinedVariable
Esempio n. 2
0
 def submit_async_call(self, func):
     """ Utility that passes function calls either to SCOOP (if it's available)
     or down to a multiprocessing call."""
     from pyxrd.generic.pool import USING_SCOOP, get_pool
     pool = get_pool()
     if USING_SCOOP: # SCOOP
         result = pool.submit(func)
     elif pool is not None: # Regular multiprocessing pool
         result = pool.apply_async(func)
     else: # No parallelization:
         result = func()
     return result
Esempio n. 3
0
 def fetch_async_result(self, result):
     """ Utility that parses the result objects returned by submit_async_call"""
     from pyxrd.generic.pool import USING_SCOOP, get_pool
     pool = get_pool()
     if USING_SCOOP:  # SCOOP result object
         return result.result()
     elif pool is not None: # Multiprocessing pool result object
         async_get_fail_count = 0
         if self.__can_time_out:
             while True:
                 try:
                     return result.get(timeout=2)
                 except TimeoutError:
                     async_get_fail_count += 1
                     if async_get_fail_count > 50:
                         logging.error(
                             "AsyncResult.get() timed out 50 times" \
                             " after 2 seconds, something is blocking!")
                         if self.__async_get_raise_error:
                             raise
         else:
             return result.get()
     else: # No parallelization:
         return result
Esempio n. 4
0
#!/usr/bin/python

# coding=UTF-8
# ex:ts=4:sw=4:et=on

# Copyright (c) 2013, Mathijs Dumon
# All rights reserved.
# Complete license can be found in the LICENSE file.

if __name__ == "__main__":

    # Init settings, first import will trigger initialization
    from pyxrd.data import settings

    # Setup basic logging
    from pyxrd.logs import setup_logging
    setup_logging(basic=True)

    # This will generate a very slim pool of worker processes, with as little
    # as possible shared state
    from pyxrd.generic.pool import get_pool
    get_pool()

    # Setup & run PyXRD
    from pyxrd.core import run_main
    run_main()