So I updated the code to keep the h.Vector() objects in memory. Another post on the forum seemed to suggest that this was important.
However, I'm still getting sporadic segfaults. The code DOES work maybe 50% of the time. When I comment out the section for adding synapses, I get no segfaults.
Code: Select all
from neuron import h
import numpy as np
import pylab as plt
# Load morphology and other stuff
h.load_file('stdrun.hoc')
h.xopen('ri06.hoc')
h.xopen('fixnseg.hoc')
h.xopen('5a_nogui.hoc')
h.tstop = 100.0
# Function to get a random segment
def randseg():
tmp = np.random.uniform(0,1)
comp = h.apic[int(np.random.uniform(0,41))]
return comp(tmp)
# Add 50 random synapses
syn, nc, vs, vec = [], [], [], []
for i in range(50):
# New synapse
syn.append(h.Exp2Syn(randseg()))
syn[-1].e = 0
syn[-1].tau1 = 0.5
syn[-1].tau2 = 20
# New VecStim object
vs.append(h.VecStim())
vec.append(h.Vector([np.random.uniform(20,80)]))
vs[-1].play(vec[-1])
# New NetCon Object
nc.append(h.NetCon(vs[-1],syn[-1]))
nc[-1].weight[0] = 0.001
# Print stim time
print vec[-1][0]
t, v = h.Vector(), h.Vector()
v.record(h.soma[0](0.5)._ref_v)
t.record(h._ref_t)
h.run()
plt.figure
plt.plot(t,v)
plt.show()