def loadReductionInput(reductionFile): """ Load an reduction job from the input file located at `reductionFile` """ targets = 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
def loadReductionInput(reductionFile): """ Load an reduction job from the input file located at `reductionFile` """ targets = None tolerance = -1 full_path = os.path.abspath(os.path.expandvars(reductionFile)) try: f = open(full_path) except IOError: 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 logging.info('Reading input file "{0}"...'.format(full_path)) global_context = {'__builtins__': None} local_context = { '__builtins__': None, 'targets': targets, 'tolerance': tolerance } try: exec f in global_context, local_context targets = local_context['targets'] tolerance = local_context['tolerance'] except (NameError, TypeError, SyntaxError) as e: logging.error('The input file "{0}" was invalid:'.format(full_path)) logging.exception(e) raise finally: f.close() assert targets is not None assert tolerance != -1 return targets, tolerance
def loadReductionInput(reductionFile): """ Load an reduction job from the input file located at `reductionFile` """ targets = None tolerance = -1 full_path = os.path.abspath(os.path.expandvars(reductionFile)) try: f = open(full_path) except IOError: 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 logging.info('Reading input file "{0}"...'.format(full_path)) global_context = { '__builtins__': None } local_context = { '__builtins__': None, 'targets': targets, 'tolerance': tolerance } try: exec f in global_context, local_context targets = local_context['targets'] tolerance = local_context['tolerance'] except (NameError, TypeError, SyntaxError) as e: logging.error('The input file "{0}" was invalid:'.format(full_path)) logging.exception(e) raise finally: f.close() assert targets is not None assert tolerance != -1 return targets, tolerance
def bisect(low, high, error, targets, reactionModel, rmg, reactionSystemIndex, orig_observable): """ Bisect method in log space. Interrupt iterations when two consecutive, successful iterations differ less than a threshold value. """ THRESHOLD = 0.05 importantReactions = None final_devs = None old_trial = low while True: midpoint = (low + high) / 2.0 reduced_observable, newImportantReactions = evaluate(midpoint, targets, reactionModel, rmg, reactionSystemIndex) devs = computeDeviation(orig_observable, reduced_observable, targets) if isInvalid(devs, error): high = midpoint else: low = midpoint importantReactions = newImportantReactions final_devs = devs if np.abs((midpoint - old_trial) / old_trial) < THRESHOLD: break old_trial = low if not importantReactions: logging.error("Could not find a good guess...") importantReactions = [] logging.info('Final deviations: '.format()) for dev, target in zip(final_devs, targets): logging.info('Final deviation for {}: {:.2f}%'.format(target, dev * 100)) return low, importantReactions
def bisect(low, high, error, targets, reactionModel, rmg, reactionSystemIndex, orig_observable): """ Bisect method in log space. Interrupt iterations when two consecutive, successful iterations differ less than a threshold value. """ THRESHOLD = 0.05 importantReactions = None final_devs = None old_trial = low while True: midpoint = (low + high) / 2.0 reduced_observable, newImportantReactions = evaluate( midpoint, targets, reactionModel, rmg, reactionSystemIndex) devs = computeDeviation(orig_observable, reduced_observable, targets) if isInvalid(devs, error): high = midpoint else: if len(newImportantReactions) == 0: logging.error( 'Model reduction resulted in a model with 0 reactions.') logging.error( 'Perhaps change reactor conditions to allow for more adequate reduction. Exiting...' ) break low = midpoint importantReactions = newImportantReactions final_devs = devs writeModel(rmg, chemkin_name='chem_reduced_{}.inp'.format( len(importantReactions))) if np.abs((midpoint - old_trial) / old_trial) < THRESHOLD: break old_trial = low if not importantReactions: logging.error("Could not find a good guess...") importantReactions = [] logging.info('Final deviations: '.format()) for dev, target in zip(final_devs, targets): logging.info('Final deviation for {}: {:.2f}%'.format( target, dev * 100)) return low, importantReactions
def bisect(low, high, error, targets, reactionModel, rmg, reactionSystemIndex, orig_observable): """ Bisect method in log space. Interrupt iterations when two consecutive, successful iterations differ less than a threshold value. """ THRESHOLD = 0.05 importantReactions = None final_devs = None old_trial = low while True: midpoint = (low + high) / 2.0 reduced_observable, newImportantReactions = evaluate(midpoint, targets, reactionModel, rmg, reactionSystemIndex) devs = computeDeviation(orig_observable, reduced_observable, targets) if isInvalid(devs, error): high = midpoint else: if len(newImportantReactions) == 0: logging.error('Model reduction resulted in a model with 0 reactions.') logging.error('Perhaps change reactor conditions to allow for more adequate reduction. Exiting...') break low = midpoint importantReactions = newImportantReactions final_devs = devs writeModel(rmg, chemkin_name='chem_reduced_{}.inp'.format(len(importantReactions))) if np.abs((midpoint - old_trial) / old_trial) < THRESHOLD: break old_trial = low if not importantReactions: logging.error("Could not find a good guess...") importantReactions = [] logging.info('Final deviations: '.format()) for dev, target in zip(final_devs, targets): logging.info('Final deviation for {}: {:.2f}%'.format(target, dev * 100)) return low, importantReactions
global_context = {'__builtins__': None} local_context = { '__builtins__': None, 'targets': targets, 'tolerance': tolerance } try: exec f in global_context, local_context targets = local_context['targets'] tolerance = local_context['tolerance'] except (NameError, TypeError, SyntaxError), e: logging.error('The input file "{0}" was invalid:'.format(full_path)) logging.exception(e) raise finally: f.close() assert targets is not None assert tolerance != -1 return targets, tolerance def load(rmgInputFile, reductionFile, chemkinFile, speciesDict): rmg = loadRMGPyJob(rmgInputFile, chemkinFile,
global_context = { '__builtins__': None } local_context = { '__builtins__': None, 'targets': targets, 'tolerance': tolerance } try: exec f in global_context, local_context targets = local_context['targets'] tolerance = local_context['tolerance'] except (NameError, TypeError, SyntaxError), e: logging.error('The input file "{0}" was invalid:'.format(full_path)) logging.exception(e) raise finally: f.close() assert targets is not None assert tolerance != -1 return targets, tolerance def load(rmgInputFile, reductionFile, chemkinFile, speciesDict): rmg = loadRMGPyJob(rmgInputFile, chemkinFile, speciesDict, generateImages=False, useChemkinNames=True) targets, tolerance = loadReductionInput(reductionFile)