Skip to content

Commit

Permalink
Merge branch 'master' into fix_connect_after_restore_check
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Oct 8, 2021
2 parents 16fb8d8 + a669f65 commit edea575
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
min-python: ${{ steps.nep29.outputs.min-python }}
max-python: ${{ steps.nep29.outputs.max-python }}
max-python: "3.9"
steps:
- name: "calculate versions according to NEP29"
id: nep29
Expand Down
14 changes: 5 additions & 9 deletions brian2/groups/subgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ class Subgroup(Group, SpikeSource):
A unique name for the group, or use ``source.name+'_subgroup_0'``, etc.
'''
def __init__(self, source, start, stop, name=None):
# First check if the source is itself a Subgroup
# If so, then make this a Subgroup of the original Group
if isinstance(source, Subgroup):
source = source.source
start = start + source.start
stop = stop + source.start
self.source = source
else:
self.source = weakproxy_with_fallback(source)
# A Subgroup should never be constructed from another Subgroup
# Instead, use Subgroup(source.source,
# start + source.start, stop + source.start)
assert not isinstance(source, Subgroup)
self.source = weakproxy_with_fallback(source)

# Store a reference to the source's equations (if any)
self.equations = None
Expand Down
16 changes: 13 additions & 3 deletions brian2/spatialneuron/spatialneuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ class SpatialNeuron(NeuronGroup):
----------
morphology : `Morphology`
The morphology of the neuron.
model : (str, `Equations`)
model : str, `Equations`
The equations defining the group.
method : (str, function), optional
method : str, function, optional
The numerical integration method. Either a string with the name of a
registered method (e.g. "euler") or a function that receives an
`Equations` object and returns the corresponding abstract code. If no
Expand Down Expand Up @@ -495,11 +495,17 @@ def spatialneuron_segment(neuron, item):
start, stop = to_start_stop(item.indices[:], neuron._N)
else:
start, stop = to_start_stop(item, neuron._N)
if isinstance(neuron, SpatialSubgroup):
start += neuron.start
stop += neuron.start

if start >= stop:
raise IndexError('Illegal start/end values for subgroup, %d>=%d' %
(start, stop))

if isinstance(neuron, SpatialSubgroup):
# Note that the start/stop values calculated above are always
# absolute values, even for subgroups
neuron = neuron.source
return Subgroup(neuron, start, stop)


Expand All @@ -522,6 +528,10 @@ class SpatialSubgroup(Subgroup):

def __init__(self, source, start, stop, morphology, name=None):
self.morphology = morphology
if isinstance(source, SpatialSubgroup):
source = source.source
start += source.start
stop += source.start
Subgroup.__init__(self, source, start, stop, name)

def __getattr__(self, name):
Expand Down
6 changes: 5 additions & 1 deletion brian2/tests/test_spatialneuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def test_spatialneuron_indexing():
sec.sec2 = Cylinder(length=50 * um, diameter=10 * um, n=16)
sec.sec2.sec21 = Cylinder(length=50 * um, diameter=10 * um, n=32)
neuron = SpatialNeuron(sec, 'Im = 0*amp/meter**2 : amp/meter**2')

neuron.v = 'i*volt'
# Accessing indices/variables of a subtree refers to the full subtree
assert len(neuron.indices[:]) == 1 + 2 + 4 + 8 + 16 + 32
assert len(neuron.sec1.indices[:]) == 2 + 4 + 8
Expand Down Expand Up @@ -659,6 +659,10 @@ def test_spatialneuron_indexing():
assert len(neuron[0:1].indices[:]) == 1
assert len(neuron[sec.sec2.indices[:]]) == 16
assert len(neuron[sec.sec2]) == 16
assert_equal(neuron.sec1.sec11.v, [3, 4, 5, 6]*volt)
assert_equal(neuron.sec1.sec11[1].v, neuron.sec1.sec11.v[1])
assert_equal(neuron.sec1.sec11[1:3].v, neuron.sec1.sec11.v[1:3])
assert_equal(neuron.sec1.sec11[1:3].v, [4, 5]*volt)


@pytest.mark.codegen_independent
Expand Down
10 changes: 5 additions & 5 deletions docs_sphinx/user/multicompartmental.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ string description may include other state variables (differential equations or
or parameters, exactly as in `NeuronGroup`. At every timestep, Brian integrates the state variables, calculates the
transmembrane current at every point on the neuronal morphology, and updates ``v`` using the transmembrane current and
the diffusion current, which is calculated based on the morphology and the intracellular resistivity.
Note that the transmembrane current is a surfacic current, not the total current in the compartement.
Note that the transmembrane current is a surfacic current, not the total current in the compartment.
This choice means that the model equations are independent of the number of compartments chosen for the simulation.
The space and time constants can obtained for any point of the neuron with the ``space_constant`` respectively
``time_constant`` attributes::
Expand Down Expand Up @@ -319,18 +319,18 @@ soma), you can use::
In the same way as for sections, you can also use slices, either with the
indices of compartments, or with the distance from the root::

first_compartments = neurons[:3]
first_compartments = neurons[0*um:30*um]
first_compartments = neuron[:3]
first_compartments = neuron[0*um:30*um]

However, note that this is restricted to contiguous indices which most of the
time means that all compartments indexed in this way have to be part of the
same section. Such indices can be acquired directly from the morphology::

axon = neurons[morpho.axon.indices[:]]
axon = neuron[morpho.axon.indices[:]]

or, more concisely::

axon = neurons[morpho.axon]
axon = neuron[morpho.axon]

Synaptic inputs
~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions examples/frompapers/Kremer_et_al_2011_barrel_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@
dA_target/dt = -A_target/taud : volt (event-driven)''',
on_pre='''ge+=w
A_source += Ap
w = clip(w+A_target, 0, EPSC)''',
w = clip(w+A_target, 0*volt, EPSC)''',
on_post='''
A_target += Ad
w = clip(w+A_source, 0, EPSC)''',
w = clip(w+A_source, 0*volt, EPSC)''',
name='feedforward')
# Connect neurons in the same barrel with 50% probability
feedforward.connect('(barrel_x_pre + barrelarraysize*barrel_y_pre) == barrel_idx_post',
Expand Down

0 comments on commit edea575

Please sign in to comment.