示例#1
0
def optimize_tolerance(target_label, reactionModel, rmg, reaction_system_index, error, orig_conv):
    """
    Increment the trial tolerance from a very low value until the introduced error is greater than the parameter threshold.
    """


    start = 1E-20
    incr = 10
    tolmax = 1

    tol = start
    trial = start
    while True:
        logging.info('Trial tolerance: {trial:.2E}'.format(**locals()))
        Xred = reduce_compute(trial, target_label, reactionModel, rmg, reaction_system_index)
        dev = np.abs((Xred - orig_conv) / orig_conv)
        logging.info('Deviation: {dev:.2f}'.format(**locals()))

        if dev > error or trial > tolmax:
            break

        tol = trial
        trial = trial * incr

    if tol == start:
        logging.error('Starting value for tolerance was too high...')

    return tol
示例#2
0
def optimize_tolerance(target_label, reactionModel, rmg, reaction_system_index,
                       error, orig_conv):
    """
    Increment the trial tolerance from a very low value until the introduced error is greater than the parameter threshold.
    """

    start = 1E-20
    incr = 10
    tolmax = 1

    tol = start
    trial = start
    while True:
        logging.info('Trial tolerance: {trial:.2E}'.format(**locals()))
        Xred = reduce_compute(trial, target_label, reactionModel, rmg,
                              reaction_system_index)
        dev = np.abs((Xred - orig_conv) / orig_conv)
        logging.info('Deviation: {dev:.2f}'.format(**locals()))

        if dev > error or trial > tolmax:
            break

        tol = trial
        trial = trial * incr

    if tol == start:
        logging.error('Starting value for tolerance was too high...')

    return tol
示例#3
0
文件: util.py 项目: Lyle-zhang/RMG-Py
def get(key):    
    """
    Searches for the shared variable to retrieve identified by the 
    parameter key.
    """

    try:
        data = shared.getConst(key)
        return data
    except KeyError, e:
        logging.error('An object with the key {} could not be found.'.format(key))
        raise e
示例#4
0
def get(key):
    """
    Searches for the shared variable to retrieve identified by the 
    parameter key.
    """

    try:
        data = shared.getConst(key)
        return data
    except KeyError, e:
        logging.error(
            'An object with the key {} could not be found.'.format(key))
        raise e
示例#5
0
def loadReductionInput(reductionFile):
    """
    Load an reduction job from the input file located at `reductionFile`
    """

    target = None
    tolerance = -1

    full_path = os.path.abspath(os.path.expandvars(reductionFile))
    try:
        f = open(full_path)
    except IOError, e:
        logging.error('The input file "{0}" could not be opened.'.format(full_path))
        logging.info('Check that the file exists and that you have read access.')
        raise e
示例#6
0
def loadReductionInput(reductionFile):
    """
    Load an reduction job from the input file located at `reductionFile`
    """

    target = None
    tolerance = -1

    full_path = os.path.abspath(os.path.expandvars(reductionFile))
    try:
        f = open(full_path)
    except IOError, e:
        logging.error(
            'The input file "{0}" could not be opened.'.format(full_path))
        logging.info(
            'Check that the file exists and that you have read access.')
        raise e
示例#7
0
def parallel(hosts_list, num_of_workers):
    # Get a list of resources to launch worker(s) on
    hosts = utils.getHosts(None, hosts_list)
    external_hostname = [utils.externalHostname(hosts)]
    # Launch SCOOP
    print(sys.executable)
    thisScoopApp = ScoopApp(
        hosts=hosts,
        n=num_of_workers,
        b=1,
        verbose=4,
        python_executable=[sys.executable],
        externalHostname=external_hostname[0],
        executable="toRun.py",
        arguments=None,
        tunnel=False,
        path="/home/martin/PycharmProjects/fineGrained/main/",
        debug=False,
        nice=None,
        env=utils.getEnv(),
        profile=None,
        pythonPath=None,
        prolog=None,
        backend='ZMQ')

    rootTaskExitCode = False
    interruptPreventer = threading.Thread(target=thisScoopApp.close)
    try:
        rootTaskExitCode = thisScoopApp.run()
    except Exception as e:
        logger.error('Error while launching SCOOP subprocesses:' + str(e))
        rootTaskExitCode = -1
    finally:
        # This should not be interrupted (ie. by a KeyboadInterrupt)
        # The only cross-platform way to do it I found was by using a thread.
        interruptPreventer.start()
        interruptPreventer.join()

    # Exit with the proper exit code
    if rootTaskExitCode:
        sys.exit(rootTaskExitCode)
示例#8
0
def launch(hosts_list, num_of_workers, path, executable):
    # Get a list of resources to launch worker(s) on
    hosts = utils.getHosts(None, hosts_list)
    external_hostname = [utils.externalHostname(hosts)]
    # Launch SCOOP
    app = ScoopApp(hosts=hosts,
                   n=num_of_workers,
                   b=1,
                   verbose=4,
                   python_executable=[sys.executable],
                   externalHostname=external_hostname[0],
                   executable=executable,
                   arguments=None,
                   tunnel=False,
                   path=path,
                   debug=False,
                   nice=None,
                   env=utils.getEnv(),
                   profile=None,
                   pythonPath=None,
                   prolog=None,
                   backend='ZMQ')

    interrupt_prevent = threading.Thread(target=app.close)
    try:
        root_task_exit_code = app.run()
    except Exception as e:
        logger.error('Error while launching SCOOP subprocesses:' + str(e))
        root_task_exit_code = -1
    finally:
        # This should not be interrupted (ie. by a KeyboadInterrupt)
        # The only cross-platform way to do it I found was by using a thread.
        interrupt_prevent.start()
        interrupt_prevent.join()

    # Exit with the proper exit code
    print("exit code " + str(root_task_exit_code))
    if root_task_exit_code:
        sys.exit(root_task_exit_code)
示例#9
0
import sys

#local imports

#global variables
reactions = None

try:
    from scoop import shared
    from scoop.futures import map as map_
    from scoop import logger as logging
    logging.setLevel(20)#10 : debug, 20: info
except ImportError:
    map_ = map
    import logging
    logging.error('Import Error!')

from rmgpy.chemkin import getSpeciesIdentifier, loadChemkinFile
from rmgpy.rmg.main import RMG
from rmgpy.solver.base import TerminationTime, TerminationConversion
from workerwrapper import WorkerWrapper
"""
Guidelines for input:

- Do not use the annotated chemkin file as input!
- 
"""

CLOSE_TO_ZERO = 1E-20

class ReductionReaction(object):
示例#10
0
import sys

#local imports

#global variables
reactions = None

try:
    from scoop import shared
    from scoop.futures import map as map_
    from scoop import logger as logging
    logging.setLevel(20)  #10 : debug, 20: info
except ImportError:
    map_ = map
    import logging
    logging.error('Import Error!')

from rmgpy.chemkin import getSpeciesIdentifier, loadChemkinFile
from rmgpy.rmg.main import RMG
from rmgpy.solver.base import TerminationTime, TerminationConversion
from workerwrapper import WorkerWrapper
"""
Guidelines for input:

- Do not use the annotated chemkin file as input!
- 
"""

CLOSE_TO_ZERO = 1E-20