Skip to content

Commit 19fda28

Browse files
authored
Merge pull request #74 from MetaCell/py3
Migrate to latest jupyter libs
2 parents 3588295 + 4af4cda commit 19fda28

35 files changed

Lines changed: 517 additions & 1188 deletions

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ script:
6767
- "curl -s -I $1 http://localhost:8888/geppetto | grep HTTP/1.1 | awk {'print $2'}"
6868
- firefox --version
6969
- travis_retry xvfb-run -a --server-args="-screen 0 1024x768x24" casperjs test netpyne-tests.js --host=http://localhost:8888/ --engine=slimerjs
70-
- sudo docker logs -t netpyne-ui_container
70+
- python -c "import fcntl; fcntl.fcntl(1, fcntl.F_SETFL, 0)"
71+
- docker logs -t netpyne-ui_container
7172
- docker stop $(docker ps -a -q)
7273
- docker rm $(docker ps -a -q)

Dockerfile

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ RUN apt-get install -y \
99
g++ \
1010
build-essential \
1111
libncurses-dev \
12-
python2.7 \
1312
libpython-dev \
1413
cython \
1514
libx11-dev \
@@ -20,36 +19,31 @@ RUN apt-get install -y \
2019
libtool \
2120
libxext-dev \
2221
libncurses-dev \
23-
python2.7-dev \
2422
xfonts-100dpi \
2523
libopenmpi-dev \
26-
python2.7-scipy \
2724
make \
2825
zlib1g-dev \
2926
unzip \
3027
vim \
3128
libpng-dev
3229

33-
# Install latest NEURON
34-
RUN git clone --branch 7.6.1crxd https://github.com/adamjhn/nrn.git
30+
# Switch to non sudo, create a Python 3 virtual environment
31+
USER $NB_USER
32+
RUN conda create --name snakes python=3.7
33+
34+
# Install latest iv and NEURON
35+
RUN git clone --branch 7.6.2 https://github.com/neuronsimulator/nrn
3536
WORKDIR nrn
3637
RUN ./build.sh
37-
RUN ./configure --without-x --with-nrnpython=python2 --without-paranrn --prefix="/home/jovyan/work/nrn/" --without-iv
38+
# Activate conda to configure nrn with the right python version
39+
RUN /bin/bash -c "source activate snakes && ./configure --without-x --with-nrnpython=python3 --without-paranrn --prefix='/home/jovyan/work/nrn/' --without-iv"
3840
RUN make --silent -j4
3941
RUN make --silent install -j4
4042

41-
# Switch to non sudo, create a Python 2 virtual environment
42-
USER $NB_USER
43-
# Commenting out the conda update things broke!
44-
# RUN conda update conda
45-
RUN conda create --name snakes python=2
46-
4743
# Install NEURON python
4844
WORKDIR src/nrnpython
4945
ENV PATH="/home/jovyan/work/nrn/x86_64/bin:${PATH}"
5046
RUN /bin/bash -c "source activate snakes && python setup.py install"
51-
# Install Bokeh
52-
RUN /bin/bash -c "source activate snakes && conda install bokeh=0.12.7"
5347

5448
ARG INCUBATOR_VER=unknown
5549
RUN /bin/bash -c "INCUBATOR_VER=${INCUBATOR_VER} source activate snakes && pip install netpyne_ui"

Dockerfile_dev

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ RUN apt-get install -y \
1313
g++ \
1414
build-essential \
1515
libncurses-dev \
16-
python2.7 \
1716
libpython-dev \
1817
cython \
1918
libx11-dev \
@@ -24,36 +23,32 @@ RUN apt-get install -y \
2423
libtool \
2524
libxext-dev \
2625
libncurses-dev \
27-
python2.7-dev \
2826
xfonts-100dpi \
2927
libopenmpi-dev \
30-
python2.7-scipy \
3128
make \
3229
zlib1g-dev \
3330
unzip \
3431
vim \
3532
libpng-dev
3633

34+
# Switch to non sudo, create a Python 3 virtual environment
35+
USER $NB_USER
36+
RUN conda create --name snakes python=3.7
37+
3738
# Install latest iv and NEURON
38-
RUN git clone --branch 7.6.1crxd https://github.com/adamjhn/nrn.git
39+
RUN git clone --branch 7.6.2 https://github.com/neuronsimulator/nrn
3940
WORKDIR nrn
4041
RUN ./build.sh
41-
RUN ./configure --without-x --with-nrnpython=python2 --without-paranrn --prefix="/home/jovyan/work/nrn/" --without-iv
42+
# Activate conda to configure nrn with the right python version
43+
RUN /bin/bash -c "source activate snakes && ./configure --without-x --with-nrnpython=python3 --without-paranrn --prefix='/home/jovyan/work/nrn/' --without-iv"
4244
RUN make --silent -j4
4345
RUN make --silent install -j4
4446

45-
# Switch to non sudo, create a Python 2 virtual environment
46-
USER $NB_USER
47-
# Commenting out the conda update things broke!
48-
# RUN conda update conda
49-
RUN conda create --name snakes python=2
5047

5148
# Install NEURON python
5249
WORKDIR src/nrnpython
5350
ENV PATH="/home/jovyan/work/nrn/x86_64/bin:${PATH}"
5451
RUN /bin/bash -c "source activate snakes && python setup.py install"
55-
# Install Bokeh
56-
RUN /bin/bash -c "source activate snakes && conda install bokeh=0.12.7"
5752

5853
# Clone NetPyNE-UI and install the development version
5954
WORKDIR ../../../

netpyne_ui/netpyne_geppetto.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
netpyne_geppetto.py
33
Initialise NetPyNE Geppetto, this class contains methods to connect NetPyNE with the Geppetto based UI
44
"""
5-
import StringIO
5+
import io
66
import json
77
import os
88
import importlib
@@ -14,9 +14,11 @@
1414
import traceback
1515

1616

17-
from netpyne import specs, sim, analysis, utils
18-
from netpyne.metadata import metadata, api
19-
from netpyne_model_interpreter import NetPyNEModelInterpreter
17+
from netpyne import specs, sim, analysis
18+
from netpyne.specs.utils import validateFunction
19+
from netpyne.conversion.neuronPyHoc import mechVarList
20+
from netpyne.metadata import metadata
21+
from netpyne_ui.netpyne_model_interpreter import NetPyNEModelInterpreter
2022
from pygeppetto.model.model_serializer import GeppettoModelSerializer
2123
import matplotlib.pyplot as plt
2224
from pygeppetto import ui
@@ -27,6 +29,7 @@
2729
from shutil import copyfile
2830
from jupyter_geppetto.geppetto_comm import GeppettoJupyterModelSync, GeppettoJupyterGUISync
2931
from jupyter_geppetto.geppetto_comm import GeppettoCoreAPI as G
32+
import imp
3033

3134

3235

@@ -108,7 +111,7 @@ def importModel(self, modelParameters):
108111

109112
self.compileModMechFiles(modelParameters['compileMod'], modelParameters['modFolder'])
110113

111-
import netpyne_geppetto
114+
from . import netpyne_geppetto
112115

113116
if modelParameters['importFormat']=='py':
114117
# NetParams
@@ -120,7 +123,7 @@ def importModel(self, modelParameters):
120123
# Import Model attributes
121124
netpyne_geppetto.netParams = getattr(netParamsModuleName, str(modelParameters["netParamsVariable"]))
122125

123-
for key, value in netpyne_geppetto.netParams.cellParams.iteritems():
126+
for key, value in netpyne_geppetto.netParams.cellParams.items():
124127
if hasattr(value, 'todict'):
125128
netpyne_geppetto.netParams.cellParams[key] = value.todict()
126129

@@ -159,7 +162,7 @@ def importCellTemplate(self, modelParameters, modFolder, compileMod):
159162
# Get Current dir
160163
owd = os.getcwd()
161164

162-
from netpyne_geppetto import netParams
165+
from .netpyne_geppetto import netParams
163166

164167
self.compileModMechFiles(compileMod, modFolder)
165168

@@ -185,7 +188,7 @@ def exportModel(self, modelParameters):
185188
return self.getJSONError("Error while exporting the NetPyNE model",traceback.format_exc())
186189

187190
def instantiateNetPyNEModel(self):
188-
import sys; reload(sys)
191+
import sys; imp.reload(sys)
189192
sim.initialize(netParams, simConfig) # create network object and set cfg and net params
190193
sim.net.createPops() # instantiate network populations
191194
sim.net.createCells() # instantiate network cells based on defined populations
@@ -198,7 +201,7 @@ def instantiateNetPyNEModel(self):
198201
return sim
199202

200203
def simulateNetPyNEModel(self):
201-
import sys; reload(sys)
204+
import sys; imp.reload(sys)
202205
sim.setupRecording()
203206
sim.simulate()
204207
sim.saveData()
@@ -244,15 +247,15 @@ def getPlot(self, plotName, LFPflavour):
244247
return [ui.getSVG(fig[0])].__str__()
245248
elif isinstance(fig, dict):
246249
svgs = []
247-
for key, value in fig.iteritems():
250+
for key, value in fig.items():
248251
logging.debug("Found plot for "+ key)
249252
svgs.append(ui.getSVG(value))
250253
return svgs.__str__()
251254
else:
252255
return [ui.getSVG(fig)].__str__()
253256

254257
def getAvailablePops(self):
255-
return netParams.popParams.keys()
258+
return list(netParams.popParams.keys())
256259

257260
def getAvailableCellModels(self):
258261
cellModels = set([])
@@ -275,29 +278,29 @@ def getAvailableCellTypes(self):
275278
def getAvailableSections(self):
276279
sections = {}
277280
for cellRule in netParams.cellParams:
278-
sections[cellRule] = netParams.cellParams[cellRule]['secs'].keys()
281+
sections[cellRule] = list(netParams.cellParams[cellRule]['secs'].keys())
279282
return sections
280283

281284
def getAvailableStimSources(self):
282-
return netParams.stimSourceParams.keys()
285+
return list(netParams.stimSourceParams.keys())
283286

284287
def getAvailableSynMech(self):
285-
return netParams.synMechParams.keys()
288+
return list(netParams.synMechParams.keys())
286289

287290
def getAvailableMechs(self):
288-
mechs = utils.mechVarList()['mechs']
289-
for key in mechs.keys():
291+
mechs = mechVarList()['mechs']
292+
for key in list(mechs.keys()):
290293
if 'ion' in key: del mechs[key]
291294
for key in ["morphology", "capacitance", "extracellular"]: del mechs[key]
292-
return mechs.keys()
295+
return list(mechs.keys())
293296

294297
def getMechParams(self, mechanism):
295-
params = utils.mechVarList()['mechs'][mechanism]
298+
params = mechVarList()['mechs'][mechanism]
296299
return [value[:-(len(mechanism) + 1)] for value in params]
297300

298301
def getAvailablePlots(self):
299302
plots = ["plotRaster", "plotSpikeHist", "plotSpikeStats","plotRatePSD", "plotTraces", "plotLFP", "plotShape", "plot2Dnet", "plotConn", "granger"]
300-
return [plot for plot in plots if plot not in simConfig.analysis.keys()]
303+
return [plot for plot in plots if plot not in list(simConfig.analysis.keys())]
301304

302305
def deleteParam(self, paramToDel):
303306
logging.debug("Checking if netParams."+paramToDel+" is not null")
@@ -308,7 +311,7 @@ def deleteParam(self, paramToDel):
308311
logging.debug('Parameter '+paramToDel+' is null, not deleted')
309312

310313
def validateFunction(self, functionString):
311-
return utils.ValidateFunction(functionString, netParams.__dict__)
314+
return ValidateFunction(functionString, netParams.__dict__)
312315

313316
def generateScript(self, metadata):
314317
def convert2bool(string):
@@ -332,20 +335,20 @@ def header(title, spacer='-'):
332335
script.write('netParams = specs.NetParams()\n')
333336
script.write('simConfig = specs.SimConfig()\n')
334337
script.write(header('single value attributes'))
335-
for attr, value in netParams.__dict__.items():
338+
for attr, value in list(netParams.__dict__.items()):
336339
if attr not in params:
337340
if value!=getattr(specs.NetParams(), attr):
338341
script.write('netParams.' + attr + ' = ')
339342
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
340343

341344
script.write(header('network attributes'))
342345
for param in params:
343-
for key, value in getattr(netParams, param).items():
346+
for key, value in list(getattr(netParams, param).items()):
344347
script.write("netParams." + param + "['" + key + "'] = ")
345348
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
346349

347350
script.write(header('network configuration'))
348-
for attr, value in simConfig.__dict__.items():
351+
for attr, value in list(simConfig.__dict__.items()):
349352
if value!=getattr(specs.SimConfig(), attr):
350353
script.write('netParams.' + attr + ' = ')
351354
script.write(convert2bool(json.dumps(value, indent=4))+'\n')
@@ -427,8 +430,11 @@ def globalMessageHandler(identifier, command, parameters):
427430
response = eval(command)
428431
else:
429432
response = eval(command + '(*parameters)')
433+
import sys
434+
imp.reload(sys)
435+
print(type(response))
430436
GeppettoJupyterModelSync.events_controller.triggerEvent(
431-
"receive_python_message", {'id': identifier, 'response': response})
437+
"receive_python_message", {'id': identifier, 'response': response.decode("utf-8") if isinstance(response, bytes) else response})
432438
except:
433439
response = netpyne_geppetto.getJSONError("Error while executing command "+command,traceback.format_exc())
434440
GeppettoJupyterModelSync.events_controller.triggerEvent(
@@ -481,7 +487,7 @@ def GeppettoInit():
481487

482488
GeppettoJupyterModelSync.current_model.original_model = json.dumps({'netParams': netParams.__dict__,
483489
'simConfig': simConfig.__dict__,
484-
'metadata': metadata.metadata,
490+
'metadata': metadata,
485491
'requirement': 'from netpyne_ui.netpyne_geppetto import *',
486492
'isDocker': os.path.isfile('/.dockerenv'),
487493
'currentFolder': os.getcwd()})

netpyne_ui/netpyne_model_interpreter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def extractPopulations(self, netpyne_model, netpyne_geppetto_library, geppetto_m
6868

6969
# Iterate sections creating spheres and cylinders
7070
if hasattr(secs, 'items'):
71-
for sec_name, sec in secs.items():
71+
for sec_name, sec in list(secs.items()):
7272
if 'pt3d' in sec['geom']:
7373
points = sec['geom']['pt3d']
7474
for i in range(len(points) - 1):

netpyne_ui/tests/M1detailed/M1detailed.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

netpyne_ui/tests/M1detailed/cells/ITcell.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def geom_nseg(self):
116116
sec.nseg = int((sec.L/(d_lambda*self.lambda_f(sec))+0.9)/2)*2 + 1
117117
for sec in self.all:
118118
after += sec.nseg
119-
print "geom_nseg: changed from ", before, " to ", after, " total segments"
119+
print(("geom_nseg: changed from ", before, " to ", after, " total segments"))
120120

121121
def lambda_f(self, section):
122122
# these are reasonable values for most models
@@ -147,7 +147,7 @@ def optimize_nseg (self):
147147
for sec in self.all:
148148
sec.Ra = rall
149149
sec.cm = cap
150-
for i in xrange(2,len(self.apic),1):
150+
for i in range(2,len(self.apic),1):
151151
self.apic[i].cm = spinecapfactor * self.apic[i].cm # spinecapfactor * cm
152152
self.apic[i].g_pas = spinecapfactor / rm # spinecapfactor * (1.0/rm)
153153
for sec in self.dend:
@@ -174,7 +174,7 @@ def init_once (self):
174174
self.apicchanprop()
175175
self.addbasalchan()
176176
self.basalchanprop()
177-
for i in xrange(2,len(self.apic),1):
177+
for i in range(2,len(self.apic),1):
178178
self.apic[i].cm = spinecapfactor * self.apic[i].cm # spinecapfactor * cm
179179
self.apic[i].g_pas = spinecapfactor / rm # spinecapfactor * (1.0/rm)
180180
for sec in self.dend:
-995 KB
Binary file not shown.

netpyne_ui/tests/M1detailed/cells/cellDensity.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
# L5B PV = 6180, SOM = 2600 (~70-30%)
6767
# L6 PV = 2640, SOM = 1820 (~60-40%)
6868

69-
print density
70-
print relDensityI
69+
print(density)
70+
print(relDensityI)
7171

7272
with open('popColors.pkl', 'r') as fileObj: popColors = pickle.load(fileObj)['popColors'] # load popColors
7373

@@ -81,15 +81,15 @@
8181
layers['5B'] = {'IT': 1155, 'PT': 1155, 'SOM': 202, 'PV':411}
8282
layers['6'] = {'IT': 1465, 'CT': 1465, 'SOM': 107, 'PV':218}
8383

84-
for layer,pops in layers.iteritems():
84+
for layer,pops in list(layers.items()):
8585
# make a square figure and axes
8686
figure(1, figsize=(6,6))
8787
ax = axes([0.1, 0.1, 0.8, 0.8])
8888

8989
# The slices will be ordered and plotted counter-clockwise.
90-
labels = pops.keys()
90+
labels = list(pops.keys())
9191
tot = float(sum(pops.values()))
92-
fracs = [float(pop)/tot for pop in pops.values()]
92+
fracs = [float(pop)/tot for pop in list(pops.values())]
9393
#explode=(0, 0.05, 0, 0)
9494
# if layer=='6':
9595
# colors = [ 'gold', 'purple', 'red', 'green']
@@ -117,7 +117,7 @@
117117
popColors.update({'SOM2': [187, 143, 206], 'SOM5A': [165, 105, 189], 'SOM5B': [142, 68, 173], 'SOM6': [142, 68, 173]}) # SOM purple tones
118118
popColors.update({'PV2': [247, 220, 111], 'PV5A': [244, 208, 63], 'PV5B': [241, 196, 15], 'PV6': [212, 172, 13]}) # PV yellow tones
119119
popColors.update({'SOM2': [248, 196, 113], 'SOM5A': [245, 176, 65], 'SOM5B': [243, 156, 18], 'SOM6': [214, 137, 16]}) # SOM orange tones
120-
for pop,col in popColors.iteritems(): popColors[pop]=[c/256.0 for c in col] #normalize
120+
for pop,col in list(popColors.items()): popColors[pop]=[c/256.0 for c in col] #normalize
121121
with open('popColors.pkl', 'wb') as fileObj:
122122
pickle.dump({'popColors': popColors}, fileObj)
123123

netpyne_ui/tests/M1detailed/cfg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
#------------------------------------------------------------------------------
6565
# Analysis and plotting
6666
#------------------------------------------------------------------------------
67-
with open('cells/popColors.pkl', 'r') as fileObj: popColors = pickle.load(fileObj)['popColors']
67+
with open('cells/popColors.pkl', 'rb') as fileObj:
68+
popColors = pickle.load(fileObj)['popColors']
6869
cfg.analysis['plotTraces'] = {'include': [('IT5A',0), ('PT5B',00)], 'timeRange': [0,500], 'oneFigPer': 'cell', 'figSize': (10,4), 'saveFig': True, 'showFig': False}
6970

7071
cfg.analysis['plotRaster'] = {'include': allpops, 'saveFig': True, 'showFig': False, 'labels': 'overlay', 'popRates': True, 'orderInverse': True,

0 commit comments

Comments
 (0)