diff --git a/Sequential_WC_Simulator/core/SimulationEngine.py b/Sequential_WC_Simulator/core/SimulationEngine.py index 5547a6f2..026a731f 100644 --- a/Sequential_WC_Simulator/core/SimulationEngine.py +++ b/Sequential_WC_Simulator/core/SimulationEngine.py @@ -107,11 +107,11 @@ def message_queues( ): def print_simulation_state( ): logger.debug( ' ' + '\t'.join( ['Sender', 'Message types sent'] ) ) - for sender in MessageTypesRegistry.senders.keys(): + for sender in MessageTypesRegistry.senders: logger.debug( ' ' + sender + '\t' + ', '.join( MessageTypesRegistry.senders[sender] ) ) logger.debug( ' ' + '\t'.join( ['Receiver', 'Message types by priority'] ) ) - for receiver in MessageTypesRegistry.receiver_priorities.keys(): + for receiver in MessageTypesRegistry.receiver_priorities: logger.debug( ' ' + sender + '\t' + ', '.join( MessageTypesRegistry.receiver_priorities[receiver] ) ) @staticmethod diff --git a/Sequential_WC_Simulator/multialgorithm/CellState.py b/Sequential_WC_Simulator/multialgorithm/CellState.py index b8fd198b..e3b6ed27 100644 --- a/Sequential_WC_Simulator/multialgorithm/CellState.py +++ b/Sequential_WC_Simulator/multialgorithm/CellState.py @@ -85,7 +85,7 @@ def __init__( self, name, initial_population, initial_fluxes=None, self.population = {} try: - for specie_name in initial_population.keys(): + for specie_name in initial_population: initial_flux_given = None if initial_fluxes is not None and specie_name in initial_fluxes: initial_flux_given = initial_fluxes[specie_name] @@ -112,7 +112,7 @@ def __init__( self, name, initial_population, initial_fluxes=None, my_level = logging.NOTSET if log: my_level = logging.DEBUG - for specie_name in initial_population.keys(): + for specie_name in initial_population: setup_logger(specie_name, level=my_level ) log = logging.getLogger(specie_name) # write log header @@ -151,7 +151,7 @@ def handle_event( self, event_list ): logging.getLogger( self.logger_name ).debug( "ADJUST_POPULATION_BY_DISCRETE_MODEL: {}".format( str(population_changes) ) ) - for specie_name in population_changes.population_change.keys(): + for specie_name in population_changes.population_change: if not specie_name in self.population: self.population[specie_name] = Specie( specie_name, 0 ) @@ -166,7 +166,7 @@ def handle_event( self, event_list ): logging.getLogger( self.logger_name ).debug( "ADJUST_POPULATION_BY_CONTINUOUS_MODEL: {}".format( str(population_changes) ) ) - for specie_name in population_changes.population_change.keys(): + for specie_name in population_changes.population_change: # raise exeception if an ADJUST_POPULATION_BY_CONTINUOUS_MODEL event acts on a # non-existent species because the species has no flux, and we don't want a default flux if not specie_name in self.population: diff --git a/Sequential_WC_Simulator/multialgorithm/shared_cell_state.py b/Sequential_WC_Simulator/multialgorithm/shared_cell_state.py index 94b51e06..02374eb9 100644 --- a/Sequential_WC_Simulator/multialgorithm/shared_cell_state.py +++ b/Sequential_WC_Simulator/multialgorithm/shared_cell_state.py @@ -72,10 +72,10 @@ def __init__( self, name, initial_population, initial_fluxes=None, retain_histor try: if initial_fluxes is not None: - for specie_id in initial_population.keys(): + for specie_id in initial_population: self.init_cell_state_specie( specie_id, initial_population[specie_id], initial_fluxes[specie_id] ) else: - for specie_id in initial_population.keys(): + for specie_id in initial_population: self.init_cell_state_specie( specie_id, initial_population[specie_id] ) except AssertionError as e: sys.stderr.write( "Cannot initialize SharedMemoryCellState: {}.\n".format( e.message ) ) @@ -100,7 +100,7 @@ def __init__( self, name, initial_population, initial_fluxes=None, retain_histor my_level = logging.NOTSET if log: my_level = logging.DEBUG - for specie_name in initial_population.keys(): + for specie_name in initial_population: setup_logger(specie_name, level=my_level ) log = logging.getLogger(specie_name) # write log header @@ -183,7 +183,7 @@ def history_debug(self): print("{}\t{}\t{}".format( len(self.history['time']), self.history['time'][0], self.history['time'][-1] )) print("Specie\t#values\tfirst\tlast") - for s in self.history['population'].keys(): + for s in self.history['population']: print("{}\t{}\t{}\t{}".format( s, len(self.history['population'][s]), self.history['population'][s][0], self.history['population'][s][-1] )) else: @@ -213,7 +213,7 @@ def __check_access_time( self, time, species ): ValueError: if specie in species is being accessed at a time earlier than a prior access """ early_accesses = filter( lambda s: time < self.last_access_time[s], species) - if early_accesses: + if any(early_accesses): raise ValueError( "Error: earlier access of specie(s): {}".format( early_accesses )) def __update_access_times( self, time, species ): @@ -252,9 +252,9 @@ def adjust_discretely( self, time, adjustments ): ValueError: adjustment attempts to change the population of an unknown species ValueError: if population goes negative """ - self._check_species( time, adjustments.keys() ) + self._check_species( time, list( adjustments.keys() ) ) self.time = time - for specie in adjustments.keys(): + for specie in adjustments: try: self.population[specie].discrete_adjustment( adjustments[specie] ) self.__update_access_times( time, [specie] ) @@ -274,7 +274,7 @@ def adjust_continuously( self, time, adjustments ): ValueError: adjustment attempts to change the population of a non-existent species ValueError: if population goes negative """ - self._check_species( time, adjustments.keys() ) + self._check_species( time, list( adjustments.keys() ) ) self.time = time # record simulation state history diff --git a/tests/test_CellStateMultiObj.py b/tests/test_CellStateMultiObj.py index 452c47fb..96024601 100644 --- a/tests/test_CellStateMultiObj.py +++ b/tests/test_CellStateMultiObj.py @@ -141,7 +141,7 @@ def testSimulation( self ): ) # GET_POPULATION - for time in pop_history_dict['get_pop'].keys(): + for time in pop_history_dict['get_pop']: TestSimObj.send_event( time, cs1, GET_POPULATION, event_body=GET_POPULATION.body( set(['x']) ) ) @@ -170,7 +170,7 @@ def testSimulationDefaultPopulation( self ): event_body=ADJUST_POPULATION_BY_DISCRETE_MODEL.body( { specie:Pop_adjust } ) ) # GET_POPULATION - for time in pop_history_dict['get_pop'].keys(): + for time in pop_history_dict['get_pop']: TestSimObj.send_event( time, cs, GET_POPULATION, event_body=GET_POPULATION.body( set([ specie ]) ) )