@@ -100,9 +100,10 @@ def simulateNetPyNEModelInGeppetto(self, args):
100100 self .geppetto_model = self .model_interpreter .getGeppettoModel (sim )
101101 netpyne_model = sim
102102
103- else : # single cpu computation
103+ else :
104104 logging .info ("Starting simulation" )
105- if not 'usePrevInst' in args or not args ['usePrevInst' ]:
105+
106+ if not args .get ('usePrevInst' , False ):
106107 logging .debug ('Instantiating single thread simulation' )
107108 netpyne_model = self .instantiateNetPyNEModel ()
108109 self .geppetto_model = self .model_interpreter .getGeppettoModel (netpyne_model )
@@ -163,7 +164,8 @@ def remove(dictionary):
163164 wake_up_geppetto = False
164165 if all ([args [option ] for option in ['loadNetParams' , 'loadSimCfg' , 'loadSimData' , 'loadNet' ]]):
165166 wake_up_geppetto = True
166- if self .doIhaveInstOrSimData ()['haveInstance' ]: sim .clearAll ()
167+ if self .doIhaveInstOrSimData ()['haveInstance' ]:
168+ sim .clearAll ()
167169 sim .initialize ()
168170 sim .loadAll (args ['jsonModelFolder' ])
169171 self .netParams = sim .net .params
@@ -173,7 +175,8 @@ def remove(dictionary):
173175 else :
174176 if args ['loadNet' ]:
175177 wake_up_geppetto = True
176- if self .doIhaveInstOrSimData ()['haveInstance' ]: sim .clearAll ()
178+ if self .doIhaveInstOrSimData ()['haveInstance' ]:
179+ sim .clearAll ()
177180 sim .initialize ()
178181 sim .loadNet (args ['jsonModelFolder' ])
179182
@@ -191,7 +194,8 @@ def remove(dictionary):
191194 remove (self .simConfig .todict ())
192195
193196 if args ['loadNetParams' ]:
194- if self .doIhaveInstOrSimData ()['haveInstance' ]: sim .clearAll ()
197+ if self .doIhaveInstOrSimData ()['haveInstance' ]:
198+ sim .clearAll ()
195199 sim .loadNetParams (args ['jsonModelFolder' ])
196200 self .netParams = sim .net .params
197201 remove (self .netParams .todict ())
@@ -218,6 +222,11 @@ def importModel(self, modelParameters):
218222 :param modelParameters:
219223 :return:
220224 """
225+ if self .doIhaveInstOrSimData ()['haveInstance' ]:
226+ # TODO: this must be integrated into the general lifecycle of "model change -> simulate"
227+ # Shouldn't be specific to Import
228+ sim .clearAll ()
229+
221230 try :
222231 # Get Current dir
223232 owd = os .getcwd ()
@@ -226,27 +235,30 @@ def importModel(self, modelParameters):
226235
227236 with redirect_stdout (sys .__stdout__ ):
228237 # NetParams
229- netParamsPath = str (modelParameters ["netParamsPath" ])
230- sys .path .append (netParamsPath )
231- os .chdir (netParamsPath )
238+ net_params_path = str (modelParameters ["netParamsPath" ])
239+ sys .path .append (net_params_path )
240+ os .chdir (net_params_path )
232241 # Import Module
233- netParamsModuleName = importlib .import_module (str (modelParameters ["netParamsModuleName" ]))
242+ net_params_module_name = importlib .import_module (str (modelParameters ["netParamsModuleName" ]))
234243 # Import Model attributes
235- self .netParams = getattr (netParamsModuleName , str (modelParameters ["netParamsVariable" ]))
244+ self .netParams = getattr (net_params_module_name , str (modelParameters ["netParamsVariable" ]))
236245
237246 for key , value in self .netParams .cellParams .items ():
238247 if hasattr (value , 'todict' ):
239248 self .netParams .cellParams [key ] = value .todict ()
240249
241250 # SimConfig
242- simConfigPath = str (modelParameters ["simConfigPath" ])
243- sys .path .append (simConfigPath )
244- os .chdir (simConfigPath )
251+ sim_config_path = str (modelParameters ["simConfigPath" ])
252+ sys .path .append (sim_config_path )
253+ os .chdir (sim_config_path )
245254 # Import Module
246- simConfigModuleName = importlib .import_module (str (modelParameters ["simConfigModuleName" ]))
255+ sim_config_module_name = importlib .import_module (str (modelParameters ["simConfigModuleName" ]))
247256 # Import Model attributes
248- self .simConfig = getattr (simConfigModuleName , str (modelParameters ["simConfigVariable" ]))
257+ self .simConfig = getattr (sim_config_module_name , str (modelParameters ["simConfigVariable" ]))
249258
259+ # TODO: when should sim.initialize be called?
260+ # Only on import or better before every simulation or network instantiation?
261+ sim .initialize ()
250262 return utils .getJSONReply ()
251263 except :
252264 return utils .getJSONError ("Error while importing the NetPyNE model" , sys .exc_info ())
@@ -319,7 +331,6 @@ def importNeuroML(self, modelParams):
319331 return utils .getJSONError ("Error while exporting the NetPyNE model" , sys .exc_info ())
320332
321333 def deleteModel (self , modelParams ):
322-
323334 try :
324335 with redirect_stdout (sys .__stdout__ ):
325336 self .netParams = specs .NetParams ()
@@ -332,8 +343,8 @@ def deleteModel(self, modelParams):
332343 try :
333344 # This function fails is some keys don't exists
334345 # sim.clearAll()
346+ # TODO: as part of #264 we should remove the method and use clearAll intstead
335347 self .clearSim ()
336-
337348 except :
338349 pass
339350
@@ -357,7 +368,11 @@ def simulateNetPyNEModel(self):
357368 sim .saveData ()
358369 return sim
359370
360- def doIhaveInstOrSimData (self ): # return [bool, bool] telling if we have an instance and simulated data
371+ def doIhaveInstOrSimData (self ):
372+ """ Telling if we have an instance or simulated data.
373+
374+ return [bool, bool]
375+ """
361376 with redirect_stdout (sys .__stdout__ ):
362377 out = [False , False ]
363378 if hasattr (sim , 'net' ):
0 commit comments