Skip to content

Commit

Permalink
Updated all in-repo references and scripts to Python 3 (#1105)
Browse files Browse the repository at this point in the history
Update all Python scripts used during build/testing/running Arbor to explicitly use Python 3.
  • Loading branch information
brenthuisman authored Aug 6, 2020
1 parent 70576ca commit e28c0ac
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ install:
if [[ "$WITH_PYTHON" == "true" ]]; then
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python$PY get-pip.py
pip --version
pip$PY --version
fi
- if [[ ( "$WITH_PYTHON" == "true" ) && ( "$TRAVIS_OS_NAME" == "osx" ) ]]; then pip$PY install numpy; fi
- |
Expand Down
6 changes: 3 additions & 3 deletions ci/codecov/build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ ENV MPICH_VERSION ${MPICH_VERSION}
# Install basic tools
RUN apt-get update -qq && apt-get install -qq -y --no-install-recommends \
build-essential lcov \
python \
python3 \
git tar wget curl && \
rm -rf /var/lib/apt/lists/*

# Install cmake
RUN wget -qO- "https://cmake.org/files/v3.17/cmake-3.17.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
RUN wget -qO- "https://github.com/Kitware/CMake/releases/download/v3.12.4/cmake-3.12.4-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local

# Install MPICH ABI compatible with Cray's lib on Piz Daint
RUN wget -q https://www.mpich.org/static/downloads/${MPICH_VERSION}/mpich-${MPICH_VERSION}.tar.gz && \
Expand All @@ -27,7 +27,7 @@ RUN wget -q https://www.mpich.org/static/downloads/${MPICH_VERSION}/mpich-${MPIC
rm -rf mpich-${MPICH_VERSION}.tar.gz mpich-${MPICH_VERSION}

# Install bundle tooling for creating small Docker images
RUN wget -q https://github.com/haampie/libtree/releases/download/v1.1.3/libtree_x86_64.tar.gz && \
RUN wget -q https://github.com/haampie/libtree/releases/download/v1.2.0/libtree_x86_64.tar.gz && \
tar -xzf libtree_x86_64.tar.gz && \
rm libtree_x86_64.tar.gz && \
ln -s /root/libtree/libtree /usr/local/bin/libtree
8 changes: 4 additions & 4 deletions ci/release/build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ ENV MPICH_VERSION ${MPICH_VERSION}
# Install basic tools
RUN apt-get update -qq && apt-get install -qq -y --no-install-recommends \
build-essential \
python \
python3 \
git tar wget curl && \
rm -rf /var/lib/apt/lists/*

# Install cmake
RUN wget -qO- "https://cmake.org/files/v3.17/cmake-3.17.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
RUN wget -qO- "https://github.com/Kitware/CMake/releases/download/v3.12.4/cmake-3.12.4-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local

# Install MPICH ABI compatible with Cray's lib on Piz Daint
RUN wget -q https://www.mpich.org/static/downloads/${MPICH_VERSION}/mpich-${MPICH_VERSION}.tar.gz && \
Expand All @@ -27,7 +27,7 @@ RUN wget -q https://www.mpich.org/static/downloads/${MPICH_VERSION}/mpich-${MPIC
rm -rf mpich-${MPICH_VERSION}.tar.gz mpich-${MPICH_VERSION}

# Install bundle tooling for creating small Docker images
RUN wget -q https://github.com/haampie/libtree/releases/download/v1.1.3/libtree_x86_64.tar.gz && \
RUN wget -q https://github.com/haampie/libtree/releases/download/v1.2.0/libtree_x86_64.tar.gz && \
tar -xzf libtree_x86_64.tar.gz && \
rm libtree_x86_64.tar.gz && \
ln -s /root/libtree/libtree /usr/local/bin/libtree
ln -s /root/libtree/libtree /usr/local/bin/libtree
2 changes: 1 addition & 1 deletion example/lfp/plot-lfp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import argparse
import matplotlib.pyplot as plt
Expand Down
29 changes: 15 additions & 14 deletions scripts/compare_spike_trains.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import os
import sys
import collections
from itertools import zip_longest

def usage(default_delta):
print ("""
print("""
compare two input spike time files on equality with a delta of max_delta
order of the spikes is not important. GID should always be equal
Display the first 50 differences encountered.
Expand Down Expand Up @@ -36,9 +37,9 @@ def parse_file(path):
gid = int(split_items[0].strip())
time = float(split_items[1].strip())
except:
print "Could not parse a line in the file!!!! \n"
print " line: " , line_idx, ": ", stripped_line
print path
print("Could not parse a line in the file!!!! \n")
print(" line: " , line_idx, ": ", stripped_line)
print(path)

exit(1) #failure

Expand All @@ -59,20 +60,20 @@ def compare(path1, data1, path2, data2, delta):
"""
combined_data = collections.defaultdict(lambda : [[],[]])

for gid, spike_data in data1.items():
for gid, spike_data in list(data1.items()):
combined_data[gid][0].extend(spike_data)


for gid, spike_data in data2.items():
for gid, spike_data in list(data2.items()):
combined_data[gid][1].extend(spike_data)

different_spikes = []
for gid, (data_1, data_2)in combined_data.items():
for gid, (data_1, data_2)in list(combined_data.items()):
gid_list1 = data_1
gid_list2 = data_2

if len(gid_list1) != len(gid_list2):
for idx, (time1, time2) in enumerate(map(None, gid_list1, gid_list2)):
for idx, (time1, time2) in enumerate(zip_longest(gid_list1, gid_list2)):
# We have to loop all spikes, check here if we have missing spikes
# and treat those different
if time1 == None or time2 == None:
Expand All @@ -93,18 +94,18 @@ def compare(path1, data1, path2, data2, delta):
different_spikes.append((gid, time1, time2))

if len(different_spikes) != 0:
print "Found difference in spike times, displaying first 50 \n"
print "key == (line_nr, spike_time, content line parsed)\n"
print "difference #, gid : target output != simulation output"
print("Found difference in spike times, displaying first 50 \n")
print("key == (line_nr, spike_time, content line parsed)\n")
print("difference #, gid : target output != simulation output")

for idx, (gid, time1, time2) in enumerate(different_spikes):
if idx == 50:
break

dif_str = "difference #{0}, {3}: {1} != {2}".format(idx, time1, time2, gid)
print dif_str
print(dif_str)

print "\n\n"
print("\n\n")


# Also output to file (could be done in previous loop, but seperation
Expand Down
10 changes: 5 additions & 5 deletions scripts/print_backtrace
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#coding: utf-8

import argparse
Expand Down Expand Up @@ -54,7 +54,7 @@ def parse_backtrace(source):
tokens = line.split()
trace.append({'location':tokens[0], 'function':tokens[1]})
else:
print "error: unable to open back trace file ", source
print("error: unable to open back trace file ", source)

return trace

Expand All @@ -75,7 +75,7 @@ args = parse_clargs()
# check that a valid executable was provided
executable = args.executable
if not os.path.isfile(executable):
print "error:", executable, "is not a valid executable"
print("error:", executable, "is not a valid executable")
else:
for frame in parse_backtrace(args.input):
location = get_function_name(frame['location'], executable)
Expand All @@ -84,6 +84,6 @@ else:
fname = c.yellow + location['filename'] + c.end
line = c.cyan + location['line'] + c.end
if args.brief:
print fname + ':' + line
print(fname + ':' + line)
else:
print fname + ':' + line, '\n ', name
print(fname + ':' + line, '\n ', name)
14 changes: 6 additions & 8 deletions scripts/tsplot
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#coding: utf-8

from __future__ import print_function

import argparse
import json
import numpy as np
Expand Down Expand Up @@ -84,7 +82,7 @@ def parse_clargs():
return P.parse_args(argsbis)

def isstring(s):
return isinstance(s,str) or isinstance(s,unicode)
return isinstance(s,str)

def take(n, s):
return islice((i for i in s), 0, n)
Expand Down Expand Up @@ -225,7 +223,7 @@ def read_json_timeseries(j, axis='time', select=[]):
return ""

i = 1
for key in jdata.keys():
for key in list(jdata.keys()):
if key==axis: continue

meta = j.copy()
Expand Down Expand Up @@ -278,7 +276,7 @@ class PlotData:
return labels

n = len(labels)
keyset = reduce(lambda k, s: k.union(s.meta.keys()), self.series, set())
keyset = reduce(lambda k, s: k.union(list(s.meta.keys())), self.series, set())
keyi = iter(keyset)
try:
while len(set(labels)) != n:
Expand All @@ -293,7 +291,7 @@ class PlotData:
for i in range(n):
prefix = '' if k=='name' else k+'='
if vs[i] is not None:
labels[i] += u', '+k+u'='+unicode(formatter(vs[i]))
labels[i] += ', '+k+'='+str(formatter(vs[i]))

except StopIteration:
pass
Expand All @@ -310,7 +308,7 @@ def gather_ts_plots(tss, groupby):
for ts in tss:
key = tuple([ts.meta.get(g) for g in groupby])
if key is () or None in key or key not in group_lookup:
pretty_key=', '.join([unicode(k)+u'='+unicode(v) for k,v in zip(groupby, key) if v is not None])
pretty_key=', '.join([str(k)+'='+str(v) for k,v in zip(groupby, key) if v is not None])
pd = PlotData(pretty_key)
pd.series = [ts]
plot_groups.append(pd)
Expand Down
2 changes: 1 addition & 1 deletion validation/ref/neuron/ball_and_3stick.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#coding: utf-8

import json
Expand Down
7 changes: 1 addition & 6 deletions validation/ref/neuron/ball_and_squiggle.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#coding: utf-8

import json
import math
import nrn_validation as V

try:
from builtins import range
except ImportError:
from __builtin__ import range

V.override_defaults_from_args()

# dendrite geometry: 100 µm long, varying diameter.
Expand Down
2 changes: 1 addition & 1 deletion validation/ref/neuron/ball_and_stick.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#coding: utf-8

import json
Expand Down
2 changes: 1 addition & 1 deletion validation/ref/neuron/ball_and_taper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#coding: utf-8

import json
Expand Down
12 changes: 3 additions & 9 deletions validation/ref/neuron/nrn_validation.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#coding: utf-8

import json
import sys
import os
import re
import numpy as np
import neuron
from neuron import h

try:
from builtins import range
except ImportError:
from __builtin__ import range

# This is super annoying: without neuron.gui, need
# to explicit load 'standard' hoc routines like 'run',
# but this is chatty on stdout, which means we get
Expand Down Expand Up @@ -55,7 +49,7 @@ def hoc_quit():

def override_defaults_from_args(args=sys.argv):
global default_model_parameters
keys = default_model_parameters.keys()
keys = list(default_model_parameters.keys())
r = re.compile('('+'|'.join(keys)+')=(.*)')
for m in [r.match(a) for a in args]:
if m:
Expand All @@ -77,7 +71,7 @@ def __init__(self):
self.netcons = []

def set_ncomp(self, n):
for s in self.sections.values():
for s in list(self.sections.values()):
s.nseg = int(n)

def add_iclamp(self, t0, dt, i, to=None, pos=1):
Expand Down
2 changes: 1 addition & 1 deletion validation/ref/neuron/simple_exp2_synapse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#coding: utf-8

import json
Expand Down
2 changes: 1 addition & 1 deletion validation/ref/neuron/simple_exp_synapse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#coding: utf-8

import json
Expand Down
2 changes: 1 addition & 1 deletion validation/ref/neuron/soma.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#coding: utf-8

import json
Expand Down

0 comments on commit e28c0ac

Please sign in to comment.