@@ -200,6 +200,34 @@ def minInterval( self ):
200200 lastval = 0.0
201201 newdata = []
202202 isElec = self .field in ['Im' , 'current' , 'Vclamp' ] or (self .field == 'rate' and 'syn' in self .entities [0 ])
203+ mint = 1e9
204+ sortedData = sorted (self .data , key = lambda tv : tv [0 ])
205+ for d in sortedData :
206+ if ( d [0 ] - lastt ) < 1e-9 :
207+ continue
208+ mint = min ( mint , d [0 ]- lastt )
209+ lastt = d [0 ]
210+ lastt = 0.0
211+ mint *= self .timeScale
212+
213+ for d in sortedData :
214+ t = float (d [0 ])* self .timeScale
215+ val = float (d [1 ])* self .quantityScale
216+ if t == 0.0 : # It is OK to have an event at t = 0.
217+ newdata .append ( [d [0 ], d [1 ]] )
218+ lastval = val
219+ continue
220+
221+ if (not isElec ) and (t - lastt ) >= 100.0 and lastval < 1e-7 and val > 0.5e-4 : # Insert tiny intermediate step up for numerics
222+ newdata .append ( [(t - mint )/ self .timeScale , d [1 ] * 1e-4 ] )
223+ #print( f"INSERTING STIM1 ({newdata[-1][0]}, {newdata[-1][1]})" )
224+
225+ newdata .append ( [d [0 ], d [1 ]] )
226+ lastt = t
227+ lastval = val
228+ #print( f"INSERTING STIM PROPER ({newdata[-1][0]}, {newdata[-1][1]})" )
229+
230+ '''
203231 for d in self.data:
204232 if float( d[0] ) == 0.0: # Stim at starting time. Legit.
205233 newdata.append( [d[0], d[1]] )
@@ -209,22 +237,27 @@ def minInterval( self ):
209237 t = float(d[0])*self.timeScale
210238 val = float(d[1])*self.quantityScale
211239 if t > lastt: # Avoid zeros, could set many things at once.
212- ret = min ( ret , t - lastt )
240+ # ret = min( ret, t - lastt )
213241 if (not isElec) and (t - lastt) >= 100.0 and lastval < 1e-7 and val > 0.5e-4:
214242 # Have to insert intermediate step in data.
215243 newdata.append( [float(d[0]), 1e-6 / self.quantityScale] )
244+ print( f"INSERTING STIM1 ({newdata[-1][0]}, {newdata[-1][1]})" )
216245 newt = t + (t - lastt)/100.0
217246 #print( "inserting: ", [d[0], 1e-6], [newt, d[1]] )
218247 newdata.append( [newt/self.timeScale, d[1]] )
248+ print( f"INSERTING STIM2 ({newdata[-1][0]}, {newdata[-1][1]})" )
219249 ret = min( ret, (t - lastt)/100.0 )
220250 else:
221251 newdata.append( [d[0], d[1]] )
252+ print( f"INSERTING STIM PROPER ({newdata[-1][0]}, {newdata[-1][1]})" )
222253 lastt = t
223254 lastval = val
224-
225255 self.data = newdata
226256 self.shortestStimInterval = ret
227257 return ret
258+ '''
259+ self .data = newdata
260+ return mint
228261
229262
230263
@@ -1150,6 +1183,8 @@ def parseAndRun( model, stims, readouts, getPlots = False ):
11501183 for i in range ( len ( q ) ):
11511184 qe = heapq .heappop ( q )
11521185 currt = sw .getCurrentTime ()
1186+ if __name__ == "__main__" :
1187+ print ( "Current Sim Time = {:.3f}" .format ( currt ), end = '\r ' )
11531188 if ( qe .t > currt ):
11541189 #print( "currt={:.4f}, qt={:.4f}".format( currt, qe.t) )
11551190 sw .advanceSimulation ( qe .t - currt , doPlot = getPlots ,
@@ -1664,12 +1699,15 @@ def innerMain( exptFile, scoreFunc = defaultScoreFunc, modelFile = "", mapFile =
16641699 sw .makeReadoutPlots ( readoutVec )
16651700 if 'timeseries' in expt .exptType :
16661701 minInterval = readouts .getMinInterval ()
1702+ #print( "MIN INTERVAL READOUTS = ", minInterval )
16671703 for s in stims :
16681704 minInterval = min ( minInterval , s .minInterval () )
1705+ #print( "MIN INTERVAL STIMS = ", s.minInterval() )
16691706 else :
16701707 minInterval = readouts .settleTime
1708+ #print( "MIN INTERVAL settleTime = ", minInterval )
16711709
1672- #print( "minInterval = ", minInterval )
1710+ #print( "minInterval = ", minInterval, "solver = ", solver )
16731711 sw .buildSolver ( solver , useVclamp = hasVclamp , minInterval = minInterval )
16741712 ##############################################################
16751713 # Here we handle presettling. First to generate, then to apply
0 commit comments