Skip to content

Commit

Permalink
Merge pull request #102 from ReactionMechanismGenerator/0diverr
Browse files Browse the repository at this point in the history
Don't crush if RMG's reaction_system.simulate() fails
  • Loading branch information
alongd authored Feb 6, 2023
2 parents 32e128d + 3cf5287 commit 486aecc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
16 changes: 11 additions & 5 deletions t3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@
from rmgpy.species import Species
from rmgpy.thermo import NASAPolynomial, NASA, ThermoData, Wilhoit

from arc.common import get_ordinal_indicator, key_by_val, read_yaml_file, save_yaml_file
from arc.common import (get_number_with_ordinal_indicator,
get_ordinal_indicator,
key_by_val,
read_yaml_file,
save_yaml_file,
)
from arc.exceptions import ConverterError
from arc.main import ARC
from arc.species.species import ARCSpecies, check_label
Expand Down Expand Up @@ -637,13 +642,14 @@ def run_rmg(self):
if rmg_exception_encountered:
self.rmg_exceptions_counter += 1
if self.rmg_exceptions_counter > max_rmg_exceptions_allowed:
self.logger.error(f'This is the {self.rmg_exceptions_counter} exception raised by RMG.\n'
f'Cannot allow more than {max_rmg_exceptions_allowed} RMG exceptions during a T3 run.\n'
f'Not allowing additional exceptions, terminating.')
self.logger.error(f'This is the {get_number_with_ordinal_indicator(self.rmg_exceptions_counter)} '
f'exception raised by RMG.\nCannot allow more than {max_rmg_exceptions_allowed} '
f'RMG exceptions during a T3 run.\nNot allowing additional exceptions, terminating.')
raise ValueError('Terminating due to RMG exceptions.')
else:
self.logger.warning(f'RMG did not converge. '
f'This is the {self.rmg_exceptions_counter} exception raised by RMG.\n'
f'This is the {get_number_with_ordinal_indicator(self.rmg_exceptions_counter)} '
f'exception raised by RMG.\n'
f'The maximum number of exceptions allowed is {max_rmg_exceptions_allowed}.')

elapsed_time = time_lapse(tic)
Expand Down
33 changes: 18 additions & 15 deletions t3/simulate/rmg_constantTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,24 @@ def simulate(self):
if reaction_system.const_spc_names is not None:
reaction_system.get_const_spc_indices(self.rmg_model.reaction_model.core.species)

reaction_system.simulate(
core_species=self.rmg_model.reaction_model.core.species,
core_reactions=self.rmg_model.reaction_model.core.reactions,
edge_species=self.rmg_model.reaction_model.edge.species,
edge_reactions=self.rmg_model.reaction_model.edge.reactions,
surface_species=[],
surface_reactions=[],
pdep_networks=pdep_networks,
sensitivity=True if reaction_system.sensitive_species else False,
sens_worksheet=sens_worksheet,
model_settings=model_settings,
simulator_settings=simulator_settings,
conditions={'T': reaction_system.sens_conditions['T'], 'P': reaction_system.sens_conditions['P']},
prune=False,
)
try:
reaction_system.simulate(
core_species=self.rmg_model.reaction_model.core.species,
core_reactions=self.rmg_model.reaction_model.core.reactions,
edge_species=self.rmg_model.reaction_model.edge.species,
edge_reactions=self.rmg_model.reaction_model.edge.reactions,
surface_species=[],
surface_reactions=[],
pdep_networks=pdep_networks,
sensitivity=True if reaction_system.sensitive_species else False,
sens_worksheet=sens_worksheet,
model_settings=model_settings,
simulator_settings=simulator_settings,
conditions={'T': reaction_system.sens_conditions['T'], 'P': reaction_system.sens_conditions['P']},
prune=False,
)
except ZeroDivisionError as e:
self.logger.warning(f'Cannot simulate reaction system, got:\n{e}')

if reaction_system.sensitive_species:
plot_sensitivity(self.rmg_model.output_directory, index, reaction_system.sensitive_species)
Expand Down

0 comments on commit 486aecc

Please sign in to comment.