AttributeError:'module' object has no attribute 'allSimData'

Moderator: tom_morse

Post Reply
bwjmbb17
Posts: 16
Joined: Mon Apr 10, 2017 10:09 am

AttributeError:'module' object has no attribute 'allSimData'

Post by bwjmbb17 » Tue Jun 20, 2017 2:58 pm

Hey all,

I was wondering if anyone has run into the problem of trying to access the spiking data when running in parallel? This is the error that I am getting:

Code: Select all

spkid = sim.allSimData['spkid']
AttributeError: 'module' object has no attribute 'allSimData'
When only running on one core it works fine but when I run in parallel this is what I get. It seems like it can still access the data because I am still able to save the data to a file but it just throws up this error. Just thought I'd let you all know.

Thanks,
Brenyn

salvadord
Posts: 57
Joined: Tue Aug 18, 2015 3:49 pm

Re: AttributeError:'module' object has no attribute 'allSimD

Post by salvadord » Tue Jun 20, 2017 3:24 pm

I tried it on the prev code you sent me and it worked ok:

Code: Select all

 
  Cells: 103
  Connections: 3231 (31.37 per cell)
  Spikes: 0 (0.00 Hz)
  Simulated time: 0.5 s; 2 workers
  Run time: 0.58 s
  Done; saving time = 0.00 s.
Plotting raster...
No spikes available to plot raster
Plotting recorded cell traces ...
Plotting 2D representation of network cell locations and connections...
  Done; plotting time = 5.16 s

Total time = 6.13 s

>>> >>> sim.allSimData
{spkt: [], avgRate: 0, spkid: [], V_soma: {'cell_39': [-65.0, ... 
Maybe you can share your new code?

bwjmbb17
Posts: 16
Joined: Mon Apr 10, 2017 10:09 am

Re: AttributeError:'module' object has no attribute 'allSimD

Post by bwjmbb17 » Wed Jun 21, 2017 1:09 pm

Here is the updated code. If I run on more than 1 core it gives the same error. The main thing that has changed is the edition of trying to save the spike ids and spike times to a text file.

Code: Select all

from netpyne import specs, sim, analysis
from random import randint

# Varible Definitions
simTime = 276000
toneTrial = 44
shockTrials = 16
toneD_Num = [8, 24]
toneV_Num = [13, 24]
noise_freq_pyr = 3
noise_freq_int = 5
noise_tot_length = simTime
totNumCells = 100
numInter = 20
numAType = int((totNumCells - numInter) * 0.5)
numBType = int((totNumCells - numInter) * 0.3)
numCType = int((totNumCells - numInter) * 0.2)
toneStimD_List = []
toneStimV_List = []
shockStim_List = []
data_output = {}		# Data Dictionary
numSpikeA = 0
numSpikeB = 0
numSpikeC = 0
numSpikeInt = 0

# Create list of toneStimD and toneStimV
for i in range(0, toneTrial):
	if i < toneD_Num[0]:
		interval = 50
		number = 10+1
		start = 3500+4000*i
		for i in range(0, number):
			toneStimD_List.append(start+interval*i)
	elif i >= toneD_Num[0] and i < toneD_Num[1]:
		interval = 50/2
		number = 10*2+1
		start = 3500+4000*i
		for i in range(0, number):
			toneStimD_List.append(start+interval*i)
	elif i >= toneD_Num[1]:
		interval = 50/2
		number = 10*2+1
		start = 100000+3500+4000*i
		for i in range(0, number):
			toneStimD_List.append(start+interval*i)

for i in range(0, toneTrial):
	if i < toneV_Num[0]:
		interval = 50
		number = 10+1
		start = 3500+4000*i
		for i in range(0, number):
			toneStimV_List.append(start+interval*i)
	elif i >= toneV_Num[0] and i < toneV_Num[1]:
		interval = 50/2
		number = 10*2+1
		start = 3500+4000*i
		for i in range(0, number):
			toneStimV_List.append(start+interval*i)
	elif i >= toneV_Num[1]:
		interval = 50/2
		number = 10*2+1
		start = 100000+3500+4000*i
		for i in range(0, number):
			toneStimV_List.append(start+interval*i)
			
for i in range(0, shockTrials):
		interval = 5
		number = 20+1
		start = 35900+4000*i
		for i in range(0, number):
			shockStim_List.append(start+interval*i)

# Network Parameters
netParams = specs.NetParams()
netParams.sizeX = 130		# Horizontal Axis
netParams.sizeY = 50		# Vertical Axis
netParams.sizeZ = 100		# Horizontal Axis

# Population Parameters
netParams.popParams['PN_A'] = {'cellType': 'PYR_A', 'numCells': numAType,'xRange': [0,25], 'yRange': [0,50], 'cellModel': 'LA_Mod'}
netParams.popParams['PN_B'] = {'cellType': 'PYR_B', 'numCells': numBType, 'xRange': [25,50], 'yRange': [0,50], 'cellModel': 'LA_Mod'}
netParams.popParams['PN_C'] = {'cellType': 'PYR_C', 'numCells': numCType, 'xRange': [50,75], 'yRange': [0,50], 'cellModel': 'LA_Mod'}
netParams.popParams['INT'] = {'cellType': 'Inter1', 'numCells': numInter, 'xRange': [75,100], 'yRange': [0,50], 'cellModel': 'LA_Mod'}

netParams.popParams['Thal_Tone_D'] = {'cellModel': 'VecStim', 'numCells': 1, 'xRange': [100,110], 'yRange': [0, 50], 'spkTimes': toneStimD_List}
netParams.popParams['Cort_Tone_V'] = {'cellModel': 'VecStim', 'numCells': 1, 'xRange': [110,120], 'yRange': [0, 50], 'spkTimes': toneStimV_List}
netParams.popParams['Shock'] = {'cellModel': 'VecStim', 'numCells': 1, 'xRange': [120,130], 'yRange': [0, 50], 'spkTimes': shockStim_List}

# Cell Property Value
netParams.importCellParams(label='Type_A_Rule', conds={'cellType': 'PYR_A', 'cellModel': 'LA_Mod'}, fileName='LA_Template.py', cellName='Cell_A')
netParams.importCellParams(label='Type_B_Rule', conds={'cellType': 'PYR_B', 'cellModel': 'LA_Mod'}, fileName='LA_Template.py', cellName='Cell_B')
netParams.importCellParams(label='Type_C_Rule', conds={'cellType': 'PYR_C', 'cellModel': 'LA_Mod'}, fileName='LA_Template.py', cellName='Cell_C')
netParams.importCellParams(label='Inter_Rule', conds={'cellType': 'Inter1', 'cellModel': 'LA_Mod'}, fileName='LA_Template.py', cellName='Inter')

## Synaptic mechanism parameters
netParams.synMechParams['exc'] = {'mod': 'Exp2Syn', 'tau1': 1.0, 'tau2': 5.0, 'e': 0}  # soma NMDA synapse
# Interneuron Cells to Pyramidal Cells GABA with local Ca2+ pool and read public soma Ca2+ pool
netParams.synMechParams['interD2pyrD_STFD'] = {'mod': 'interD2pyrD_STFD', 'initW': 0.7}	# Synaptic weight range: 0.7 - 2 ('initW': 0.7)
# Pyramidal Cells to Interneuron Cells AMPA+NMDA with local Ca2+ pool
netParams.synMechParams['pyrD2interD_STFD'] = {'mod': 'pyrD2interD_STFD'} 	# Synaptic weight range: 1 - 2
# Pyramidal Cells to Pyramidal Cells AMPA+NMDA with local Ca2+ pool
netParams.synMechParams['pyrD2pyrD_STFD'] = {'mod': 'pyrD2pyrD_STFD'}		# Synaptic weight range: 0.5 - 1
# Shock to Interneuron Cells AMPA+NMDA with local Ca2+ pool
netParams.synMechParams['shock2interD'] = {'mod': 'shock2interD'}			# Synaptic weight range: 9 - 12
# Shock to Pyramidal Cells AMPA+NMDA with local Ca2+ pool
netParams.synMechParams['shock2pyrD'] = {'mod': 'shock2pyrD'}				# Synaptic weight range: 2 - 4.5 ( 10/4.6 (2) - 12/4.6 (2.6) )
# Tone to Interneuron Cells AMPA+NMDA with local Ca2+ pool
netParams.synMechParams['tone2interD'] = {'mod': 'tone2interD'}				# Synaptic weight range: 2 - 4
# Tone to Pyramidal Cells AMPA+NMDA with local Ca2+ pool
netParams.synMechParams['tone2pyrD'] = {'mod': 'tone2pyrD'}				# Synaptic weight range: 0.7 - 2
# Background to Interneuron Cells AMPA+NMDA 
netParams.synMechParams['bg2inter'] = {'mod': 'bg2inter'}
# Background to Pyramidal Cells AMPA+NMDA 
netParams.synMechParams['bg2pyr'] = {'mod': 'bg2pyr'}

# Stimulation parameters
# Generate Background Noise (Sources and Targets)
netParams.stimSourceParams['bg2inter_stim'] = {'type': 'NetStim', 'interval': 1000/noise_freq_int, 'number': noise_tot_length*noise_freq_int/1000, 'start': 0, 'noise': 1}
netParams.stimSourceParams['bg2pyr_stim'] = {'type': 'NetStim', 'interval': 1000/noise_freq_pyr, 'number': noise_tot_length*noise_freq_pyr/1000, 'start': 0, 'noise': 1}

netParams.stimTargetParams['bkg->inter'] = {'source': 'bg2inter_stim', 'conds': {'popLabel': 'INT'}, 'delay': 0, 'synMech': 'bg2inter'}	# Weight: 7 - 10 ('weight': 7)
netParams.stimTargetParams['bkg->pyr_a'] = {'source': 'bg2pyr_stim', 'conds': {'popLabel': 'PN_A'}, 'delay': 0, 'synMech': 'bg2pyr'}		# Weight: 0.7 - 2
netParams.stimTargetParams['bkg->pyr_b'] = {'source': 'bg2pyr_stim', 'conds': {'popLabel': 'PN_B'}, 'delay': 0, 'synMech': 'bg2pyr'}		# Weight: 0.7 - 2
netParams.stimTargetParams['bkg->pyr_c'] = {'source': 'bg2pyr_stim', 'conds': {'popLabel': 'PN_C'}, 'delay': 0, 'synMech': 'bg2pyr'}		# Weight: 0.7 - 2

## Cell Connectivity Rules
# Connectivity Between Pyramidal and Interneurons
netParams.connParams['PNs->PNs'] = {
	'preConds': {'popLabel': ['PN_A','PN_B','PN_C']},  	# connection from
	'postConds': {'popLabel': ['PN_A','PN_B','PN_C']},	# connnection to
	'probability': 0.25, 								# probability of connection (.25)
	'weight': 1,										# synaptic weight: 0.5 - 1
	'delay': randint(10,20),							# transmission delay (ms) 
	'synMech': 'pyrD2pyrD_STFD'}   						# target synaptic mechanism

netParams.connParams['INTs->PNs'] = {
	'preConds': {'popLabel': 'INT'},  					# connection from
	'postConds': {'popLabel': ['PN_A','PN_B','PN_C']},	# connnection to
	'probability': 0.6, 								# probability of connection
	'weight': 1, 									# synaptic weight: 0.7 - 2
	'delay': randint(10,20),							# transmission delay (ms) 
	'synMech': 'interD2pyrD_STFD'}   					# target synaptic mechanism

netParams.connParams['PNs->INTs'] = {
	'preConds': {'popLabel': ['PN_A','PN_B','PN_C']}, 	# connection from
	'postConds': {'popLabel': 'INT'},					# connnection to
	'probability': 0.33, 								# probability of connection
	'weight': 1, 										# synaptic weight: 1 - 2
	'delay': randint(10,20),							# transmission delay (ms) 
	'synMech': 'pyrD2interD_STFD'}   					# target synaptic mechanism	

## Connectivity Between Cells and Tone/Shock
# Pyramidal Cells and Input
netParams.connParams['Thal->PNs'] = {
	'preConds': {'popLabel': 'Thal_Tone_D'}, 
	'postConds': {'popLabel': ['PN_A','PN_B','PN_C']}, 
	'probability': 0.53, 					# probability of connection
	'weight': 1, 							# synaptic weight: 0.7 - 2
	'delay': randint(10,20),				# transmission delay (ms) 
	'synMech': 'tone2pyrD'}   				# target synaptic mechanism

netParams.connParams['Cort->PNs'] = {
	'preConds': {'popLabel': 'Cort_Tone_V'}, 
	'postConds': {'popLabel': ['PN_A','PN_B','PN_C']},
	'probability': 0.53, 					# probability of connection
	'weight': 1, 							# synaptic weight: 0.7 - 2
	'delay': randint(10,20),				# transmission delay (ms) 
	'synMech': 'tone2pyrD'}   				# target synaptic mechanism

netParams.connParams['Shock->PNs'] = {
	'preConds': {'popLabel': 'Shock'}, 
	'postConds': {'popLabel': ['PN_A','PN_B','PN_C']},
	'probability': 0.7, 					# probability of connection
	'weight': 1, 							# synaptic weight:  2 - 4.5 ( 10/4.6 (2) - 12/4.6 (2.6) )
	'delay': randint(10,20),				# transmission delay (ms) 
	'synMech': 'shock2pyrD'}   				# target synaptic mechanism

# Interneurons and Input
netParams.connParams['Thal->INTs'] = {
	'preConds': {'popLabel': 'Thal_Tone_D'}, 
	'postConds': {'popLabel': 'INT'}, 
	'probability': 0.5, 					# probability of connection
	'weight': 1, 							# synaptic weight: 2 - 4
	'delay': randint(10,20),				# transmission delay (ms) 
	'synMech': 'tone2interD'}   				# target synaptic mechanism

netParams.connParams['Cort->INTs'] = {
	'preConds': {'popLabel': 'Cort_Tone_V'}, 
	'postConds': {'popLabel': 'INT'},
	'probability': 0.5, 					# probability of connection
	'weight': 1, 							# synaptic weight: 2 - 4
	'delay': randint(10,20),				# transmission delay (ms) 
	'synMech': 'tone2interD'}   				# target synaptic mechanism

netParams.connParams['Shock->INTs'] = {
	'preConds': {'popLabel': 'Shock'}, 
	'postConds': {'popLabel': 'INT'},
	'probability': 0.7, 					# probability of connection
	'weight': 1, 							# synaptic weight: 9 - 12
	'delay': randint(10,20),				# transmission delay (ms) 
	'synMech': 'shock2interD'}   				# target synaptic mechanism

## Simulation options
simConfig = specs.SimConfig()					# object of class SimConfig to store simulation configuration
simConfig.duration = simTime			# Duration of the simulation, in ms
simConfig.dt = 0.05 #0.025 						# Internal integration timestep to use
simConfig.hParams = {'celsius': 31,'clamp_resist': 0.001,'steps_per_ms': 20} #, 'v_init': -65}
simConfig.verbose = 0						# Show detailed messages
simConfig.recordTraces = {'V_soma':{'sec':'soma','loc':0.5,'var':'v'}}  # Dict with traces to record
simConfig.recordStep = 0.01#0.025 					# Step size in ms to save data (eg. V traces, LFP, etc)
simConfig.filename = 'model_output'  				# Set file output name
simConfig.savePickle = False 					# Save params, network and sim output to pickle file
simConfig.checkErrors = 1

# Create network and run simulation
sim.createSimulateAnalyze(netParams = netParams, simConfig = simConfig)

import pylab; pylab.show()  # this line is only necessary in certain systems where figures appear empty

# Used to stop program after simulation and graphs and then save data and quit
#input("Type a number to quit:")

spkid = sim.allSimData['spkid']
spkt = sim.allSimData['spkt']

# Create open data.txt file and write to it
spike_file = open("data.txt", 'w')

# Save data to a text file
for i in range(0, len(spkid)):
	# Only save spikes from cells less than 100 (Cell 100 - 102 are tone and shock cells)
	if int(spkid[i]) < 100:
		spike_file.write('{0:8.3f}\t\t{1:2d}\n'.format(spkt[i], int(spkid[i])))

spike_file.close()
quit()

salvadord
Posts: 57
Joined: Tue Aug 18, 2015 3:49 pm

Re: AttributeError:'module' object has no attribute 'allSimD

Post by salvadord » Fri Jul 07, 2017 10:49 pm

Sorry for the delayed response, for some reason I wasn't getting email notifications for the forum posts.

The variable sim.allSimData only exists on node 0, so to solve your issue you just need to put your last lines of code within an if condition that makes sure only node 0 executes them :

Code: Select all

if sim.rank == 0:
   spkid = sim.allSimData['spkid']
   spkt = sim.allSimData['spkt']

   # Create open data.txt file and write to it
   spike_file = open("data.txt", 'w')

   # Save data to a text file
   for i in range(0, len(spkid)):
      # Only save spikes from cells less than 100 (Cell 100 - 102 are tone and shock cells)
      if int(spkid[i]) < 100:
         spike_file.write('{0:8.3f}\t\t{1:2d}\n'.format(spkt[i], int(spkid[i])))

   spike_file.close()


Note that sim.rank contains the index of the node/processor executing the code (value returned by sim.pc.id()); see http://www.neuron.yale.edu/neuron/stati ... arcon.html for more info.

Post Reply