/
GenNetworkParallel.py
295 lines (220 loc) · 10.4 KB
/
GenNetworkParallel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#
#
# File to generate network for execution on parallel NEURON
# Note this script has only been tested with UCL's cluster!
#
# Author: Padraig Gleeson
#
# This file has been developed as part of the neuroConstruct project
# This work has been funded by the Medical Research Council and the
# Wellcome Trust
#
#
from sys import *
from time import *
from java.io import File
from ucl.physiol.neuroconstruct.project import ProjectManager
from ucl.physiol.neuroconstruct.utils import NumberGenerator
from ucl.physiol.neuroconstruct.hpc.mpi import MpiSettings
from ucl.physiol.neuroconstruct.simulation import SimulationsInfo
from ucl.physiol.neuroconstruct.cell.utils import CellTopologyHelper
path.append(environ["NC_HOME"]+"/pythonNeuroML/nCUtils")
import ncutils as nc
projFile = File("../Thalamocortical.ncx")
########### Main settings ###########
simConfig= "CunninghamEtAl04_small"
simDuration = 1000 # ms
simDt = 0.05 # ms
neuroConstructSeed = 12345
simulatorSeed = 12345
#simulators = ["NEURON", "GENESIS"]
#simulators = ["NEURON", "GENESIS", "MOOSE"]
#simulators = ["NEURON", "MOOSE"]
#simulators = ["GENESIS"]
simulators = ["NEURON"]
#simulators = ["MOOSE"]
simRefPrefix = "Fract_"
defaultSynapticDelay = 0.1
#mpiConf = MpiSettings.CLUSTER_4PROC
#mpiConf = MpiSettings.LEGION_8PROC
#mpiConf = MpiSettings.LEGION_16PROC
mpiConf = MpiSettings.LOCAL_SERIAL
mpiConf = MpiSettings.MATLEM_8PROC
mpiConf = MpiSettings.MATLEM_32PROC
mpiConf = MpiSettings.MATLEM_64PROC
#mpiConf = MpiSettings.LEGION_1PROC
#mpiConf = MpiSettings.LEGION_16PROC
#mpiConf = MpiSettings.LEGION_256PROC
#mpiConf = 'Matthau_6_8PROCS'
#mpiConf = 'Matthau_Lemmon_Test_56'
#mpiConf = 'Matthau_Lemmon_Test_ALL'
'''
numFRB = 3
numRS = 3
numLTS = 0
numBask = 0
numAxAx = 0
numFRB = 6
numRS = 20
numLTS = 10
numBask = 10
numAxAx = 10
'''
numPyr = 1152
fractFRB = 0.05
SimulationsInfo.addExtraSimProperty("fractFRB", str(fractFRB))
numFRB = int(fractFRB*numPyr)
numRS = numPyr - numFRB
numLTS = 96
numBask = 96
numAxAx = 96
# Maximum electronic length of compartments (adjusts nseg etc.)
maxElecLenFRB = -1 # 0.01 will give ~700, -1 will leave as is
maxElecLenRS = -1 # 0.01 will give ~700, -1 will leave as is
maxElecLenLTS = -1 # 0.01 will give ~570, -1 will leave as is
maxElecLenAxAx = -1 # 0.01 will give ~570, -1 will leave as is
maxElecLenBask = -1 # 0.01 will give ~570, -1 will leave as is
somaNseg = -1 # 12
# Scaling for electrical coupling weights
gapScaling = 0.7
# Scaling for all chemical synapse weights
synScaling = 1
varTimestepNeuron = False
verbose = True
runInBackground= False
saveAsHdf5 = True
#saveAsHdf5 = False
suggestedRemoteRunTime = 1430
'''
numFRB = 6
numRS = 109
numLTS = 10
numBask = 10
numAxAx = 10
'''
#######################################
### Load neuroConstruct project
print "Loading project from "+ projFile.getCanonicalPath()
pm = ProjectManager()
project = pm.loadProject(projFile)
### Set duration & timestep & simulation configuration
project.simulationParameters.setDt(simDt)
simConfig = project.simConfigInfo.getSimConfig(simConfig)
simConfig.setSimDuration(simDuration)
### Set simulation reference
index = 0
simRef = "%s%i"%(simRefPrefix,index)
while File( "%s/simulations/%s_N"%(project.getProjectMainDirectory().getCanonicalPath(), simRef)).exists():
simRef = "%s%i"%(simRefPrefix,index)
index = index+1
project.simulationParameters.setReference(simRef)
### Change num in each cell group
project.cellGroupsInfo.getCellPackingAdapter("CG_C04_FRB_sm").setMaxNumberCells(numFRB) # Note only works if RandomCellPackingAdapter
project.cellGroupsInfo.getCellPackingAdapter("CG_C04_RS_sm").setMaxNumberCells(numRS)
project.cellGroupsInfo.getCellPackingAdapter("CG_C04_LTS_sm").setMaxNumberCells(numLTS)
project.cellGroupsInfo.getCellPackingAdapter("CG_C04_Bask_sm").setMaxNumberCells(numBask)
project.cellGroupsInfo.getCellPackingAdapter("CG_C04_AxAx_sm").setMaxNumberCells(numAxAx)
### Change weights in synapses/gap junctions
for netConnName in simConfig.getNetConns():
if netConnName.count("gap")==0:
if synScaling != 1:
SimulationsInfo.addExtraSimProperty("synapticWeightScaling", str(synScaling))
print "Changing synaptic weight in %s by factor %f"%(netConnName, synScaling)
project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(0).setWeightsGenerator(NumberGenerator(synScaling))
else:
if gapScaling != 1:
SimulationsInfo.addExtraSimProperty("gapJunctionWeightScaling", str(gapScaling))
print "Changing gap junction weight in %s by factor %f"%(netConnName, gapScaling)
project.morphNetworkConnectionsInfo.getSynapseList(netConnName).get(0).setWeightsGenerator(NumberGenerator(gapScaling))
### Change spatial discretisation of some cells. This will impact accuracy & simulation speed
if maxElecLenFRB > 0:
frbCell = project.cellManager.getCell("L23PyrFRB_varInit")
info = CellTopologyHelper.recompartmentaliseCell(frbCell, maxElecLenFRB, project)
print "Recompartmentalised FRB cell: "+info
if somaNseg > 0:
frbCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)
if maxElecLenRS > 0:
rsCell = project.cellManager.getCell("L23PyrRS")
info = CellTopologyHelper.recompartmentaliseCell(rsCell, maxElecLenRS, project)
print "Recompartmentalised RS cell: "+info
if somaNseg > 0:
rsCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)
if maxElecLenLTS > 0:
ltsCell = project.cellManager.getCell("SupLTSInter")
info = CellTopologyHelper.recompartmentaliseCell(ltsCell, maxElecLenLTS, project)
print "Recompartmentalised LTS cell: "+info
if somaNseg > 0:
ltsCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)
if maxElecLenAxAx > 0:
axAxCell = project.cellManager.getCell("SupAxAx")
info = CellTopologyHelper.recompartmentaliseCell(axAxCell, maxElecLenAxAx, project)
print "Recompartmentalised AxAx cell: "+info
if somaNseg > 0:
axAxCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)
if maxElecLenBask > 0:
baskCell = project.cellManager.getCell("SupBasket")
info = CellTopologyHelper.recompartmentaliseCell(baskCell, maxElecLenBask, project)
print "Recompartmentalised Bask cell: "+info
if somaNseg > 0:
baskCell.getSegmentWithId(0).getSection().setNumberInternalDivisions(somaNseg)
### Change parallel configuration
mpiSettings = MpiSettings()
simConfig.setMpiConf(mpiSettings.getMpiConfiguration(mpiConf))
print "Parallel configuration: "+ str(simConfig.getMpiConf())
if suggestedRemoteRunTime > 0:
project.neuronFileManager.setSuggestedRemoteRunTime(suggestedRemoteRunTime)
project.genesisFileManager.setSuggestedRemoteRunTime(suggestedRemoteRunTime)
### Change synaptic delay associated with each net conn
for netConnName in simConfig.getNetConns():
if netConnName.count("gap")==0:
print "Changing synaptic delay in %s to %f"%(netConnName, defaultSynapticDelay)
delayGen = NumberGenerator(defaultSynapticDelay)
for synProps in project.morphNetworkConnectionsInfo.getSynapseList(netConnName):
synProps.setDelayGenerator(delayGen)
# defaultSynapticDelay will be recorded in simulation.props and listed in SimulationBrowser GUI
SimulationsInfo.addExtraSimProperty("defaultSynapticDelay", str(defaultSynapticDelay))
### Generate network structure in neuroConstruct
pm.doGenerate(simConfig.getName(), neuroConstructSeed)
while pm.isGenerating():
print "Waiting for the project to be generated with Simulation Configuration: "+str(simConfig)
sleep(2)
print "Number of cells generated: " + str(project.generatedCellPositions.getNumberInAllCellGroups())
print "Number of network connections generated: " + str(project.generatedNetworkConnections.getNumAllSynConns())
if simulators.count("NEURON")>0:
simRefN = simRef+"_N"
project.simulationParameters.setReference(simRefN)
nc.generateAndRunNeuron(project,
pm,
simConfig,
simRefN,
simulatorSeed,
verbose=verbose,
runInBackground=runInBackground,
saveAsHdf5 = saveAsHdf5,
varTimestep=varTimestepNeuron)
sleep(2) # wait a while before running GENESIS...
if simulators.count("GENESIS")>0:
simRefG = simRef+"_G"
project.simulationParameters.setReference(simRefG)
nc.generateAndRunGenesis(project,
pm,
simConfig,
simRefG,
simulatorSeed,
verbose=verbose,
runInBackground=runInBackground)
sleep(2) # wait a while before running MOOSE...
if simulators.count("MOOSE")>0:
simRefM = simRef+"_M"
project.simulationParameters.setReference(simRefM)
nc.generateAndRunMoose(project,
pm,
simConfig,
simRefM,
simulatorSeed,
verbose=verbose,
runInBackground=runInBackground)
sleep(2) # wait a while before running GENESIS...
print "Finished running all sims, shutting down..."
sleep(5)
exit()