Skip to content

Commit 659b998

Browse files
committed
Fixes for stim queue insertion block
1 parent 41c6b74 commit 659b998

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

findSim.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

simWrapMoose.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,7 @@ def loadModelFile( self, fname, modifyFunc, scaleParam, dumpFname, paramFname, c
417417
# Deprecated. Here we override the rdes to NOT make a solver.
418418
#self.turnOffElec = rdes.turnOffElec
419419
#rdes.turnOffElec = False
420-
#print( "LIB: ", moose.element( '/library/chem/kinetics/glu/vesicle_release' ).Kf )
421420
mscript.build( rdes )
422-
#print( "MODEL: ", moose.element( '/model/chem/dend/glu/vesicle_release' ).Kf )
423421
self.modelId = moose.element( '/model' )
424422
self.buildModelLookup( self.objMap )
425423
#rdes.turnOffElec = self.turnOffElec
@@ -481,6 +479,7 @@ def buildSolver( self, solver, useVclamp = False, minInterval = 1.0 ):
481479
stoich.compartment = moose.element( compt.path )
482480
stoich.ksolve = ksolve
483481
stoich.reacSystemPath = compt.path + '/##'
482+
#print( "ESTIMATED DT = ", ksolve.estimatedDt )
484483
for i in range( 10, 20 ):
485484
moose.setClock( i, 0.5 * minInterval )
486485

@@ -687,6 +686,13 @@ def getCurrentTime( self ):
687686
return moose.element( '/clock' ).currentTime
688687

689688
def advanceSimulation( self, advanceTime, doPlot = True, doSettle = False ):
689+
'''
690+
dts = moose.element( "/clock").dts
691+
print( "DTS: ")
692+
for idx, dt in enumerate( dts ):
693+
if dt > 0:
694+
print( idx, dt)
695+
'''
690696
moose.start( advanceTime )
691697

692698
def reinitSimulation( self ):

0 commit comments

Comments
 (0)