Skip to content

Commit

Permalink
ran 2to3 stage 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Oct 19, 2017
1 parent 6277e20 commit 7ce42d1
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 43 deletions.
15 changes: 8 additions & 7 deletions examples/brunel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import division
from __future__ import print_function
import os.path
from itertools import groupby
from operator import itemgetter
Expand Down Expand Up @@ -157,11 +158,11 @@
max_delay=ReferenceBrunel2000.max_delay,
dt=args.timestep * un.ms, seed=seed) as sim:
# Construct the network
print "Constructing the network in {}".format(simulator.upper())
print("Constructing the network in {}".format(simulator.upper()))
networks[simulator] = pype9_network_classes[simulator](
model, build_mode=args.build_mode)
print "Finished constructing the network in {}".format(
simulator.upper())
print("Finished constructing the network in {}".format(
simulator.upper()))
# Record spikes and voltages
for pop in networks[simulator].component_arrays:
pop[:args.num_record].record('spikes')
Expand All @@ -170,7 +171,7 @@

# Create the reference simulation if required
if simulator == 'nest' and args.reference:
print "Constructing the reference NEST implementation"
print("Constructing the reference NEST implementation")
if args.no_init_v:
init_v = {'Exc': 0.0, 'Inh': 0.0}
else:
Expand All @@ -183,7 +184,7 @@
to_plot=pops_to_plot, timestep=args.timestep)

# Run the simulation(s)
print "Running the simulation in {}".format(simulator.upper())
print("Running the simulation in {}".format(simulator.upper()))
if args.progress_bar:
kwargs = {'callbacks': [
SimulationProgressBar(args.simtime / 77, args.simtime)]}
Expand All @@ -193,7 +194,7 @@

if mpi_rank == 0:
# Plot the results
print "Plotting the results"
print("Plotting the results")
num_subplots = len(args.simulators) + int(args.reference)
for pop_name in pops_to_plot:
spike_fig, spike_subplots = plt.subplots(num_subplots, 1,
Expand Down Expand Up @@ -288,4 +289,4 @@
'{}_v'.format(pop_name)))
if save_path is None:
plt.show()
print "done"
print("done")
5 changes: 3 additions & 2 deletions examples/izhikevich.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import nineml.units as un
from argparse import ArgumentParser
import ninemlcatalog
Expand Down Expand Up @@ -166,7 +167,7 @@ def construct_reference(input_signal, dt):
# allow the backend to be set
from matplotlib import pyplot as plt # @IgnorePep8

print "Plotting the results"
print("Plotting the results")
plt.figure(figsize=args.figsize)
if args.fast_spiking:
title = "Izhikevich Fast Spiking"
Expand All @@ -193,4 +194,4 @@ def construct_reference(input_signal, dt):
plt.savefig(args.save_fig)
else:
plt.show()
print "done"
print("done")
9 changes: 5 additions & 4 deletions pype9/cmd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import convert
import simulate
import plot
import help # @ReservedAssignment
from __future__ import absolute_import
from . import convert
from . import simulate
from . import plot
from . import help # @ReservedAssignment
1 change: 1 addition & 0 deletions pype9/cmd/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ninemlcatalog
from argparse import ArgumentTypeError
from pype9.exceptions import Pype9UsageError, Pype9UnitStrError
from functools import reduce


def existing_file(fname):
Expand Down
3 changes: 2 additions & 1 deletion pype9/cmd/help.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Prints help information associated with a PyPe9 command
"""
from __future__ import print_function
from argparse import ArgumentParser


Expand Down Expand Up @@ -35,7 +36,7 @@ def _get_description(cmd):

def run(argv):
if not argv:
print available_cmds_message()
print(available_cmds_message())
else:
args = argparser().parse_args(argv)
get_parser(args.cmd).print_help()
Expand Down
1 change: 1 addition & 0 deletions pype9/simulate/common/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pype9.exceptions import Pype9RuntimeError
from pype9.utils import classproperty
from fractions import gcd
from functools import reduce
numpy.seterr(all='raise')


Expand Down
2 changes: 1 addition & 1 deletion pype9/simulate/nest/cells/code_gen/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def clean_compile_dir(self, compile_dir, **kwargs): # @UnusedVariable @IgnorePe
try:
if not path.exists(compile_dir):
os.makedirs(compile_dir)
except IOError, e:
except IOError as e:
raise Pype9BuildError(
"Could not make compile directory '{}': {}"
.format(compile_dir, e))
Expand Down
19 changes: 10 additions & 9 deletions pype9/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
NEST
"""
from __future__ import absolute_import, division
from __future__ import print_function
import os.path
import re
from itertools import combinations
Expand Down Expand Up @@ -541,8 +542,8 @@ def __init__(self, case, order, external_input=None, connections=None,
J_ex, J_in, p_rate) = self.parameters(case, order)

if override_input is not None:
print "changing poisson rate from {} to {}".format(p_rate,
override_input)
print("changing poisson rate from {} to {}".format(p_rate,
override_input))
p_rate = override_input

nest.SetDefaults("iaf_psc_alpha", neuron_params)
Expand Down Expand Up @@ -739,7 +740,7 @@ def assertEqual(self, first, second, msg=None):
if msg is None:
msg = '{} and {} are not equal'.format(repr(first),
repr(second))
print msg
print(msg)

def assertAlmostEqual(self, first, second, places=None, msg=None):
if places is None:
Expand All @@ -748,37 +749,37 @@ def assertAlmostEqual(self, first, second, places=None, msg=None):
if msg is None:
msg = '{} and {} are not equal'.format(repr(first),
repr(second))
print msg
print(msg)

def assertLess(self, first, second, msg=None):
if first >= second:
if msg is None:
msg = '{} is not less than {}'.format(repr(first),
repr(second))
print msg
print(msg)

def assertLessEqual(self, first, second, msg=None):
if first > second:
if msg is None:
msg = '{} is not less than or equal to {}'.format(
repr(first), repr(second))
print msg
print(msg)

def assertNotEqual(self, first, second, msg=None):
if first == second:
if msg is None:
msg = '{} is equal to {}'.format(
repr(first), repr(second))
print msg
print(msg)

def assertTrue(self, statement, msg=None):
if not statement:
if msg is None:
msg = '{} is not true'.format(repr(statement))
print msg
print(msg)

def assertNotTrue(self, statement, msg=None):
if statement:
if msg is None:
msg = '{} is true'.format(repr(statement))
print msg
print(msg)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import re
import platform
Expand Down
3 changes: 2 additions & 1 deletion test/test_cmds/test_convert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os.path
import tempfile
import shutil
Expand Down Expand Up @@ -42,7 +43,7 @@ def test_convert_format(self):
in_path = os.path.join(os.path.relpath(ninemlcatalog.root),
'neuron', 'Izhikevich.xml')
out_path = os.path.join(self.tmpdir, 'Izhikevich.yml')
print out_path
print(out_path)
args = '{} {}'.format(in_path, out_path)
convert.run(args.split())
# Check the output file is yaml
Expand Down
17 changes: 9 additions & 8 deletions test/test_seeding.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import division
from __future__ import print_function
from itertools import chain
import ninemlcatalog
import numpy
Expand Down Expand Up @@ -67,9 +68,9 @@ def test_network_seed(self):
with Simulation(dt=0.01 * un.ms, seed=1) as sim:
network1 = Network(brunel_model)
network1.component_array('Ext').record('spike_output')
print "Sim 1 - prop: {}, dyn: {}, global: {}".format(
print("Sim 1 - prop: {}, dyn: {}, global: {}".format(
sim.all_properties_seeds, sim.all_dynamics_seeds,
sim.global_seed)
sim.global_seed))
sim.run(20 * un.ms)
ext1_spikes = network1.component_array(
'Ext').recording('spike_output')
Expand All @@ -78,9 +79,9 @@ def test_network_seed(self):
with Simulation(dt=0.01 * un.ms, seed=1) as sim:
network2 = Network(brunel_model)
network2.component_array('Ext').record('spike_output')
print "Sim 2 - prop: {}, dyn: {}, global: {}".format(
print("Sim 2 - prop: {}, dyn: {}, global: {}".format(
sim.all_properties_seeds, sim.all_dynamics_seeds,
sim.global_seed)
sim.global_seed))
sim.run(20 * un.ms)
ext2_spikes = network2.component_array(
'Ext').recording('spike_output')
Expand All @@ -89,9 +90,9 @@ def test_network_seed(self):
with Simulation(dt=0.01 * un.ms, seed=2) as sim:
network3 = Network(brunel_model)
network3.component_array('Ext').record('spike_output')
print "Sim 3 - prop: {}, dyn: {}, global: {}".format(
print("Sim 3 - prop: {}, dyn: {}, global: {}".format(
sim.all_properties_seeds, sim.all_dynamics_seeds,
sim.global_seed)
sim.global_seed))
sim.run(20 * un.ms)
ext3_spikes = network3.component_array(
'Ext').recording('spike_output')
Expand All @@ -100,9 +101,9 @@ def test_network_seed(self):
with Simulation(dt=0.01 * un.ms, properties_seed=1) as sim:
network4 = Network(brunel_model)
network4.component_array('Ext').record('spike_output')
print "Sim 4 - prop: {}, dyn: {}, global: {}".format(
print("Sim 4 - prop: {}, dyn: {}, global: {}".format(
sim.all_properties_seeds, sim.all_dynamics_seeds,
sim.global_seed)
sim.global_seed))
sim.run(20 * un.ms)
ext4_spikes = network4.component_array(
'Ext').recording('spike_output')
Expand Down
19 changes: 10 additions & 9 deletions test/test_simulations/test_cells.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
import sys
import quantities as pq
import os.path
Expand Down Expand Up @@ -96,7 +97,7 @@ def test_izhi(self, plot=PLOT_DEFAULT, print_comparisons=False,
comparisons = comparer.compare()
if print_comparisons:
for (name1, name2), diff in comparisons.iteritems():
print '{} v {}: {}'.format(name1, name2, diff)
print('{} v {}: {}'.format(name1, name2, diff))
if plot:
comparer.plot()
if 'nest' in simulators and 'neuron' in simulators:
Expand Down Expand Up @@ -169,7 +170,7 @@ def test_hh(self, plot=PLOT_DEFAULT, print_comparisons=False,
comparisons = comparer.compare()
if print_comparisons:
for (name1, name2), diff in comparisons.iteritems():
print '{} v {}: {}'.format(name1, name2, diff)
print('{} v {}: {}'.format(name1, name2, diff))
if plot:
comparer.plot()
# FIXME: Need to work out what is happening with the reference NEURON
Expand Down Expand Up @@ -219,7 +220,7 @@ def test_liaf(self, plot=PLOT_DEFAULT, print_comparisons=False,
comparisons = comparer.compare()
if print_comparisons:
for (name1, name2), diff in comparisons.iteritems():
print '{} v {}: {}'.format(name1, name2, diff)
print('{} v {}: {}'.format(name1, name2, diff))
if plot:
comparer.plot()
if 'neuron' in simulators:
Expand Down Expand Up @@ -344,7 +345,7 @@ def test_alpha_syn(self, plot=PLOT_DEFAULT, print_comparisons=False,
comparisons = comparer.compare()
if print_comparisons:
for (name1, name2), diff in comparisons.iteritems():
print '{} v {}: {}'.format(name1, name2, diff)
print('{} v {}: {}'.format(name1, name2, diff))
if plot:
comparer.plot()
if 'nest' in simulators and 'neuron' in simulators:
Expand Down Expand Up @@ -389,7 +390,7 @@ def test_izhiFS(self, plot=PLOT_DEFAULT, print_comparisons=False,
comparisons = comparer.compare()
if print_comparisons:
for (name1, name2), diff in comparisons.iteritems():
print '{} v {}: {}'.format(name1, name2, diff)
print('{} v {}: {}'.format(name1, name2, diff))
if plot:
comparer.plot()
if 'nest' in simulators and 'neuron' in simulators:
Expand Down Expand Up @@ -431,9 +432,9 @@ def test_poisson(self, duration=100 * un.s, rate=100 * un.Hz,
ref_rate = pq.Quantity(UnitHandlerNEST.to_pq_quantity(rate), 'Hz')
rate_difference = abs(ref_rate - recorded_rate)
if print_comparisons:
print "Reference rate: {}".format(ref_rate)
print "{} recorded rate: {}".format(sim_name, recorded_rate)
print "{} difference: {}".format(sim_name, rate_difference)
print("Reference rate: {}".format(ref_rate))
print("{} recorded rate: {}".format(sim_name, recorded_rate))
print("{} difference: {}".format(sim_name, rate_difference))
self.assertLess(
rate_difference, 5 * pq.Hz,
("Recorded rate of {} poisson generator ({}) did not match "
Expand Down Expand Up @@ -491,4 +492,4 @@ def test_poisson(self, duration=100 * un.s, rate=100 * un.Hz,
test = getattr(tester, 'test_' + args.test)
test(plot=args.plot, print_comparisons=args.print_comparisons,
simulators=args.simulators, build_mode=args.build_mode, **kwargs)
print "done"
print("done")
3 changes: 2 additions & 1 deletion test/test_simulations/test_network.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from __future__ import division
from __future__ import print_function
from itertools import groupby, izip
from operator import itemgetter
import itertools
Expand Down Expand Up @@ -557,7 +558,7 @@ def test_activity_with_neuron(self, case='AI', order=10, simtime=100.0,
percent_psth_stdev_error)))
if plot:
plt.show()
print "done"
print("done")

def test_flatten(self, **kwargs): # @UnusedVariable
brunel_network = ninemlcatalog.load(
Expand Down

0 comments on commit 7ce42d1

Please sign in to comment.