Skip to content

Commit d976b85

Browse files
rwestmjohnson541
authored andcommitted
Fix format specifier when logging species pruning.
Hopefully this closes #2043 The Species class doesn't have an ability to interpret a format specifier "<56" (although the Species.label would, because it's a string. Anyway, while fixing that I also changed some other logging.debug() statements over to the old-fashioned format syntax and left the formatting to the logging module. This way, it formats the string "lazily", and if you're not running in verbose mode (i.e. the debug messages aren't going to be printed anyway) then it doesn't bother doing the formatting. Might save a few nanoseconds :-) Because we almost always run with logging.info() showing, I left those alone.
1 parent ca2f663 commit d976b85

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

rmgpy/rmg/model.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def make_new_species(self, object, label='', reactive=True, check_existing=True,
304304
# This may change later after getting thermo in self.generate_thermo()
305305
if not spec.label:
306306
spec.label = spec.smiles
307-
logging.debug('Creating new species {0}'.format(spec.label))
307+
logging.debug('Creating new species %s', spec.label)
308308

309309
formula = molecule.get_formula()
310310
if formula in self.species_dict:
@@ -452,11 +452,11 @@ def make_new_reaction(self, forward, check_existing=True, generate_thermo=True):
452452

453453
# Note in the log
454454
if isinstance(forward, TemplateReaction):
455-
logging.debug('Creating new {0} template reaction {1}'.format(forward.family, forward))
455+
logging.debug('Creating new %s template reaction %s', forward.family, forward)
456456
elif isinstance(forward, DepositoryReaction):
457-
logging.debug('Creating new {0} reaction {1}'.format(forward.get_source(), forward))
457+
logging.debug('Creating new %s reaction %s', forward.get_source(), forward)
458458
elif isinstance(forward, LibraryReaction):
459-
logging.debug('Creating new library reaction {0}'.format(forward))
459+
logging.debug('Creating new library reaction %s', forward)
460460
else:
461461
raise Exception("Unrecognized reaction type {0!s}".format(forward.__class__))
462462

@@ -1044,7 +1044,7 @@ def add_species_to_core(self, spec):
10441044
if spec in self.edge.species:
10451045

10461046
# If species was in edge, remove it
1047-
logging.debug("Removing species {0} from edge.".format(spec))
1047+
logging.debug("Removing species %s from edge.", spec)
10481048
self.edge.species.remove(spec)
10491049

10501050
# Search edge for reactions that now contain only core species;
@@ -1063,7 +1063,7 @@ def add_species_to_core(self, spec):
10631063
# Move any identified reactions to the core
10641064
for rxn in rxn_list:
10651065
self.add_reaction_to_core(rxn)
1066-
logging.debug("Moving reaction from edge to core: {0}".format(rxn))
1066+
logging.debug("Moving reaction from edge to core: %s", rxn)
10671067
return rxn_list
10681068

10691069
def add_species_to_edge(self, spec):
@@ -1123,7 +1123,7 @@ def thermo_filter_down(self, maximum_edge_species, min_species_exist_iterations_
11231123
"""
11241124
Tmax = self.Tmax
11251125
num_to_remove = len(self.edge.species) - maximum_edge_species
1126-
logging.debug('Planning to remove {0} species'.format(num_to_remove))
1126+
logging.debug('Planning to remove %d species', num_to_remove)
11271127
iteration = self.iteration_num
11281128

11291129
if num_to_remove > 0: # implies flux pruning is off or did not trigger
@@ -1149,7 +1149,7 @@ def thermo_filter_down(self, maximum_edge_species, min_species_exist_iterations_
11491149
num_to_remove -= 1
11501150
ind += 1
11511151

1152-
logging.debug('found {0} eligible species for filtering'.format(len(remove_spcs)))
1152+
logging.debug('Found %d eligible species for filtering', len(remove_spcs))
11531153

11541154
for i, spc in enumerate(remove_spcs):
11551155
logging.info('Removing species {0} from edge to meet maximum number of edge species, Gibbs '
@@ -1176,7 +1176,7 @@ def remove_empty_pdep_networks(self):
11761176
if len(networks_to_delete) > 0:
11771177
logging.info('Deleting {0:d} empty pressure-dependent reaction networks'.format(len(networks_to_delete)))
11781178
for network in networks_to_delete:
1179-
logging.debug(' Deleting empty pressure dependent reaction network #{0:d}'.format(network.index))
1179+
logging.debug(' Deleting empty pressure dependent reaction network #%d', network.index)
11801180
source = tuple(network.source)
11811181
nets_with_this_source = self.network_dict[source]
11821182
nets_with_this_source.remove(network)
@@ -1255,17 +1255,18 @@ def prune(self, reaction_systems, tol_keep_in_edge, tol_move_to_core, maximum_ed
12551255

12561256
# Actually do the pruning
12571257
if prune_due_to_rate_counter > 0:
1258-
logging.info('Pruning {0:d} species whose rate ratios against characteristic rate did not exceed the '
1259-
'minimum threshold of {1:g}'.format(prune_due_to_rate_counter, tol_keep_in_edge))
1258+
logging.info('Pruning %d species whose rate ratios against characteristic rate did not exceed the '
1259+
'minimum threshold of %g', prune_due_to_rate_counter, tol_keep_in_edge)
12601260
for index, spec in species_to_prune[0:prune_due_to_rate_counter]:
1261-
logging.info('Pruning species {0:<56}'.format(spec))
1262-
logging.debug(' {0:<56} {1:10.4e}'.format(spec, max_edge_species_rate_ratios[index]))
1261+
logging.info('Pruning species %s', spec)
1262+
logging.debug(' %-56s %10.4e', spec, max_edge_species_rate_ratios[index])
12631263
self.remove_species_from_edge(reaction_systems, spec)
12641264
if len(species_to_prune) - prune_due_to_rate_counter > 0:
1265-
logging.info('Pruning {0:d} species to obtain an edge size of {1:d} species'.format(len(species_to_prune) - prune_due_to_rate_counter, maximum_edge_species))
1265+
logging.info('Pruning %d species to obtain an edge size of %d species',
1266+
len(species_to_prune) - prune_due_to_rate_counter, maximum_edge_species)
12661267
for index, spec in species_to_prune[prune_due_to_rate_counter:]:
1267-
logging.info('Pruning species {0:<56}'.format(spec))
1268-
logging.debug(' {0:<56} {1:10.4e}'.format(spec, max_edge_species_rate_ratios[index]))
1268+
logging.info('Pruning species %s', spec)
1269+
logging.debug(' %-56s %10.4e', spec, max_edge_species_rate_ratios[index])
12691270
self.remove_species_from_edge(reaction_systems, spec)
12701271

12711272
# Delete any networks that became empty as a result of pruning

0 commit comments

Comments
 (0)