Skip to content

Commit

Permalink
Tests::Py && Lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstenhater committed Dec 1, 2023
1 parent a085dbc commit a1d963c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
10 changes: 5 additions & 5 deletions python/test/unit/test_clear_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class TestClearSamplers(unittest.TestCase):
def test_spike_clearing(self, art_spiking_sim):
sim = art_spiking_sim
sim.record(A.spike_recording.all)
handle = sim.sample((3, "Um"), A.regular_schedule(0.1*U.ms))
handle = sim.sample((3, "Um"), A.regular_schedule(0.1 * U.ms))

# baseline to test against Run in exactly the same stepping to make sure there are no rounding differences
sim.run(3*U.ms, 0.01*U.ms)
sim.run(5*U.ms, 0.01*U.ms)
sim.run(3 * U.ms, 0.01 * U.ms)
sim.run(5 * U.ms, 0.01 * U.ms)
spikes = sim.spikes()
times = spikes["time"].tolist()
gids = spikes["source"]["gid"].tolist()
Expand All @@ -35,7 +35,7 @@ def test_spike_clearing(self, art_spiking_sim):
sim.reset()

# simulated with clearing the memory inbetween the steppings
sim.run(3*U.ms, 0.01*U.ms)
sim.run(3 * U.ms, 0.01 * U.ms)
spikes = sim.spikes()
times_t = spikes["time"].tolist()
gids_t = spikes["source"]["gid"].tolist()
Expand All @@ -52,7 +52,7 @@ def test_spike_clearing(self, art_spiking_sim):
self.assertEqual(0, data_test.size)

# run the next part of the simulation
sim.run(5*U.ms, 0.01*U.ms)
sim.run(5 * U.ms, 0.01 * U.ms)
spikes = sim.spikes()
times_t.extend(spikes["time"].tolist())
gids_t.extend(spikes["source"]["gid"].tolist())
Expand Down
15 changes: 9 additions & 6 deletions python/test/unit/test_decor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
import arbor as A
from arbor import units as U

"""
Tests for decor and decoration wrappers.
TODO: Coverage for more than just iclamp.
Expand All @@ -12,29 +13,31 @@
class TestDecorClasses(unittest.TestCase):
def test_iclamp(self):
# Constant amplitude iclamp:
clamp = A.iclamp(10*U.nA)
clamp = A.iclamp(10 * U.nA)
self.assertEqual(0, clamp.frequency)
self.assertEqual([(0, 10)], clamp.envelope)

clamp = A.iclamp(current=10*U.nA, frequency=20*U.kHz)
clamp = A.iclamp(current=10 * U.nA, frequency=20 * U.kHz)
self.assertEqual(20, clamp.frequency)
self.assertEqual([(0, 10)], clamp.envelope)

# Square pulse:
clamp = A.iclamp(100*U.ms, 20*U.ms, 3*U.nA)
clamp = A.iclamp(100 * U.ms, 20 * U.ms, 3 * U.nA)
self.assertEqual(0, clamp.frequency)
self.assertEqual([(100, 3), (120, 3), (120, 0)], clamp.envelope)

clamp = A.iclamp(100*U.ms, 20*U.ms, 3*U.nA, frequency=7*U.kHz)
clamp = A.iclamp(100 * U.ms, 20 * U.ms, 3 * U.nA, frequency=7 * U.kHz)
self.assertEqual(7, clamp.frequency)
self.assertEqual([(100, 3), (120, 3), (120, 0)], clamp.envelope)

# Explicit envelope:
envelope = [(1, 10), (3, 30), (5, 50), (7, 0)]
clamp = A.iclamp([(t*U.ms, i*U.nA) for t, i in envelope])
clamp = A.iclamp([(t * U.ms, i * U.nA) for t, i in envelope])
self.assertEqual(0, clamp.frequency)
self.assertEqual(envelope, clamp.envelope)

clamp = A.iclamp([(t*U.ms, i*U.nA) for t, i in envelope], frequency=7*U.kHz)
clamp = A.iclamp(
[(t * U.ms, i * U.nA) for t, i in envelope], frequency=7 * U.kHz
)
self.assertEqual(7, clamp.frequency)
self.assertEqual(envelope, clamp.envelope)
7 changes: 4 additions & 3 deletions python/test/unit/test_event_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import arbor as arb
from arbor import units as U

"""
all tests for event generators (regular, explicit, poisson)
"""
Expand All @@ -14,22 +15,22 @@
class TestEventGenerator(unittest.TestCase):
def test_event_generator_regular_schedule(self):
cm = arb.cell_local_label("tgt0")
rs = arb.regular_schedule(2.0*U.ms, 1.0*U.ms, 100.0*U.ms)
rs = arb.regular_schedule(2.0 * U.ms, 1.0 * U.ms, 100.0 * U.ms)
rg = arb.event_generator(cm, 3.14, rs)
self.assertEqual(rg.target.label, "tgt0")
self.assertEqual(rg.target.policy, arb.selection_policy.univalent)
self.assertAlmostEqual(rg.weight, 3.14)

def test_event_generator_explicit_schedule(self):
cm = arb.cell_local_label("tgt1", arb.selection_policy.round_robin)
es = arb.explicit_schedule([0*U.ms, 1*U.ms, 2*U.ms, 3*U.ms, 4.4*U.ms])
es = arb.explicit_schedule([0 * U.ms, 1 * U.ms, 2 * U.ms, 3 * U.ms, 4.4 * U.ms])
eg = arb.event_generator(cm, -0.01, es)
self.assertEqual(eg.target.label, "tgt1")
self.assertEqual(eg.target.policy, arb.selection_policy.round_robin)
self.assertAlmostEqual(eg.weight, -0.01)

def test_event_generator_poisson_schedule(self):
ps = arb.poisson_schedule(freq=10.0*U.kHz, seed=0)
ps = arb.poisson_schedule(freq=10.0 * U.kHz, seed=0)
pg = arb.event_generator("tgt2", 42.0, ps)
self.assertEqual(pg.target.label, "tgt2")
self.assertEqual(pg.target.policy, arb.selection_policy.univalent)
Expand Down
38 changes: 20 additions & 18 deletions python/test/unit/test_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import unittest

import arbor as arb
import arbor as A
from arbor import units as U
import functools

"""
Expand All @@ -30,17 +31,17 @@ def wrapped(*args, **kwargs):
return inner_decorator


class a_recipe(arb.recipe):
class a_recipe(A.recipe):
def __init__(self):
arb.recipe.__init__(self)
self.props = arb.neuron_cable_properties()
A.recipe.__init__(self)
self.props = A.neuron_cable_properties()
self.trains = [[0.8, 2, 2.1, 3], [0.4, 2, 2.2, 3.1, 4.5], [0.2, 2, 2.8, 3]]

def num_cells(self):
return 3

def cell_kind(self, gid):
return arb.cell_kind.spike_source
return A.cell_kind.spike_source

def connections_on(self, gid):
return []
Expand All @@ -55,44 +56,45 @@ def probes(self, gid):
return []

def cell_description(self, gid):
return arb.spike_source_cell("src", arb.explicit_schedule(self.trains[gid]))
sched = A.explicit_schedule([t * U.ms for t in self.trains[gid]])
return A.spike_source_cell("src", sched)


def skipWithoutSupport():
return not bool(arb.config().get("profiling", False))
return not bool(A.config().get("profiling", False))


class TestProfiling(unittest.TestCase):
def test_support(self):
self.assertTrue("profiling" in arb.config(), "profiling key not in config")
profiling_support = arb.config()["profiling"]
self.assertTrue("profiling" in A.config(), "profiling key not in config")
profiling_support = A.config()["profiling"]
self.assertEqual(bool, type(profiling_support), "profiling flag should be bool")
if profiling_support:
self.assertTrue(
hasattr(arb, "profiler_initialize"),
hasattr(A, "profiler_initialize"),
"missing profiling interface with profiling support",
)
self.assertTrue(
hasattr(arb, "profiler_summary"),
hasattr(A, "profiler_summary"),
"missing profiling interface with profiling support",
)
else:
self.assertFalse(
hasattr(arb, "profiler_initialize"),
hasattr(A, "profiler_initialize"),
"profiling interface without profiling support",
)
self.assertFalse(
hasattr(arb, "profiler_summary"),
hasattr(A, "profiler_summary"),
"profiling interface without profiling support",
)

@lazy_skipIf(skipWithoutSupport, "run test only with profiling support")
def test_summary(self):
context = arb.context()
arb.profiler_initialize(context)
context = A.context()
A.profiler_initialize(context)
recipe = a_recipe()
dd = arb.partition_load_balance(recipe, context)
arb.simulation(recipe, context, dd).run(1)
summary = arb.profiler_summary()
dd = A.partition_load_balance(recipe, context)
A.simulation(recipe, context, dd).run(1 * U.ms)
summary = A.profiler_summary()
self.assertEqual(str, type(summary), "profiler summary must be str")
self.assertTrue(summary, "empty summary")

0 comments on commit a1d963c

Please sign in to comment.