HHTypedNeuron#

class braincell.HHTypedNeuron(size, name=None, **ion_channels)#

Base class for Hodgkin-Huxley typed neuronal membrane dynamics.

Subclasses own the membrane voltage V and the integration scheme; this class owns the ion-channel container and the lifecycle calls that fan out to it.

Parameters:
  • size (int | Sequence[int] | integer | Sequence[integer]) – The size of the simulation target: an int, or a tuple/list of ints read as (..., n_neuron, n_compartment).

  • name (str | None) – The name of the instance. A default is generated when omitted.

  • **ion_channels – Ion channel instances to add to the neuron, keyed by attribute name.

Raises:

ValueError – If size is neither an int nor a non-empty tuple/list of ints.

add(**elements)[source]#

Add ion channels to the neuron after construction.

Parameters:

**elements – Ion channel instances to add, keyed by attribute name.

Raises:

TypeError – If an element’s root_type does not accept this neuron, or if it is not an IonChannel.

compute_derivative(*args, **kwargs)[source]#

Fill in the derivative of every state this neuron integrates.

Parameters:
  • *args – Positional arguments defined by the subclass.

  • **kwargs – Keyword arguments defined by the subclass.

Raises:

NotImplementedError – Always, in the base class. Subclasses must override.

current(*args, **kwargs)[source]#

Sum the membrane current contributed by every ion channel.

Parameters:
  • *args – Positional arguments defined by the subclass.

  • **kwargs – Keyword arguments defined by the subclass.

Returns:

Total membrane current, in the subclass’s current units.

Return type:

brainunit.Quantity

Raises:

NotImplementedError – Always, in the base class. Subclasses must override.

get_spike(last_V, next_V)[source]#

Surrogate-gradient spike indicator at the V_th crossing.

Uses self.V_th (threshold voltage) and self.spk_fun (surrogate-gradient callable) supplied by subclasses. The product of rising- and falling-crossing terms produces a non-zero value only when last_V < V_th <= next_V.

init_state(batch_size=None)[source]#

Allocate the state of every direct ion-channel child.

Parameters:

batch_size (int, optional) – Leading batch dimension to allocate channel states with.

Raises:

TypeError – If a child channel’s root_type does not accept this neuron.

Notes

Channels are seeded from the current membrane potential self.V.value, so V must already be initialized.

property n_compartment: int#

Number of compartments per neuron.

Returns:

How many compartments – soma, dendrite, axon sections – each neuron in the group is divided into.

Return type:

int

Raises:

NotImplementedError – Always, in the base class. Subclasses must override.

property pop_size: Tuple[int, ...]#

Neuron-population shape, that is size without the compartment axis.

Returns:

The population size in each dimension: (100, 50) is a 2-D population of 100 by 50 neurons.

Return type:

tuple of int

Raises:

NotImplementedError – Always, in the base class. Subclasses must override.

post_integral(*args, **kwargs)[source]#

Run whatever must happen after each integration step.

Does nothing by default. Subclasses override it to publish spikes, clamp concentrations, or otherwise fix up state the solver wrote.

Parameters:
  • *args – Positional arguments defined by the subclass.

  • **kwargs – Keyword arguments defined by the subclass.

pre_integral(*args, **kwargs)[source]#

Run whatever must happen before each integration step.

Parameters:
  • *args – Positional arguments defined by the subclass.

  • **kwargs – Keyword arguments defined by the subclass.

Raises:

NotImplementedError – Always, in the base class. Subclasses must override.

reset_state(batch_size=None)[source]#

Return every direct ion-channel child to its initial state.

Parameters:

batch_size (int, optional) – Leading batch dimension to reset channel states with.

Notes

Unlike init_state() this does not re-check hierarchies: the state already exists, so the check has already run.